Skip to main content
Memory lets agents remember facts and preferences across separate runs — scoped per user, tenant, or custom tags — without relying on conversation history alone. At the start of each run, the SDK performs a semantic search against the memory store using the incoming prompt as a query. Matching memories are injected as a labeled “Relevant Memories” message ahead of conversation history (the system prompt itself is left untouched) — so the model can reference past facts without the caller having to pass them explicitly. When both memory and retrieval prefetch are active, memory is placed first, RAG context second, keeping the request’s stable prefix (system prompt, tools) unaffected by either. The agent also stores new memories during or after the run depending on the store mode. Use it when users return across sessions, when preferences should persist beyond a single conversation, or when you need tenant- or project-scoped memory separate from chat history.

Enable

Pass WithMemory with a memory.Config:

Backends

Infrastructure setup (local dev):
Both Weaviate and pgvector are external shared stores — the same backend works for single-process and remote-worker deployments. Both processes must reach the same host or cluster.

Scope

Memories are isolated by scope. Attach context values on every run that should share memories:
By default, memories are also isolated per agent name. Override resolvers or add custom tags on memCfg.ScopeConfig:

Store modes

Use on-demand when the model should decide what to persist. Use always when every run should be saved without relying on tool calls — useful for pipelines and batch agents where you want comprehensive memory without explicit tool calls.

Memory kinds

Memories are tagged with a Kind that controls TTL defaults and filtering: Set memCfg.Recall.Kinds to filter which kinds are recalled for a given agent.
With StoreModeAlways and no custom Extract, the worker needs WithLLMClient when using remote workers — the SDK runs an LLM call at run-end to extract memories. Set memCfg.Store.Extract to a custom function if you want to avoid this extra LLM call.

Recall config

TTL and dedup

Override default TTLs with memCfg.TTLPolicy:
memCfg.Store.DedupMinScore (default 0.85) controls whether a near-duplicate memory is updated or appended. Lower to dedup more aggressively; raise to keep distinct entries.

Remote workers

Pass the same memory.Config to both NewAgent and NewAgentWorker. Both processes must reach the same backend host. See Distributed Execution for the full split-process setup.

Custom backend

Implement interfaces.Memory:
  • Store persists in scope and returns an ID. Support WithMemoryID for upserts.
  • Load returns scoped results ordered by relevance; honor limit and min-score options.
  • Clear deletes all memories in a scope.
Pass to memory.DefaultConfig(yourStore) and use with agent.WithMemory.

Example

Memory

Weaviate and pgvector store/recall demos

Conversation

Session history within a single chat

Retrieval

RAG from external document stores