Help improve this page
To contribute to this user guide, choose the Edit this page on GitHub link that is located in the right pane of every page.
Choose an agent’s memory components
A model keeps no state between calls. Anything an agent remembers, from the previous turn to a preference a user stated last month, is stored outside the model and loaded back into its context. These stores hold what people told your agents, so they need the same retention, access control, and isolation as any other store of user data.
Agents typically need these capabilities in order as the workload grows more complex. Most agents with more than one turn need session state, and many also need durable checkpoints so that a conversation or a task survives a pod restart. Fewer need semantic recall, and only agents that personalize across sessions need consolidation. Each capability adds a component to operate and secure, so turn on only the ones your agent needs.
| Capability | Agent gains | You take on |
|---|---|---|
|
Session state |
Continuity between turns, and replicas that can serve any turn |
A key-value store |
|
Durable checkpoints |
State and conversations that survive the pod |
An Amazon S3 bucket |
|
Semantic recall |
Retrieval by meaning over a corpus or past interactions |
A vector index tied to one embedding model |
|
Consolidation |
Facts selected and reconciled across sessions, scoped per user |
A consolidation layer, plus model calls to extract what to keep |
The following diagrams show each path.
Open source and AWS services paths
The following table compares how each path provides each memory capability.
| Aspect | Open source | AWS services |
|---|---|---|
|
Session state |
Valkey in the cluster |
Amazon ElastiCache Serverless |
|
Durable checkpoints |
A versioned Amazon S3 bucket with one prefix per agent |
A versioned Amazon S3 bucket with one prefix per agent |
|
Semantic recall |
pgvector on Postgres, run in the cluster by the CloudNativePG operator |
Amazon S3 Vectors, in a shared vector bucket |
|
Consolidation |
The Mem0 library inside the agent, storing records in the semantic recall tier |
AgentCore memory, a managed service with its own record store |
|
Consolidation requires |
Semantic recall, the gateway, and |
No other memory capability |
|
Separation between agents |
One Postgres table per agent for Mem0 records |
Namespaces in one shared memory, and one vector bucket that every agent’s grant covers |
|
Who operates the stores |
You operate Valkey and Postgres, including backups, upgrades, and capacity |
The managed services, with no tier to operate |
Choose memory capabilities
An agent whose work ends within one task, such as a coding agent or a build-and-test agent, needs none of these. Its state is ephemeral, and its execution tier exchanges files through a workspace volume. For other agents, use the following:
-
The agent has more than one turn: session state. Turn it on before you run more than one replica.
-
A conversation or a task must survive a pod restart, or the execution tier returns files: durable checkpoints.
-
The agent answers questions over a corpus: semantic recall.
-
The agent personalizes across sessions, or several agents share one model of the same user: consolidation.
The capabilities you need don’t depend on the path you chose. Each has an open source and a managed option.
Session state
Most agents have more than one turn, and between turns they hold the conversation so far, intermediate results, and tool outputs. Kept in the pod, that state ties a session to one replica and disappears when the pod restarts. Kept in a key-value store, it lets any replica serve the next turn and survives a restart. A key-value store is enough, because the agent reads and writes this state by session ID and doesn’t search it.
The open source option is Valkey in the cluster. The managed option is Amazon ElastiCache Serverless for Valkey, or Amazon MemoryDB when the state must also survive a cache failure. Store structured facts that an agent writes and reads back in a relational database you already operate.
The cache is shared, so isolating one agent’s sessions from another’s is a design decision. See Store agent session state.
Durable checkpoints
Durable checkpoints hold state that must outlive the pod, such as a checkpoint an agent resumes from, the record of its actions, and files returned by the execution tier. Both paths use a versioned Amazon S3 bucket with one prefix per agent, enforced in each agent’s IAM policy. The reference agent saves its conversation there. If you split an agent into two tiers, the execution tier can exchange data only through a volume and this bucket. See Durable state in Amazon S3 and Save the conversation between turns.
Semantic recall
Semantic recall lets an agent find stored text by meaning instead of by key. An embedding model turns each piece of text into a vector, and a vector index returns the stored vectors closest to the vector of a query. An agent that answers questions over a corpus needs semantic recall, and an agent that needs only retrieval needs nothing more.
An index is bound to the embedding model that fills it. The vector length is fixed when the index is created, and so is the distance metric that ranks matches, so changing the embedding model means building a new index. Cosine distance suits most text embeddings.
The two options trade operating effort for control:
-
pgvector adds a vector index to Postgres. If you already operate Postgres, add the index there instead of running a second database for one index. You own backups, upgrades, and capacity. The sample includes a Postgres tier, run by the CloudNativePG operator, for clusters without one.
-
Amazon S3 Vectors is managed, with no tier to operate. Vectors live in a vector bucket that holds one or more indexes. A dimension mismatch isn’t detected until the first write, so confirm your embedding model’s vector length before you create an index.
Isolation between agents works the same way as for any shared store. In the sample, every agent’s IAM grant covers the whole shared vector bucket, so one agent can query another’s vectors unless you separate them. Give each agent its own index and scope its grant to that index, or keep vectors that must stay private in a store only that agent can reach.
Consolidation
Retrieval returns whatever was stored, including statements that are no longer true. Consolidation sits above the stores and decides what to keep. It extracts facts from conversations, reconciles a new statement with a stored one so that a changed preference replaces the old one, and scopes each record to a user and an agent. An agent that personalizes across sessions, or several agents that share one model of the same user, need consolidation. Most agents don’t, and it adds a stateful tier and the model calls that do the extraction.
Scoping is the security property of consolidation. A consolidated store holds facts about many people. If records aren’t scoped per user, an agent can return one person’s context in another person’s session. Both options scope by namespace, a path filled in from the user and session IDs on each event, such as /agents/{actorId}/{sessionId}. A strategy that defines no namespace pools every user’s records.
The two options differ in where consolidation runs:
-
Mem0 runs as a library inside the agent and stores records in the semantic recall tier. Its extraction and embedding calls are model calls the agent makes through the gateway with its own token, so they count against the agent’s budget and appear in its audit trail. The agent image must include Mem0. The reference sample’s reference image does.
-
AgentCore memory, a capability of Amazon Bedrock AgentCore, runs consolidation as a managed service with its own record store. A strategy tells it what to extract, such as user preferences, and its namespaces say where each record goes. In the sample, the stack has one memory and every agent’s grant covers all of it, because AgentCore memory has no ACK controller to create one per agent. The namespaces are then the only separation between agents.
Set how long records are kept from your organization’s data retention policy, because the store holds what people told your agents.
Memory in the reference sample
The base setup in the reference sample turns off all four. Each is a Terraform variable on both paths. enable_session_state turns on session state, enable_checkpoints durable checkpoints, enable_semantic_recall semantic recall, and enable_consolidation consolidation. Session state and durable checkpoints are set up in Store agent session state, and this page sets up the other two. Consolidation’s requirements differ by path:
-
Open source path. Consolidation also requires semantic recall, the gateway, and
platform-secrets. -
AWS services path. Consolidation doesn’t require semantic recall, because AgentCore Memory stores its own records.
Prerequisites
-
The base setup from Set up an Amazon EKS cluster for agent workloads, applied, and the in-cluster components from Set up EKS Capabilities and in-cluster components for agents, synced.
-
For consolidation on the open source path: the gateway from Route agent egress through a gateway, semantic recall,
platform-secrets, and an agent image that includes Mem0, such as the sample’s reference image. -
PAVED_PATHset toopen-sourceoraws-services, such as withexport PAVED_PATH=open-source. -
A shell with
kubectlaccess to the cluster, on the bastion or your workstation, and an agent deployed as in Deploy an agent on Amazon EKS. The commands use the reference agentresearchin namespaceagents.
Step 1: Turn on semantic recall and consolidation
This step turns on the capabilities your agents need. Outside these templates, create the same stores, grant each agent’s role access, and pass the resource names to the agent as environment variables.
The bootstrap script applies the rendered root Application, refreshes and syncs it, and waits for the Applications to converge. With --roll-agents, it then recreates each agent pod whose Sandbox changed, and prints a line for each agent, such as agents/research: recreating (env AGENT_MEMORY_ID added), or current for an agent that didn’t change.
Every Application reports Synced and Healthy. If one stays Progressing after its objects are ready, run the bootstrap script again, because Argo CD can keep the health it computed while they were starting. See Turn on a component later.
A Sandbox doesn’t replace its running pod when its spec changes, so without --roll-agents a sandboxed agent keeps running without the new variable. The --roll-agents on the sync recreates the pod. To confirm that the agent’s Sandbox has the new variable, run the following. The variable depends on the path:
-
Open source path.
AGENT_CONSOLIDATION_DB_HOST. -
AWS services path.
AGENT_VECTOR_BUCKET_ARNorAGENT_MEMORY_ID.
./scripts/run-stack.sh --root terraform/$PAVED_PATH -- bash -c "kubectl -n agents get sandbox research -o yaml | grep -A1 -E 'AGENT_CONSOLIDATION_DB_HOST|AGENT_VECTOR_BUCKET_ARN|AGENT_MEMORY_ID'"
An agent with runtime: deployment rolls automatically.
Step 2: Verify each capability as the agent
This step confirms each capability works with the agent’s own identity.
Clean up
To remove semantic recall and consolidation, turn it off as described in Turn on a component later. Set the variable to false, apply with scripts/apply.sh, and run the bootstrap script with --sync --prune. Set enable_consolidation to false first, then enable_semantic_recall, because consolidation on the open source path stores its records in the semantic recall tier.
Next steps
Evaluate agent output on Amazon EKS for grading what the agent does with its memory.