Agent Memory¶
How memory systems integrate with the Agent class.
See Agent Overview for the core Agent class, roles, and configuration. See Memory Module for the full memory system documentation.
Memory Architecture¶
Cogent provides five composable memory systems:
| System | Parameter | Purpose |
|---|---|---|
| Conversation | conversation=True |
Thread-based message history (default ON) |
| ACC | acc=True |
Agentic Context Compression — prevents drift |
| Knowledge | memory=True |
Long-term memory with remember/recall tools |
| Episodic | episodic=True |
Graph-backed temporal recall across sessions |
| Cache | cache=True |
Semantic cache for tool outputs |
Episodic memory supports optional reflection — EpisodicMemory(reflection=True) (every turn)
or EpisodicMemory(reflection=N) (every N turns) — which synthesizes observations into
reusable lessons stored in both the episodic graph and semantic memory.
See Memory Module for detailed explanation of how each system works.
Long-term memory with tools¶
agent = Agent(name="Assistant", model="gpt4", memory=True)
Agent gets remember(), recall(), forget() tools¶
Semantic cache for expensive tools¶
agent = Agent(name="Assistant", model="gpt4", cache=True)
All systems together¶
agent = Agent(
name="SuperAgent",
model="gpt4",
acc=True, # Prevents context drift
memory=True, # Long-term facts
cache=True, # Cache tool outputs
)
ACC (Agentic Context Compression)¶
For long conversations (>10 turns), enable ACC to prevent memory drift:
from cogent.memory.acc import AgentCognitiveCompressor
# Simple: Enable with defaults
agent = Agent(name="Assistant", model="gpt4", acc=True)
# Advanced: Custom ACC with specific bounds
acc = AgentCognitiveCompressor(max_constraints=5, max_entities=20)
agent = Agent(name="Assistant", model="gpt4", acc=acc)
See docs/acc.md for detailed ACC documentation.
Semantic Cache¶
For expensive tools, enable semantic caching to avoid redundant calls:
from cogent.memory import SemanticCache
from cogent.models import create_embedding
# Simple: Enable with defaults
agent = Agent(name="Assistant", model="gpt4", cache=True)
# Advanced: Custom SemanticCache instance
embed = create_embedding("openai", "text-embedding-3-small")
cache = SemanticCache(
embedding=embed,
similarity_threshold=0.90, # Stricter matching
max_entries=5000,
default_ttl=3600, # 1 hour
)
agent = Agent(name="Assistant", model="gpt4", cache=cache)
See docs/memory.md#semantic-cache for detailed cache documentation.