What is a session in AI agents?
In AI agents, a session is the durable record of one conversation or run, a log of messages, tool calls, results and state kept outside the model's context window and used to rebuild each prompt or resume work.
Checked
A model call is stateless. The session is what makes a conversation or task continuous: it stores everything that happened, so the next call can be built from it and a crashed run can pick up where it stopped.
All three major labs now use the word, and they mean much the same thing. Google calls the session the ground truth of an agent run, OpenAI's Agents SDK uses it as the memory object passed to each run, and Anthropic's Managed Agents design describes it as an append-only log of everything that happened.
How the labs implement it
Google ADK
Every user message, agent reply, tool call, tool result, control signal and error is stored as a structured event. A session also carries key-value state. The working context for each call is built from these events.
OpenAI Agents SDK
Before each run the runner loads the session's history into the input, and after the run it saves the new items. Backends include SQLite, Redis, SQLAlchemy, MongoDB and OpenAI's Conversations API, plus wrappers for encryption and compaction.
Anthropic Managed Agents
The session is a durable event log outside both the context window and the sandbox. The harness reads slices of it, writes events during the loop, and a crashed harness can be woken with the session ID and resume from the last event.
Why the log lives outside the window
Anthropic's April 2026 Managed Agents post points out that compaction and trimming are irreversible decisions about what to keep, made without knowing which tokens later turns will need. Keeping the full record in the session means anything removed from the prompt can still be recovered.
The split also separates concerns. The session guarantees durable, queryable storage; the harness decides how to present it, including ordering for prompt cache hits.
Common confusions
Session and working context
The session stores everything; the working context is the slice shown to the model on one call.
Session and long-term memory
A session covers one conversation or run. Long-term memory carries selected facts across many sessions.
Session and login session
An agent session ID selects which history to load. OpenAI's documentation states plainly that it does not authenticate a user, so authorisation stays the application's job.
Where it fails
Replaying a whole session into every prompt stops working as runs get long. Google's May 2026 ADK post lists the costs: old tool outputs pollute the prompt, resending long history is expensive, and after a long pause the model can hallucinate steps that never happened. The fix is to keep the session as storage, track progress in explicit state, and build a smaller working context from both.
How Motiontic's engineers apply it
Motiontic's engineers store sessions in the client's own database with retention rules agreed up front, tie every session to an authenticated user or service identity, and keep the session as the record that audits and evals replay.
Sessions in three agent stacks
| Google ADK | OpenAI Agents SDK | Anthropic Managed Agents | |
|---|---|---|---|
| Unit stored | Events plus key-value state | Conversation items | Events in an append-only log |
| How prompts use it | Processors build the working context | History loaded before each run, optionally capped | Harness reads slices and arranges context |
| Storage | In-memory, database or managed service | SQLite, Redis, SQLAlchemy, MongoDB, Conversations API and more | Hosted by the platform |
| Resume | Rehydrate from the session service | Pass the same session to the next run | Wake the harness with the session ID |
Common questions
What is a session in an AI agent?
A session is the stored history of one conversation or agent run, including messages, tool calls and results, kept outside the model and used to build each prompt and to resume after interruptions.
Is a session the same as agent memory?
A session is short-term memory for one conversation or run. Long-term memory stores selected facts across sessions and is recalled when relevant.
Does a session ID identify the user?
No. It selects which history to load. OpenAI's Agents SDK documentation notes that a session ID does not authenticate a user, so the application must enforce access.
Related
Working context
The per-call view of the agent's state, compiled fresh for each model call.
Agent state
The facts about where a task stands, kept as data instead of buried in chat history.
Long-term memory (AI agents)
What an agent keeps after the conversation ends, and the rules for writing and recalling it.
Agent memory
Session state for the task at hand, plus stored knowledge the agent recalls later.
AI agent development
Agents that do real work for users, with the evals, traces and guardrails to keep them in production.
Sources
- Google, Architecting efficient context-aware multi-agent framework for production (2025-12-04)
- OpenAI Agents SDK docs, Sessions
- Anthropic, Scaling Managed Agents: decoupling the brain from the hands (2026-04-08)
- Google Developers Blog, Build long-running AI agents that pause, resume and never lose context with ADK (2026-05-12)
Running agents that have to hold up?
Describe the agent, the systems it touches and what it must never get wrong. The first call is with a lab engineer, who will say plainly whether it is ready for production, and whether Motiontic is the right team.