Skip to content

Give long-term memory

Long-term memory lets the agent recall durable facts across conversations without you re-supplying them. Strands harness keeps it on by default: it distills facts into markdown files, searches them before each turn, and folds the top matches into context. Persistence is plain files, independent of any session, so memory survives across sessions and works with sessions off.

With memory on, Strands harness runs a memory manager over a file-backed store under ./.agent/memory. Before each turn it searches that store and injects the most relevant entries, and the agent also gets a search_memory tool for on-demand recall. Extraction, distilling durable facts from the conversation, runs in the background every few turns on a small, credential-aligned model, so keeping memory costs little.

Memory injection runs on every turn, not only when the user speaks, so an autonomous step or a delegate consults memory at each turn of a multi-step task.

Set memory={"dir": ...} to store the memory files somewhere other than ./.agent/memory:

from strands_harness import create_harness
agent = create_harness(memory={"dir": "/var/lib/agent/memory"})

To keep facts somewhere other than local files, pass your own memory store (or several) as memory={"stores": [...]}. Strands harness still owns the manager, so its policy holds: injection on, search_memory on, and no write tool. This is the seam for a non-file backend without giving up Strands harness’s defaults:

from strands_harness import create_harness
from my_stores import PostgresMemoryStore
agent = create_harness(memory={"stores": [PostgresMemoryStore(dsn="postgres://...")]})

The generalist delegate shares these stores read-only, so it recalls the same memory but never writes throwaway subtask noise into it. To replace the manager wholesale, pass a full memory_manager through to the Agent instead; that owns its own stores and Strands harness steps aside.

Pass False/null (or set memory off) to disable memory entirely:

from strands_harness import create_harness
agent = create_harness(memory=False)

Extraction is background and turn-triggered, so a short run can end with its latest turns not yet written. Flush at your shutdown boundary to persist what is pending:

if agent.memory_manager:
await agent.memory_manager.flush()

The Strands harness CLI already flushes at the process boundary; a library consumer should do the same. For the memory manager and stores, see the Strands Harness SDK’s long-term memory documentation. For the full option list, see the configuration reference.