Skip to content

AgentCore Memory Store

The AgentCore Memory Store, available in Python and TypeScript, implements the Strands MemoryStore interface on top of Amazon Bedrock AgentCore Memory. Search maps to AgentCore’s RetrieveMemoryRecords, and conversation turns are ingested for server-side memory extraction into long-term records. Attach it to an agent through a MemoryManager like any other store. See the Getting Started section for more information.

Use this integration for long-term memory through a memory manager. To persist and restore conversation history, use SnapshotSessionManagerSessionManager as described in the single-agent session guide.

Use an existing Amazon Bedrock AgentCore Memory resource with extraction strategies and AWS credentials to access it. Match the examples’ namespaces to those configured on your strategies. The store does not create the resource.

  • bedrock-agentcore >= 1.21.0
  • strands-agents >= 1.56.0
Terminal window
pip install "bedrock-agentcore[strands-agents]>=1.21.0"

To recall from multiple namespaces, use create_agentcore_memory_storescreateAgentCoreMemoryStores. It builds one store per namespace over a shared client. Attach the stores to an agent through a MemoryManager and enable extraction on one writer to capture conversation turns. Writes go to the shared conversation stream; the memory resource’s strategies decide which namespaces receive extracted records.

Set AGENTCORE_MEMORY_ID to your memory resource ID.

import os
from strands import Agent
from strands.memory import MemoryManager
from bedrock_agentcore.memory.integrations.strands.memorystore import (
create_agentcore_memory_stores,
)
stores = create_agentcore_memory_stores(
memory_id=os.environ["AGENTCORE_MEMORY_ID"],
actor_id="user-123",
session_id="session-1",
namespaces=[
{"namespace": "/facts/{actorId}", "writable": True},
{"namespace": "/preferences/{actorId}", "min_score": 0.5},
],
extraction=True,
region_name="us-east-1",
)
manager = MemoryManager(stores=stores)
agent = Agent(memory_manager=manager)

The import package is memorystore, without an underscore. With extraction enabled, the factory selects the first namespace not explicitly marked writable=False when no writer is specified. Set writable=True on one namespace to choose the writer explicitly, as above. Omit extraction and writer flags for recall-only stores.

A single AgentCoreMemoryStore can also be constructed directly when you only need one namespace:

import os
from strands import Agent
from strands.memory import MemoryManager
from bedrock_agentcore.memory.integrations.strands.memorystore import (
AgentCoreMemoryStore,
)
store = AgentCoreMemoryStore(
memory_id=os.environ["AGENTCORE_MEMORY_ID"],
actor_id="user-123",
session_id="session-1",
namespace="/facts/{actorId}",
writable=True,
extraction=True,
region_name="us-east-1",
)
manager = MemoryManager(stores=[store])
agent = Agent(memory_manager=manager)

Set namespace-specific options on each factory entry, and identity and extraction options at the top level. The direct AgentCoreMemoryStore constructor takes all options in one flat config.

OptionTypeDescription
memory_idmemoryIdstringMemory resource ID.
actor_idactorIdstringReplaces {actorId}.
session_idsessionIdstringReplaces {sessionId}.
namespacestringExact namespace prefix for recall.
namespace_pathnamespacePathstringSubtree query; direct constructor only, instead of namespace.
writablebooleanEnables conversation writes; false by default on a direct store.
extractionboolean or configEnables automatic dispatch, with cadence and filtering.
min_scoreminScorenumberMinimum relevance score for recall.

For custom extraction cadence, pass an extraction dictionary with cadence and filter to the factory. For example, use IntervalTrigger(turns=10) from strands.memory as the cadence. The direct constructor uses the Strands ExtractionConfig, whose cadence key is trigger.

See the package README for batching, score filtering, metadata, and the full namespace contract.

Conversation writes use CreateEvent for server-side extraction, preserving user and assistant roles. Flush pending writes at a shutdown boundary after asynchronous invocation or streaming.

Synchronous agent(...) calls flush automatically. After agent.invoke_async(...) or agent.stream_async(...), call await manager.flush() before closing the event loop. Reuse the manager while the same actor and session remain active to retain buffered turns and cadence state.

Strands logs extraction write failures and retains failed batches for retry. A completed flush() alone is not proof that events were persisted.

The store implements add_messages(), not the flat-string add() interface, so it does not enable the manager’s add_memory tool. Enable extraction to send conversation turns instead.

A completed flush does not confirm that server-side extraction has finished. Monitor write failures in logs; newly extracted records may not be immediately searchable.

  • One writable store per session. Mark at most one store writable for a given memory resource, actor, and session: multiple writers would emit duplicate events to the same stream. The factory rejects configurations with more than one writer.
  • Placeholders resolve at construction. Only {actorId} and {sessionId} are substituted client-side, into the namespace used for recall. Any other placeholder in a namespace causes construction to throw. Provision strategies with {actorId}/{sessionId}-only templates to match.
  • Cross-session recall. A namespace containing {sessionId} scopes recall to that session. Use an actor-only namespace to recall memories across sessions.