Skip to main content
Version: Next

Choosing a Memory Backend

Agent Kernel has two different kinds of memory, and they solve different problems:

You need to remember...UseLifetime
The current conversation (history, agent state)Session storeUntil the session expires or is cleared
Temporary data during one requestVolatile cacheOne request
Data across turns without sending it to the LLMNon-volatile cacheOne session
Durable knowledge shared by many sessions and agentsKnowledge baseUntil you delete it

This page helps you choose a session store and cache, then explains when a knowledge base is the right tool instead. For full details, see Session, Memory Management and Knowledge Bases.

Start simple

Use in_memory for your very first run. Move to Redis when you want the conversation to survive a restart.

Session store comparison​

A session store holds conversation history and framework state. Agent Kernel selects one from session.type; you never construct it yourself.

Backendsession.typeWhere it runsSurvives restartShared by processesExtra to installBest for
In-memoryin_memoryYour process❌❌noneFirst run, tests, single process
RedisredisSelf-hosted or any cloud✅✅agentkernel[redis]Local dev that survives restarts, containerized production
ValkeyvalkeySelf-hosted or AWS ElastiCache✅✅agentkernel[valkey]Same as Redis with an open-source license
DynamoDBdynamodbAWS✅✅agentkernel[aws]AWS serverless (Lambda)
Cosmos DBcosmosdbAzure✅✅agentkernel[azure]Azure Functions and Container Apps
FirestorefirestoreGoogle Cloud✅✅agentkernel[gcp]GCP Cloud Run

Rules of thumb:

  • First run: leave in_memory (the default). There is nothing to install or run.
  • Local development that should survive a restart: use Redis — one Docker command is all the setup you need.
  • Deploying to a cloud: use that cloud's managed store — DynamoDB on AWS, Cosmos DB on Azure, Firestore on GCP. They need no server for you to operate.
  • Choosing between Redis and Valkey: they are wire-compatible. Pick Valkey if you want the open-source project or ElastiCache's Valkey engine; otherwise Redis.

Quick chooser​

Setup steps, env vars, and YAML for every backend — including caching — are in the Session reference; the Configuration page lists every field. This page only helps you pick.

Small working example​

This example proves the backend is wired up without calling an LLM. It writes one value and then reads it back in a separate process — so it only works with a persistent backend such as Redis.

config.yaml

session:
type: redis
redis:
url: redis://localhost:6379
prefix: "ak:sessions:"

memory_demo.py

from agentkernel.core.builder import SessionStoreBuilder

store = SessionStoreBuilder.build()
session = store.load("demo-session")

if session.get("greeting") is None:
session.set("greeting", "hello from the first process")
store.store(session)
print("wrote:", session.get("greeting"))
else:
print("read:", session.get("greeting"))

Run it twice:

python memory_demo.py # wrote: hello from the first process
python memory_demo.py # read: hello from the first process

The second run reads the value from Redis. With session.type: in_memory it would print wrote: both times, because each process starts with an empty store.

In a real application you do not write this code: configuring session.type is enough, because Runtime and the framework adapters create and use the store for you. The script exists only so you can verify your configuration.

Session memory vs. knowledge bases​

Session memory is per conversation. A knowledge base is durable, shared, and retrieved on demand.

QuestionAnswer
Should the last few turns influence this answer?Session memory
Should this data disappear when the conversation ends?Session memory or a cache
Must a different user or session see the same information tomorrow?Knowledge base
Is the data a large document, manual, or dataset?Knowledge base
Do you need search by meaning, graph traversal, or SQL?Knowledge base with the matching backend

A useful pattern combines both: retrieve from a knowledge base in a pre-hook, store the result in the session's volatile cache for the rest of the request, and keep the LLM prompt small.

Knowledge base comparison​

A knowledge base is not a replacement for sessions. Pick it when the knowledge must outlive the conversation.

BackendKindRetrievalWriteExtraBest for
ChromaDBVectorSemantic search✅agentkernel[chromadb]FAQs, manuals, natural-language facts
Neo4jGraphCypher queries✅agentkernel[neo4j]Entities, relationships, connected data
StarburstSQLSQL (Trino)❌ read-onlyagentkernel[trino]Existing warehouses, MongoDB, Sheets
OKF bundleDocumentsLexical search, fetch, browse✅ if the store is writablenone (S3 needs agentkernel[aws])Markdown docs in Git or S3, no database to run

Rules of thumb:

  • Start with ChromaDB if you want "search my documents by meaning".
  • Use Neo4j when the question is about how things are connected.
  • Use Starburst when the data already lives in a queryable system.
  • Use an OKF bundle when your knowledge is already Markdown and you do not want to operate a database.

The full capability model and tool set are documented in Knowledge Bases.

Minimal ChromaDB example​

pip install "agentkernel[openai,chromadb]"
from agents import Agent
from agentkernel.cli import CLI
from agentkernel.knowledgebase.chroma import ChromaManager
from agentkernel.knowledgebase.knowledgebuilder import KnowledgeBuilder
from agentkernel.openai import OpenAIModule, OpenAIToolBuilder

docs = ChromaManager(persist_path="./chroma", name="Docs").add_schema(
{"description": "Product documentation, retrieved by meaning."}
)
docs.write(
[{"text": "Our product offers a 30-day free trial with no credit card required.", "metadata": {"source": "pricing-faq"}}]
)

agent = Agent(
name="docs_assistant",
model="gpt-4.1-mini",
instructions="Use the read_kb tool with backend 'Docs' to answer from the product documentation.",
tools=OpenAIToolBuilder.bind(KnowledgeBuilder([docs]).build()),
)

OpenAIModule([agent])
CLI.main()

Minimal OKF example (no database)​

# config.yaml — a folder of Markdown files under ./bundle
okf:
databases:
handbook:
type: local
uri: ./bundle
consumer: [Support_Agent]

For a complete walkthrough, see the Knowledge Bases guide and the runnable examples under examples/cli/knowledgebase/openai/.

Troubleshooting​

SymptomLikely causeFix
unknown session store type 'X'Typo or unsupported nameUse one of in_memory, redis, valkey, dynamodb, cosmosdb, firestore
session.type: redis requires the 'redis' extraOptional SDK not installedpip install "agentkernel[redis]" (or the matching extra)
Connection refused / timeout (Redis, Valkey)Server not running or wrong URLStart the server and check the URL; put a password in the URL
Sessions disappear between runsin_memory, or a new process/instanceUse a persistent backend
Works locally, not across podsProcess-local cache or in_memoryRemove session.cache and use a shared backend
DynamoDB ResourceNotFoundException or key errorTable missing or wrong keysPartition key session_id, sort key key
Cosmos DB connection or table errorWrong connection-string formatUse the Table API format (DefaultEndpointsProtocol=...;AccountName=...;AccountKey=...;TableEndpoint=...), see Session
Firestore documents never expireNo TTL policyAdd a TTL policy on expiry_time
Configuration seems ignoredWrong working directoryRun where config.yaml lives, or set AK_CONFIG_PATH_OVERRIDE

Agent Kernel logs Building '<type>' session store when it builds the store, which is the quickest way to confirm which backend is active.

Next steps​

Ready to Ship Your
First Agent?

Free, open-source, Apache 2.0. No licensing costs, no vendor lock-in. Join hundreds of developers building production AI agents with Agent Kernel.

Agent Kernel
Ask Agent Kernel