Sessions
View as MarkdownA durable agent session is one Flow run that holds one conversation. Each model call and each tool call runs in a Step. So a crash, a deploy, or a long wait repeats nothing that already finished.
RunModelTool callCallToolApprovalAwaitToolApprovalModel callRunModelEach chip is a Step that Dex records.
A durable agent session
One Flow run is one agent session. The Flow ID is the session ID. Dex Agents builds the session Flow: the dex-agents package in Python and @superdurable/dex-agents in TypeScript. A framework adapter adds one agent framework to it.
The session stores the conversation in Attributes. A session waits for the next user message without using a Worker task slot.
Model calls run in a RunModel Step. In most harnesses, each RunModel Step makes one model call, and each tool call runs in its own Step. The Steps of one turn are:
| Step | What it does |
|---|---|
RunModel | Makes one model call and records the response. |
CallTool | Runs one call of a read or an idempotent write. Dex may retry it. |
CallSingleAttemptTool | Runs one call of any other write. Dex runs it at most once. |
AwaitToolApproval | Waits for a person to approve or reject a tool call. See Approvals. |
ResumeTurn | Waits for every tool result of the model response, then moves back to RunModel. |
The tool calls of one model response run in parallel. When they all finish, ResumeTurn sends their results to the model.
Latency and cost
Every session Step is SYNC: Dex commits the Step's start before the Worker gets it, and its result before the session moves on, each to object storage. A turn in which the model asks for three tools and then answers takes six Steps: two RunModel, three tool Steps, and one ResumeTurn. Performance measured a p50 of about 105 ms for a SYNC Step on a 2-vCPU server at half of its peak load. The three tool Steps run in parallel, so the turn waits on four Steps in a row. At that p50, they add about 0.4 seconds to the turn, on top of the model and tool time.
A RunModel Step retries up to three attempts within 30 minutes. A retry sends the model call to the provider again, so you pay for its tokens again. run_model_limit in Python, or runModelLimit in TypeScript, lowers the attempts for an expensive call. Step timeouts lists the defaults.
A crash repeats only the Step that was running. Dex does not replay the loop. So the agent code needs no determinism rules, and a code change takes effect at the next Step.
Two harnesses group more work into one Step:
- Claude Agent SDK. The Claude Code CLI runs a turn segment in one
RunModelStep. The segment holds the model calls and the read tool calls, and a failed segment reruns as a whole. Writes leave the segment one at a time, each in its own Step, so they never run in parallel. - LangChain and LangGraph. One
RunModelStep runs the graph to its next tool calls. A graph can make several model calls on the way, and a retry repeats them together.
What a session remembers
A session keeps one conversation: its messages, its tool calls, and their results. A new session starts empty. Dex Agents has no memory that one session shares with the next.
Keep long-term memory, such as a user's preferences or past orders, in a store that you own. That store can be your database or a Flow that you keep for each user. Give the agent a tool that reads it, and a tool that writes it with the right policy.
A stopped session stays readable for the retention period, and then Dex deletes it. History and retention has the defaults.
Framework support
Framework Support shows how your framework runs a turn, which session features it has, and its limits.
Next
- Tool Calls
- RPCs during a deploy: what
send_user_messagedoes while no Worker runs - Agents reference