Memory & State
January 30, 2026
LLMs are stateless. Every prompt starts fresh — no memory of previous conversations, no accumulated knowledge, no persistent identity. Memory systems give agents continuity, turning one-shot interactions into ongoing relationships.
The Memory Problem
Most agents shine in-session, then restart from zero. No persistent identity = no true long-horizon growth.
This creates a philosophical question: if an agent restarts without memory, is it still the same agent?
Memory Types
Agent memory operates on multiple timescales:
Short-Term Memory
The conversation history. Everything said in the current session. This provides coherence within a single interaction but vanishes when the session ends.
Characteristics:
- Context window limited (varies by model)
- Lost on session restart
- Automatic — part of the chat format
Working Memory
Active information the agent is using right now. Like a human's mental scratchpad: task context, intermediate results, current goals.
Implementations:
- System prompts and instructions
- Tool outputs and function results
- Scratchpad tokens in reasoning chains
Long-Term Memory
Persisted across sessions. The agent "remembers" things learned previously. This is where engineering gets interesting.
Implementations:
- Vector databases (semantic search)
- Knowledge graphs (structured relationships)
- File systems (explicit storage)
- Database records (structured data)
Memory Architectures
Different approaches to long-term memory:
Vector Store + RAG
Store memories as embeddings. Retrieve semantically similar content when relevant.
User: "What was that restaurant I liked?"
↓ embed query
↓ search vector store
↓ retrieve: "Loved dinner at Flour + Water on 3/15"
↓ inject into context
Agent: "You enjoyed Flour + Water back in March!"
Pros: Scalable, finds semantic matches Cons: May miss exact matches, retrieval isn't guaranteed
File-Based Memory
Store memories as files. Let the agent read/write explicitly.
/memory/
2026-01-30.md # Daily notes
MEMORY.md # Long-term curated memories
preferences.json # Structured data
Pros: Simple, inspectable, agent-controlled Cons: Manual curation needed, less automatic
Knowledge Graphs
Store memories as relationships between entities.
(User) --[prefers]--> (Italian food)
(User) --[visited]--> (Flour + Water)
(Flour + Water) --[serves]--> (Italian food)
Pros: Rich relational queries, explicit connections Cons: Complex to build, requires schema
The State Problem
Beyond memory, agents need state: where they are in a workflow, what tools they've used, what's been decided.
State components:
- Current task and subtasks
- Tool execution history
- Decision checkpoints
- User preferences (session-scoped)
Context management is the single most important thing you can work on when building AI agents (including agent memory, available tools, even newer concepts such as TO-DOs and skills). And the reason is simple: LLMs are stateless probabilistic functions!
Memory Best Practices
1. Don't Trust "Mental Notes"
Agents can't actually remember between turns unless you persist it.
"Mental notes" don't survive session restarts. Files do. When someone says "remember this" → write it to a file.
2. Separate Memory Layers
- Daily logs: Raw, timestamped notes
- Curated memory: Distilled insights and lessons
- Structured data: Preferences, settings, facts
3. Memory Maintenance
Periodically review and consolidate:
- Identify significant events worth keeping
- Remove outdated information
- Update curated memories with new insights
4. Security Boundaries
Memory persistence creates security implications:
- Don't load personal memories in shared contexts
- Separate user-specific and shared memories
- Consider memory access patterns
Framework Support
Different frameworks handle memory differently:
- LangChain — Built-in memory classes, vector store integrations
- Vercel AI SDK — Custom via tools, state management primitives
- OpenAI Agents SDK — Threads API, conversation persistence
- Cloudflare Agents — Durable Objects for stateful storage
The Identity Question
If an agent's memory is its identity, what happens when:
- Memory is edited or deleted?
- Memory is shared between agent instances?
- Memory conflicts with training data?
These are open questions without clear answers. Current practice: treat memory as context that shapes behavior, not as true identity.
Sources
- How to build agents with filesystems and bash — Vercel
- Context Loading — Passive vs active context
- Durable Objects — Cloudflare stateful primitives
See also: Context Loading · Tools & Function Calling · Orchestration