Short-Term Memory: What an Agent Actually Needs Within One Run
Short-term memory is everything an agent must hold for the current session so the next decision is grounded in what already happened.
Search across all documentation pages
Short-term memory is everything an agent must hold for the current session so the next decision is grounded in what already happened.
It is not a vector store of lifelong facts.
It is the working set: transcript turns, intermediate plans, and reusable tool results that keep one multi-turn run coherent.
A run or session is a bounded unit of work: one user conversation, one support ticket thread, or one autonomous job with a session id.
Everything the model sees on the next model call is working memory.
That working set is finite because the model has a context window (input plus output tokens per call).
Three buckets of short-term data solve different jobs:
ticket_id, files_touched, confidence). Needed so multi-step work does not rely on the model re-deriving status from a messy transcript.These are not three chat roles.
They are three storage concerns that you may serialize into messages when you call the model, but you should manage them separately outside the prompt when possible.
Long-term memory (preferences, CRM facts, embeddings) is a different product surface.
If a fact must matter next week for a different session, design an extraction and retrieval path.
If a fact only matters until the user closes the chat, keep it short-term.
Typical turn flow:
(tenant_id, user_id, session_id) - never by user message content alone.# Conceptual session shape (not a framework API)
session = {
"messages": [], # conversation history
"scratchpad": {}, # structured task state
"tool_cache": {}, # key -> {value, expires_at}
}History is usually a list of role-tagged messages the chat API accepts.
Include tool-call and tool-result messages when the provider requires them for multi-turn tool use.
Do not treat every log line as history.
Debug traces, raw HTML, and multi-megabyte blobs belong in storage with a short pointer in the prompt, not as full pastes every turn.
The scratchpad is authoritative structured state.
The model may propose updates; your runtime validates and writes them.
Good scratchpad fields are small, typed, and goal-oriented: goal, steps_done, steps_remaining, blockers, artifacts.
Bad scratchpads are free-form diaries that grow without bound.
Cache when:
Invalidate when the world may have changed (user uploaded a new file, write tool succeeded, TTL expired).
Only a projection of these stores enters each model call.
You might send the last N turns of history, a one-screen scratchpad JSON, and one cached tool snippet relevant to the current step.
The full history can live in Redis or a database while the model sees a budget-safe view.
Plan-and-execute agents benefit from a scratchpad that holds the plan and step index separately from chat chatter.
ReAct-style loops still need history of observations, but you can collapse early observations into "done: searched X, found Y" on the scratchpad and drop the raw pages.
Handoffs should pass a package: goal, constraints, scratchpad snapshot, and a short transcript excerpt - not the entire unbounded log.
Each specialist may keep its own scratchpad keyed under the same session id with a role prefix.
Short-term memory often contains PII, secrets from tool output, and other tenants' data if isolation fails.
Encrypt at rest when required, redacted logs, and hard keying by tenant are part of short-term design, not polish.
| Approach | Strength | Weakness | Best Fit |
|---|---|---|---|
| All state in the prompt | Simple, no external store | Hits context limits fast; hard multi-instance | Demos, single-process CLIs |
| History list only | Natural chat continuity | Weak for multi-step plans; noisy | Short Q&A agents |
| History + scratchpad | Clear task progress | Extra schema to design | Multi-step workflows |
| History + scratchpad + tool cache | Fewer redundant tool calls | Cache invalidation bugs | Research, support, data agents |
| Durable DB as only store | Survives process restarts | Latency; must still project into context | Multi-worker production |
A session id, a message list you append every turn, and a max history policy (count or tokens). Add a scratchpad when tasks span more than a few tool steps.
Both can: keep a compact observation in history for the next decision, and keep the full payload in a cache or object store if you may need it again.
The system prompt is relatively stable policy. Short-term memory is session-specific and changes every turn.
No. In-memory dicts work for single-process demos. Redis (or equivalent) helps when multiple workers, restarts, or shared sessions appear.
Truncate when early turns are disposable small talk. Summarize when early turns hold goals, constraints, or decisions you still need.
Not for user-facing chat. Users expect conversational continuity. Scratchpads complement history for machine-readable progress.
Usually not into long-lived user history. Keep them in ephemeral traces for debug, subject to provider and privacy rules.
Graph/checkpoint state is a form of short-term (and sometimes durable) session memory. Map their channels onto history vs scratchpad vs cache deliberately.
Long-lived secrets (prefer vaults), other tenants' data, and unbounded binary blobs without references and size caps.
Simulate multi-turn scripts: assert messages append, budgets trim, scratchpad updates, and session A cannot read session B.
No. One run is many model and tool calls under one session until a stop condition or user ends the conversation.
When you deliberately extract facts meant to survive session end and retrieve them later under a user or org scope.
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