strands.memory.memory_manager
Cross-session memory retrieval and storage for agents.
MemoryManager
Section titled “MemoryManager”class MemoryManager(Plugin)Defined in: src/strands/memory/memory_manager.py:63
Provides cross-session memory retrieval and storage for agents.
Example:
from strands import Agentfrom strands.memory import MemoryManager
memory_manager = MemoryManager(stores=[my_store])agent = Agent(model=model, memory_manager=memory_manager)agent("Remember I prefer dark mode")
results = await memory_manager.search("user preferences")__init__
Section titled “__init__”def __init__(stores: list[MemoryStore], search_tool_config: MemoryToolConfig | bool = True, add_tool_config: MemoryAddToolConfig | bool = False) -> NoneDefined in: src/strands/memory/memory_manager.py:81
Initialize the memory manager.
Arguments:
stores- One or more memory stores to manage.search_tool_config- Search tool configuration.True(default) registers asearch_memorytool with default name/description; a :class:MemoryToolConfigcustomizes it;Falsedisables it.add_tool_config- Add tool configuration.False(default) disables the add tool;Truelets it write to all writable stores; a :class:MemoryAddToolConfigrestricts/customizes it.
Raises:
ValueError- Ifstoresis empty, a store name is duplicated, a writable store has no write sink, an extraction config is misconfigured, or the add tool is enabled/scoped against stores that cannot accept discreteaddwrites.
@propertydef tools() -> list[AgentTool]Defined in: src/strands/memory/memory_manager.py:229
Tools registered by this plugin: search/add plus any store-provided tools.
Widens the base :class:~strands.plugins.plugin.Plugin annotation because
a store’s get_tools may contribute any
:class:~strands.types.tools.AgentTool.
search
Section titled “search”async def search( query: str, options: MemorySearchOptions | None = None) -> list[MemoryEntry]Defined in: src/strands/memory/memory_manager.py:238
Search stores for entries matching the query.
Unscoped: searches all configured stores when options.stores is
omitted. Results are attributed to their store via store_name and
concatenated in target order.
Raises:
ValueError- If a named store is not found (raised before querying).
async def add(content: str, options: MemoryAddOptions | None = None) -> NoneDefined in: src/strands/memory/memory_manager.py:302
Add content to writable stores.
Unscoped: targets all configured writable stores. Target stores are
validated first, then writes are awaited concurrently; per-store failures
are logged and surfaced as an
:class:~strands.types.exceptions.AggregateMemoryError.
Raises:
ValueError- If a named store is not found or is read-only, or if no writable store matched.AggregateMemoryError- If any targeted store write fails.
init_agent
Section titled “init_agent”def init_agent(agent: Agent) -> NoneDefined in: src/strands/memory/memory_manager.py:508
Initialize the plugin with the agent.
Wires up automatic extraction for any store configured with an
ExtractionConfig. A no-op when no store uses extraction.
Extraction runs in the background. The synchronous Agent(...) entry
point awaits :meth:flush after each invocation so writes persist;
callers driving the agent through their own event loop should await
:meth:flush at a shutdown boundary.
async def flush() -> NoneDefined in: src/strands/memory/memory_manager.py:542
Save every store’s remaining messages and wait for all saves to finish.
A no-op when no store has extraction configured. Drains automatic
extraction only; add_memory fire-and-forget writes are not awaited
here.