Skip to content

strands.memory.memory_manager

Cross-session memory retrieval and storage for agents.

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 Agent
from 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")
def __init__(stores: list[MemoryStore],
search_tool_config: MemoryToolConfig | bool = True,
add_tool_config: MemoryAddToolConfig | bool = False) -> None

Defined 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 a search_memory tool with default name/description; a :class:MemoryToolConfig customizes it; False disables it.
  • add_tool_config - Add tool configuration. False (default) disables the add tool; True lets it write to all writable stores; a :class:MemoryAddToolConfig restricts/customizes it.

Raises:

  • ValueError - If stores is 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 discrete add writes.
@property
def 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.

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) -> None

Defined 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.
def init_agent(agent: Agent) -> None

Defined 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() -> None

Defined 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.