Memory Management
Agent Kernel provides a sophisticated memory management system with multiple layers designed for different use cases and lifecycles. Understanding these layers helps you build efficient, context-aware agents that don't bloat LLM prompts.
Memory Architecture
Memory Layers
Agent Kernel provides three distinct memory layers, each with different purposes and lifecycles.
1. Conversational State (Short-term Memory)
Purpose: Store conversation history and agent state that becomes part of the LLM context.
Lifecycle: Session-scoped, persists across multiple requests within a session.
Characteristics:
- ✅ Automatically managed by framework adapters
- ✅ Included in LLM context window
- ✅ Persists across agent invocations
- ⚠️ Contributes to token usage
- ⚠️ Should not contain large data (files, documents)
Managed By: Framework-specific runners (OpenAI, LangGraph, CrewAI, ADK)
What's Stored:
- User messages and agent responses
- Multi-turn conversation history
- Agent state and context
- Framework-specific metadata
You Don't Manage This Directly: The framework adapters automatically handle conversation persistence.
Learn about session management →
2. Auxiliary Memory (Smart Caching)
Purpose: Store additional data needed by tools and hooks without bloating the LLM context.
Agent Kernel provides two types of auxiliary caches with identical APIs but different lifecycles:
Volatile Cache (Request-Scoped)
Lifecycle: Cleared automatically after each request completes.
Perfect For:
- 📄 RAG context retrieved from knowledge bases
- 📁 File contents loaded for processing
- 🧮 Intermediate calculation results
- 🔄 Temporary processing data
- 🎯 Request-specific metadata
Benefits:
- ✅ Keeps LLM prompts clean and focused
- ✅ Reduces token usage and costs
- ✅ Auto-cleanup - no memory leaks
- ✅ Fast access during request lifecycle
Example Use Cases:
# Store RAG context in pre-hook
v_cache.set("rag_context", retrieved_documents)
# Access in tool without passing through LLM
def my_tool():
context = v_cache.get("rag_context")
# Process context...
# Automatically cleared after request