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
Copy file name to clipboardExpand all lines: documentation/docs/user-guide/memory/quickstart.md
+7-134Lines changed: 7 additions & 134 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,6 @@ The steps are as follows
7
7
1. Create a memory resource containing a semantic strategy
8
8
2. Write events (conversation history) to the memory resource.
9
9
3. Retrieve memory records from long term memory
10
-
4. Integrate with an agent
11
10
12
11
## Prerequisites
13
12
@@ -25,6 +24,7 @@ cd agentcore-memory-quickstart
25
24
python -m venv .venv
26
25
source .venv/bin/activate
27
26
pip install bedrock-agentcore
27
+
pip install bedrock-agentcore-starter-toolkit
28
28
```
29
29
30
30
@@ -38,10 +38,11 @@ A memory resource is needed to start storing information for your agent. By defa
38
38
We are going to create a memory resource with a semantic strategy so that both short term and long term memory can be utilized. This will take 1-2 minutes. Memory resources can also be created in the AWS console.
39
39
40
40
```python
41
-
from bedrock_agentcore.memory import MemoryManager
42
-
from bedrock_agentcore.session import MemorySessionManager
43
-
from bedrock_agentcore.constants import StrategyType
44
-
from bedrock_agentcore.models.strategies.semantic import SemanticStrategy
41
+
from bedrock_agentcore_starter_toolkit.operations.memory.manager import MemoryManager
42
+
from bedrock_agentcore.memory.session import MemorySessionManager
43
+
from bedrock_agentcore.memory.constants import StrategyType
44
+
from bedrock_agentcore_starter_toolkit.operations.memory.models.strategies import (
@@ -157,135 +159,6 @@ Important information about the user is likely stored is long term memory. Agent
157
159
158
160
The full example source file showing steps 1 - 3 is available [here](../../examples/semantic_search.md).
159
161
160
-
## Step Four: Putting it all together
161
-
162
-
Now that the concepts are clear, let’s incorporate this in an agent. The following example shows a conversational AI agent built using the Strands SDK that automatically extracts and remembers user preferences from conversations.
163
-
164
-
Install dependencies for the strands SDK.
165
-
166
-
```bash
167
-
pip install strands
168
-
pip install flask
169
-
```
170
-
171
-
Create a new file called `preference_saver.py` and add the following code.
172
-
173
-
```python
174
-
from bedrock_agentcore.memory import MemoryManager
175
-
from bedrock_agentcore.session import MemorySessionManager
176
-
from bedrock_agentcore.constants import StrategyType, ConversationalMessage, MessageRole
177
-
from strands import Agent
178
-
from flask import Flask, request, jsonify
179
-
import uuid
180
-
181
-
# Initialize memory storage for the agent
182
-
# This creates a persistent memory that can store user preferences and conversation history
print("🚀 Starting memory-enhanced conversational agent server on port 8080...")
258
-
print("Send POST requests to http://localhost:8080/invoke with JSON: {'message': 'your message', 'user_id': 'user123'}")
259
-
app.run(host='0.0.0.0', port=8080, debug=True)
260
-
```
261
-
262
-
Execute the agent code with:
263
-
264
-
```bash
265
-
python `preference_saver.py`
266
-
```
267
-
268
-
and wait for the “Memory created” message. In another terminal, invoke the agent using the following commands:
269
-
270
-
#### Invocation 1:
271
-
```bash
272
-
curl -X POST http://localhost:8080/invoke -H "Content-Type: application/json" -d '{"message": "My name is Alice and I like pepperoni on pizza", "user_id": "alice"}'
273
-
```
274
-
275
-
The preference is extracted asynchronously and can take up to a minute to be extracted. Please give it a minute before the next invocation.
276
-
277
-
#### Invocation 2:
278
-
279
-
```bash
280
-
curl -X POST http://localhost:8080/invoke -H "Content-Type: application/json" -d '{"message": "What topping do I like on pizza?", "user_id": "alice"}'
281
-
```
282
-
283
-
284
-
The agent stores each conversation turn as a memory event, allowing the UserPreferenceMemoryStrategy to automatically extract and consolidate personal preferences over time. Before responding to new messages, it queries the
285
-
memory store to retrieve relevant context, then saves the new user-bot exchange as another memory event.
286
-
287
-
The end result is a context-aware agent!
288
-
289
162
## What’s Next?
290
163
291
164
Consider the following as you continue your AgentCore journey
0 commit comments