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: docs/AGENT_CONFIGURATION.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,7 @@ A basic conversational agent using the Strands framework with AgentCore Memory i
16
16
17
17
- Multi-turn conversational chat
18
18
- Maintains conversation history with short-term memory
19
+
-**Optional long-term memory**: When `use_long_term_memory: true` is set in `config.yaml`, the agent uses a `SemanticMemoryStrategy` to extract and recall facts across sessions (keyed by Cognito user ID). See [Memory Integration Guide](MEMORY_INTEGRATION.md#enabling-long-term-memory) for details.
19
20
- Streams responses for better UX
20
21
- Authenticated via Cognito (user identity tracked in memory)
Copy file name to clipboardExpand all lines: docs/MEMORY_INTEGRATION.md
+66Lines changed: 66 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,46 @@ AgentCore provides two types of memory: **short-term memory** stores raw convers
6
6
7
7
---
8
8
9
+
## Enabling Long-Term Memory
10
+
11
+
Long-term memory (LTM) is supported on the **`strands-single-agent`** pattern. It uses a `SemanticMemoryStrategy` to automatically extract and store facts from conversations, enabling the agent to recall information across sessions. Facts are keyed by the Cognito `userId`, so each user gets their own persistent memory.
12
+
13
+
### How It Works
14
+
15
+
1.**Infrastructure**: The CDK stack always creates the `SemanticMemoryStrategy` on the memory resource (there is no cost to simply define the strategy). A `USE_LONG_TERM_MEMORY` environment variable is passed to the agent runtime.
16
+
2.**Agent behavior**: When `USE_LONG_TERM_MEMORY` is `"true"`, the Strands agent's `AgentCoreMemorySessionManager` is configured with a `retrieval_config` that reads from the `/facts/{actorId}` namespace on each turn. When `"false"` (the default), only short-term conversation history is active.
17
+
3.**Fact extraction**: AgentCore processes conversation events asynchronously and extracts factual information (e.g., "the user lives in Seattle", "the user prefers Python"). These facts are stored under `/facts/{actorId}` and retrieved on subsequent turns to personalize responses.
-**Storage**: $0.75 per 1,000 memory records stored
39
+
-**Retrieval**: $0.50 per 1,000 retrieval calls
40
+
41
+
When `use_long_term_memory` is `false`, neither cost applies — short-term memory (conversation history) is the only active feature.
42
+
43
+
### Other Patterns
44
+
45
+
The **`langgraph-single-agent`** pattern does not currently use long-term memory. It uses `AgentCoreMemorySaver` as a LangGraph checkpointer for short-term conversation persistence only. See the LangGraph section below for details on adding long-term memory via `AgentCoreMemoryStore`.
46
+
47
+
---
48
+
9
49
## Step 1: Configure Memory with CDK
10
50
11
51
Memory resources are created using [CloudFormation L1 constructs](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-bedrockagentcore-memory.html). **L2 constructs will be available in future releases.**
**With long-term memory enabled** (see [Enabling Long-Term Memory](#enabling-long-term-memory) above):
201
+
202
+
The `strands-single-agent` pattern conditionally enables LTM retrieval based on the `USE_LONG_TERM_MEMORY` environment variable. When enabled, the agent retrieves facts from the `/facts/{actorId}` namespace on each turn:
Description: `Short-term memory for ${config.stack_name_base} agent`,
244
-
MemoryStrategies: [],// Empty array = short-term only (conversation history)
248
+
MemoryStrategies: [
249
+
{
250
+
// Extracts and stores factual information shared by the user across sessions.
251
+
// Stored under /facts/{actorId} — retrieved on each turn to personalise responses.
252
+
SemanticMemoryStrategy: {
253
+
Name: "FactExtractor",
254
+
Namespaces: ["/facts/{actorId}"],
255
+
},
256
+
},
257
+
],
245
258
MemoryExecutionRoleArn: agentRole.roleArn,
246
259
Tags: {
247
260
Name: `${config.stack_name_base}_Memory`,
@@ -339,6 +352,14 @@ export class BackendStack extends cdk.NestedStack {
339
352
MEMORY_ID: memoryId,
340
353
STACK_NAME: config.stack_name_base,
341
354
GATEWAY_CREDENTIAL_PROVIDER_NAME: `${config.stack_name_base}-runtime-gateway-auth`,// Used by @requires_access_token decorator to look up the correct provider
355
+
// Controls whether the agent activates long-term semantic memory retrieval.
356
+
// The memory resource always includes the SemanticMemoryStrategy (no cost to define it),
357
+
// but retrieval is only performed when this is "true". See config.yaml: use_long_term_memory.
0 commit comments