Short-Term Memory Best Practices
Ten practices for keeping session state correct, cheap, and isolated while multi-turn agents stay inside the context window.
Search across all documentation pages
Ten practices for keeping session state correct, cheap, and isolated while multi-turn agents stay inside the context window.
Use this list when you add chat memory, Redis sessions, scratchpads, or summarization to an agent.
| Stage | Habits | Exit criterion |
|---|---|---|
| Design | 1-3 | Scoped keys; state diagram for history/pad/cache |
| Implement | 4-6 | Budget function + atomic trim in the turn path |
| Harden | 7-9 | Summarize + TTL + cold/hot split live |
| Operate | 10 | Automated isolation and retention tests in CI |
messages = [] on a multi-tenant server.# Pattern: scoped load → budget → model → save with TTL
# key = f"agent:stm:{tenant}:{user}:{session}"
# sess = load(key) or new_session()
# sess["messages"] = trim_or_summarize(sess["messages"], budget=...)
# resp = model.complete(project(sess)) # history + compact scratchpad
# append_turn(sess, user, resp); save(key, sess, ttl=SESSION_TTL)Isolation keys (1), input budget with reserves (4), and tests for cross-tenant deny plus retention (10).
No. They reduce how often you summarize, not the need for isolation, TTLs, or cost control.
Only when multiple workers, restarts, or shared sessions require it. Single-process prototypes can start in memory with the same keying discipline.
When early turns hold goals, constraints, or ids you still need. Truncate pure chit-chat.
Short-term habits keep one session healthy. Promote durable facts deliberately; do not treat TTL session blobs as a CRM.
Next to the agent skill or graph definition, versioned with the code that validates them.
Tokens of history per turn, p95 latency, and cost per successful task rising while task success stays flat.
Frameworks supply checkpoints and helpers. You still own key scope, budgets, retention, and tests.
Related: Short-Term Memory Basics
Related: Managing Conversation History Within a Context Budget
Related: Redis for Fast Short-Term Agent State
Related: Session Isolation
Related: Summarization Strategies for Long-Running Conversations
Stack versions: Pins from the category manifest (verify at build): OpenRouter (~315+ models, July 2026 pricing/fees); LangGraph 1.0+; CrewAI 1.14+; Microsoft Agent Framework 1.0; Vercel AI SDK 6; Pydantic AI (latest); LlamaIndex (latest); OpenAI Agents SDK (latest + MCP); MCP (Linux Foundation governance); A2A (HTTP+SSE+JSON-RPC 2.0); Solana
@solana/web3.js+@solana/spl-token.
Reviewed by Chris St. John·Last updated Jul 16, 2026