You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Short-term memory provides basic conversation persistence within a session. This is the simplest way to get started with AgentCore Memory.
19
+
20
+
#### Creating the Memory Resource
21
+
22
+
!!! note "One-time Setup"
23
+
The memory resource creation shown below is typically done once, separately from your agent application. In production, you would create the memory resource through the AWS Console or a separate setup script, then use the memory ID in your agent application.
16
24
17
25
```python
18
-
from strands importAgent
26
+
importos
19
27
from bedrock_agentcore.memory import MemoryClient
20
-
from bedrock_agentcore.memory.integrations.strands.config import AgentCoreMemoryConfig
21
-
from bedrock_agentcore.memory.integrations.strands.session_manager import AgentCoreMemorySessionManager
22
-
from datetime import datetime
23
28
24
-
#Create a basic memory for short-term functionality
29
+
#This is typically done once, separately from your agent application
25
30
client = MemoryClient(region_name="us-east-1")
26
31
basic_memory = client.create_memory(
27
32
name="BasicTestMemory",
28
33
description="Basic memory for testing short-term functionality"
29
34
)
30
35
31
-
# Configure memory
36
+
# Export the memory ID as an environment variable for reuse
37
+
memory_id = basic_memory.get('id')
38
+
print(f"Created memory with ID: {memory_id}")
39
+
os.environ['AGENTCORE_MEMORY_ID'] = memory_id
40
+
```
41
+
42
+
43
+
### Using the Session Manager with Existing Memory
44
+
45
+
```python
46
+
import uuid
47
+
import boto3
48
+
from datetime import datetime
49
+
from strands import Agent
50
+
from bedrock_agentcore.memory.integrations.strands.config import AgentCoreMemoryConfig
51
+
from bedrock_agentcore.memory.integrations.strands.session_manager import AgentCoreMemorySessionManager
system_prompt="You are a helpful assistant. Use all you know about the user to provide helpful responses.",
47
73
session_manager=session_manager,
48
74
)
49
75
50
-
# Use the agent - conversations are persisted with intelligent retrieval
76
+
# Use the agent - conversations are automatically persisted
51
77
agent("I like sushi with tuna")
52
-
agent("What should I buy for lunch today?")# Agent remembers preferences
78
+
agent("What should I buy for lunch today?")
53
79
```
54
80
55
-
### Advanced Setup (Long-Term Memory)
56
81
57
-
For more sophisticated memory capabilities, create a memory with multiple strategies:
82
+
## Long-Term Memory (LTM)
83
+
84
+
Long-term memory provides advanced capabilities with multiple strategies for learning and storing user preferences, facts, and session summaries across conversations.
85
+
86
+
### Creating LTM Memory with Strategies
87
+
88
+
!!! note "One-time Setup"
89
+
Similar to STM, the LTM memory resource creation is typically done once, separately from your agent application. In production, you would create the memory resource with strategies through the AWS Console or a separate setup script.
90
+
91
+
Bedrock AgentCore Memory supports three built-in memory strategies:
The `{actorId}` and `{sessionId}` placeholders are automatically replaced with the values from your configuration.
236
+
237
+
See the following docs for more on namespaces: [Memory scoping with namespaces](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/session-actor-namespace.html)
238
+
239
+
140
240
141
241
## Important Notes
142
242
143
-
> **Session Limitations:** Currently, only **one** agent per session is supported when using AgentCoreMemorySessionManager. Creating multiple agents with the same session will show a warning.
243
+
!!! note "Session Limitations"
244
+
Currently, only **one** agent per session is supported when using AgentCoreMemorySessionManager. Creating multiple agents with the same session will show a warning.
0 commit comments