Run call starts with a clean context.
Built-in stores
| Store | Package | Infrastructure | Best for |
|---|---|---|---|
| In-memory | pkg/memory/inmemory | None | Testing, single-process |
| SQLite | pkg/memory/sqlite | None (pure Go) | Dev, embedded, zero-dep |
| PostgreSQL | pkg/memory/postgres | Postgres server | Production SQL |
| Redis | pkg/memory/redis | Redis server | Fast sessions, TTL |
core.MemoryStore and plug in identically via chainforge.WithMemory(store).
In-memory store
sessionID. Different IDs are fully isolated.
Options
The in-memory store accepts functional options to control session lifecycle:| Option | Description | Default |
|---|---|---|
WithTTL(d) | Sessions that have not received a new message within d are cleared on the next Get. TTL resets on every Append (sliding window). | No expiry |
WithMaxMessages(n) | After each Append, if the session exceeds n messages the oldest are dropped. | Unlimited |
WithTTL to prevent unbounded memory growth in long-running processes, and WithMaxMessages to cap per-session context size.
SQLite store
Zero infrastructure required — pure Go, no cgo.PostgreSQL store
pgx.Identifier.
Redis store
{prefix}:{sessionID}). TTL is reset on every Append (sliding window).
Custom store
Implementcore.MemoryStore to use any other backend:
History summarization
WhenWithMaxHistory is set, old messages are normally dropped. Use WithHistorySummarizer to compress them into a single compact message instead:
maxHistory:
- The oldest
len(history) - (maxHistory - 1)messages are sent to the summarizer agent. - The summary is stored as a single
[Summary: ...]message. - The
maxHistory - 1most recent messages are kept verbatim. - The compressed history (summary + recent) replaces the full history in the memory store.
maxHistory messages: one summary + maxHistory-1 recent. On subsequent runs the same compression can happen again, layering summaries.
Session isolation: the summarizer runs under "<sessionID>:summarizer" so its internal conversation does not interfere with the parent session.
Error handling: if the summarizer fails, Run returns the error immediately. There is no silent fallback to dropping messages.
Multi-agent memory isolation
The orchestrator automatically namespaces session IDs per step ("sessionID:step-N"), so each agent in a sequential pipeline has isolated history.
Semantic retrieval (RAG)
For semantic search over a knowledge base — not just conversation history — see the RAG guide. The RAG layer uses Qdrant as a vector store and exposesrag.NewQdrantRetriever and rag.NewQdrantIngestor built on the same qdrant.Store used for memory.