generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 105
feat: Add AgentCore Session Manager Documentation #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8fe3775
chore: Added Bedrock AgentCore to Deployment patterns section
yonib05 53783b3
fix: Adjusted text to be inline with other options
yonib05 448b852
fix: Adjusted text to read like the other options
yonib05 eee99d0
Merge branch 'strands-agents:main' into main
yonib05 5be6526
feat: AgentCore Session Manager Documentation
yonib05 b8a1f6a
feat: add session management Community Sections
yonib05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# AgentCore Memory Session Manager | ||
|
||
{{ community_contribution_banner }} | ||
|
||
The [AgentCore Memory Session Manager](https://github.com/aws/bedrock-agentcore-sdk-python/tree/main/src/bedrock_agentcore/memory/integrations/strands) leverages Amazon Bedrock AgentCore Memory to provide advanced memory capabilities with intelligent retrieval for Strands Agents. It supports both short-term memory (STM) for conversation persistence and long-term memory (LTM) with multiple strategies for learning user preferences, facts, and session summaries. | ||
|
||
## Installation | ||
|
||
```bash | ||
pip install 'bedrock-agentcore[strands-agents]' | ||
``` | ||
|
||
## Usage | ||
|
||
### Basic Setup (Short-Term Memory) | ||
|
||
```python | ||
from strands import Agent | ||
from bedrock_agentcore.memory import MemoryClient | ||
from bedrock_agentcore.memory.integrations.strands.config import AgentCoreMemoryConfig | ||
from bedrock_agentcore.memory.integrations.strands.session_manager import AgentCoreMemorySessionManager | ||
from datetime import datetime | ||
|
||
# Create a basic memory for short-term functionality | ||
client = MemoryClient(region_name="us-east-1") | ||
basic_memory = client.create_memory( | ||
name="BasicTestMemory", | ||
description="Basic memory for testing short-term functionality" | ||
) | ||
|
||
# Configure memory | ||
agentcore_memory_config = AgentCoreMemoryConfig( | ||
memory_id=basic_memory.get('id'), | ||
session_id=f"session_{datetime.now().strftime('%Y%m%d%H%M%S')}", | ||
actor_id=f"user_{datetime.now().strftime('%Y%m%d%H%M%S')}" | ||
) | ||
|
||
# Create session manager | ||
session_manager = AgentCoreMemorySessionManager( | ||
agentcore_memory_config=agentcore_memory_config, | ||
region_name="us-east-1" | ||
) | ||
|
||
# Create agent | ||
agent = Agent( | ||
system_prompt="You are a helpful assistant. Use all you know about the user to provide helpful responses.", | ||
session_manager=session_manager, | ||
) | ||
|
||
# Use the agent - conversations are persisted with intelligent retrieval | ||
agent("I like sushi with tuna") | ||
agent("What should I buy for lunch today?") # Agent remembers preferences | ||
``` | ||
|
||
### Advanced Setup (Long-Term Memory) | ||
|
||
For more sophisticated memory capabilities, create a memory with multiple strategies: | ||
|
||
```python | ||
from bedrock_agentcore.memory.integrations.strands.config import RetrievalConfig | ||
|
||
# Create comprehensive memory with all built-in strategies | ||
comprehensive_memory = client.create_memory_and_wait( | ||
name="ComprehensiveAgentMemory", | ||
description="Full-featured memory with all built-in strategies", | ||
strategies=[ | ||
{ | ||
"summaryMemoryStrategy": { | ||
"name": "SessionSummarizer", | ||
"namespaces": ["/summaries/{actorId}/{sessionId}"] | ||
} | ||
}, | ||
{ | ||
"userPreferenceMemoryStrategy": { | ||
"name": "PreferenceLearner", | ||
"namespaces": ["/preferences/{actorId}"] | ||
} | ||
}, | ||
{ | ||
"semanticMemoryStrategy": { | ||
"name": "FactExtractor", | ||
"namespaces": ["/facts/{actorId}"] | ||
} | ||
} | ||
] | ||
) | ||
|
||
# Configure with multiple namespace retrieval | ||
config = AgentCoreMemoryConfig( | ||
memory_id=comprehensive_memory.get('id'), | ||
session_id=f"session_{datetime.now().strftime('%Y%m%d%H%M%S')}", | ||
actor_id=f"user_{datetime.now().strftime('%Y%m%d%H%M%S')}", | ||
retrieval_config={ | ||
"/preferences/{actorId}": RetrievalConfig( | ||
top_k=5, | ||
relevance_score=0.7 | ||
), | ||
"/facts/{actorId}": RetrievalConfig( | ||
top_k=10, | ||
relevance_score=0.3 | ||
), | ||
"/summaries/{actorId}/{sessionId}": RetrievalConfig( | ||
top_k=5, | ||
relevance_score=0.5 | ||
) | ||
} | ||
) | ||
|
||
session_manager = AgentCoreMemorySessionManager(config, region_name='us-east-1') | ||
agent = Agent(session_manager=session_manager) | ||
``` | ||
|
||
## Configuration | ||
|
||
### Memory Strategies | ||
|
||
AgentCore Memory supports three built-in strategies: | ||
|
||
1. **summaryMemoryStrategy**: Automatically summarizes conversation sessions for efficient context retrieval | ||
2. **userPreferenceMemoryStrategy**: Learns and stores user preferences across sessions | ||
3. **semanticMemoryStrategy**: Extracts and stores factual information from conversations | ||
|
||
### AgentCoreMemoryConfig Parameters | ||
|
||
- `memory_id`: ID of the Bedrock AgentCore Memory resource | ||
- `session_id`: Unique identifier for the conversation session | ||
- `actor_id`: Unique identifier for the user/actor | ||
- `retrieval_config`: Dictionary mapping namespaces to RetrievalConfig objects | ||
|
||
### RetrievalConfig Parameters | ||
|
||
- `top_k`: Number of top results to retrieve (default: 5) | ||
- `relevance_score`: Minimum relevance threshold (0.0-1.0) | ||
|
||
### Namespace Patterns | ||
|
||
- `/preferences/{actorId}`: User-specific preferences across sessions | ||
- `/facts/{actorId}`: User-specific factual information | ||
- `/summaries/{actorId}/{sessionId}`: Session-specific conversation summaries | ||
|
||
## Important Notes | ||
|
||
> **Session Limitations:** Currently, only **one** agent per session is supported when using AgentCoreMemorySessionManager. Creating multiple agents with the same session will show a warning. | ||
|
||
## Resources | ||
|
||
- **GitHub**: [bedrock-agentcore-sdk-python](https://github.com/aws/bedrock-agentcore-sdk-python/) | ||
- **Documentation**: [Strands Integration Examples](https://github.com/aws/bedrock-agentcore-sdk-python/tree/main/src/bedrock_agentcore/memory/integrations/strands) | ||
- **Issues**: Report bugs and feature requests in the [bedrock-agentcore-sdk-python repository](https://github.com/aws/bedrock-agentcore-sdk-python/issues/new/choose) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.