---
title: "Agent SDK adapters"
description: "Which agent SDKs Dex supports, in which languages, which session features each adapter has, how each one runs a turn as Steps, its limits, what a turn costs, and the complete example files."
canonical_url: "https://docs.superdurable.io/reference/agents/agent-sdk-adapters/"
source: "docs/reference/agents/frameworks.mdx"
locale: "en"
framework: "claude-agent-sdk"
language: "python"
---

> Index of every page for AI agents: https://docs.superdurable.io/llms.txt

# Agent SDK adapters

This file shows the Claude Agent SDK version. Other frameworks: [Eino](https://docs.superdurable.io/reference/agents/agent-sdk-adapters.eino.md) · [Google ADK](https://docs.superdurable.io/reference/agents/agent-sdk-adapters.google-adk.md) · [LangGraph](https://docs.superdurable.io/reference/agents/agent-sdk-adapters.langchain-langgraph.md) · [Mastra](https://docs.superdurable.io/reference/agents/agent-sdk-adapters.mastra.md) · [OpenAI Agents SDK](https://docs.superdurable.io/reference/agents/agent-sdk-adapters.openai-agents-sdk.md) · [Pi](https://docs.superdurable.io/reference/agents/agent-sdk-adapters.pi.md) · [Pydantic AI](https://docs.superdurable.io/reference/agents/agent-sdk-adapters.pydantic-ai.md) · [Vercel AI SDK](https://docs.superdurable.io/reference/agents/agent-sdk-adapters.vercel-ai-sdk.md)

Code on this page is in Python. Other languages: [Go](https://docs.superdurable.io/reference/agents/agent-sdk-adapters.go.md) · [TypeScript](https://docs.superdurable.io/reference/agents/agent-sdk-adapters.typescript.md)

Dex runs agents built with nine agent SDKs, plus the Dex Agent Framework. Every one of them runs on the same session Flow through its own adapter. This page lists the session features of each adapter, how it runs a turn as Steps, its limits, and what a turn costs. [Use Dex with Agent SDKs](https://docs.superdurable.io/build-ai-agents/use-dex-with-agent-sdks.md) explains the session Flow that they share. The rules for sessions on the [Dex Agent Framework](https://docs.superdurable.io/build-ai-agents/dex-agent-framework.md), such as plans, durable waits, and MCP servers, are in the [Dex Agent Framework reference](https://docs.superdurable.io/reference/agents/dex-agent-framework.md).

Sections that moved to other pages:

- <a id="built-in-agent-loop"></a>[Dex Agent Framework reference](https://docs.superdurable.io/reference/agents/dex-agent-framework.md)

<a id="features-by-harness"></a>

## Features by harness

Every harness gets a durable session, tool policies, approvals, Connectors as tools, queued messages, and live events on the AgentEvents Stream. Every one that runs in Python or TypeScript also gets **Steer**, `cancel_turn`, and `delete_queued_message`. Eino runs on the Go core, which has none of them.

| Framework           | Languages          | Each tool call in its own Step                                                                       | Context compaction by Dex                    | Questions and plans |
| ------------------- | ------------------ | ---------------------------------------------------------------------------------------------------- | -------------------------------------------- | ------------------- |
| Claude Agent SDK    | Python, TypeScript | Writes, reads that need approval, and Connector calls. Other reads run inside the model call's Step. | No. Claude Code compacts its own transcript. | No                  |
| Eino                | Go                 | Yes. The tools of an agent tool's sub-agent run inside that tool's Step.                             | No. The Go core has no compaction.           | No                  |
| Google ADK          | Python             | Yes                                                                                                  | Yes                                          | No                  |
| LangGraph           | Python             | Yes. Provider-run tools run at the provider.                                                         | Yes                                          | No                  |
| Mastra              | TypeScript         | Yes, except tools that Mastra runs itself                                                            | Yes                                          | No                  |
| OpenAI Agents SDK   | Python, TypeScript | Function tools. Hosted tools run at the provider.                                                    | Yes                                          | No                  |
| Pi                  | TypeScript         | Yes                                                                                                  | Yes                                          | Yes                 |
| Pydantic AI         | Python             | Yes. Provider-run tools run at the provider.                                                         | Yes                                          | No                  |
| Vercel AI SDK       | TypeScript         | Yes. Provider-executed tools run at the provider.                                                    | Yes                                          | No                  |
| Dex Agent Framework | Python, TypeScript | Yes                                                                                                  | Yes                                          | Yes                 |

A tool call in its own Step runs again after a crash only by the rules of [What runs again](https://docs.superdurable.io/reference/agents/failures.md#what-runs-again): Dex can retry a read or an idempotent write with the same key, and gives any other write one attempt per call. A [new call](https://docs.superdurable.io/reference/agents/failures.md#tool-runs-twice) from the model can still repeat an effect. A tool that runs inside the model call's Step, or at the provider, runs again when that Step retries.

<a id="term-map"></a>

## Your agent SDK's terms in Dex

| In your agent SDK                      | In Dex                                                                                                                  | What changes for you                                                                                                                                                                                                                                                                                                      |
| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Thread, conversation, session          | A **session**: one Flow run                                                                                             | It survives crashes and deploys.                                                                                                                                                                                                                                                                                          |
| Run the agent                          | The `send_user_message` RPC from a Client (`sendUserMessage` in TypeScript)                                             | Dex saves the message first. Messages sent during a turn queue.                                                                                                                                                                                                                                                           |
| Turn                                   | A **turn**: the Steps from one user message to the reply                                                                | In Python and TypeScript, [Steer and Stop](https://docs.superdurable.io/reference/agents/agent-sdk-adapters.md#steer-and-cancel-turn) end the active turn early. That section says what happens to running tools and remote tasks.                                                                                        |
| LLM call                               | A `RunModel` Step, with one or more model calls                                                                         | Dex saves the Step's result.                                                                                                                                                                                                                                                                                              |
| Tool call, function call               | By default, its own Step: `CallTool` for a read or an idempotent write, `CallSingleAttemptTool` for any other write     | The [tool policy](https://docs.superdurable.io/build-ai-agents/use-dex-with-agent-sdks.md#give-each-tool-a-policy) picks the Step. [Features by harness](https://docs.superdurable.io/reference/agents/agent-sdk-adapters.md#features-by-harness) lists the tools an agent SDK runs inside `RunModel` or at the provider. |
| Parallel tool calls                    | Tool Steps that run in parallel, then a `ResumeTurn` Step. Connector writes of one response run in order.               | `ResumeTurn` waits for every result and gives them to the model.                                                                                                                                                                                                                                                          |
| Human in the loop, tool confirmation   | An `AwaitToolApproval` Step, answered with the `resolve_interrupt` RPC (`resolveInterrupt` in TypeScript) or in Dex Web | The wait can last days and holds no Worker.                                                                                                                                                                                                                                                                               |
| Checkpointer, durable execution plugin | Saved Step results. The adapter keeps the agent SDK's own state between Steps.                                          | The agent code needs no determinism rules.                                                                                                                                                                                                                                                                                |
| Chat history, short-term memory        | The session's Attributes                                                                                                | A session keeps one conversation. A new session starts empty.                                                                                                                                                                                                                                                             |
| Streaming callbacks                    | The AgentEvents Stream                                                                                                  | It is best effort. `get_agent_snapshot` (`getAgentSnapshot` in TypeScript) reads the saved conversation.                                                                                                                                                                                                                  |
| MCP servers, tool integrations         | Tool sources. Official Connectors come in through `ConnectorToolSource`.                                                | Each Connector call gets its credentials and an idempotency key.                                                                                                                                                                                                                                                          |

The session ID is the Flow ID. Between turns the session waits for the next
user message and holds no Worker task slot. A stopped session stays readable
for the [retention](https://docs.superdurable.io/reference/server/configuration.md#retention) period.

<a id="steer-and-cancel-turn"></a>

## Steer and Stop

These rules apply to every Python and TypeScript harness, including the Dex Agent Framework. The Go core has no **Steer** or `cancel_turn`.

- **Steer** (`steer_user_message`, `steerUserMessage` in TypeScript) applies a message at the turn's next safe Step boundary. It never interrupts a model call or a tool call that has started. Tool calls that have not started, and approvals, questions, and durable waits that are still waiting, record **REJECTED** with the cancellation reason **STEERED**. The turn then ends, and a new turn starts with every steered message, in order. Steer takes new text or the `message_id` of a queued message. While no turn runs, steered text queues like `send_user_message`, and a queued message stays queued. If another Step takes that queued message first, the RPC raises `ChannelMessageNotFoundError` and changes nothing; reload the snapshot. While a remote tool task runs, Steer waits for it.
- **Stop** (`cancel_turn`, `cancelTurn` in TypeScript) ends the turn with no new turn. It cancels a running model call or compaction Step at once and drops its uncommitted answer. Whether the provider request itself stops depends on the provider client's cancellation support. It cancels the Steps that wait for an approval, an answer, a `durable_wait` Timer, or a remote task's next poll. A tool call Step that has started runs to the end, and the turn ends after it. Calls that have not started record **REJECTED** with the cancellation reason **TURN_CANCELLED**. A started remote task is abandoned, and its call records `outcome_unknown`; a runner that implements `ToolTaskCanceller` is asked to cancel the task. A model call that already saved its final answer completes the turn. `cancel_turn` takes an optional turn ID; pass the same one when you retry. A second call for the same turn changes nothing. While no turn is active, `cancel_turn` returns false and changes nothing.
- A turn that a Worker without steering started or advanced cannot be steered or stopped.

<a id="how-each-framework-runs-a-turn"></a>

## How your framework runs a turn

Most adapters stop the framework before a tool runs, so each tool call runs in its own Step, and most run in parallel (Connector writes of one response run in order): `CallTool` for a read or an idempotent write, `CallSingleAttemptTool` for any other write. A call that needs approval waits in `AwaitToolApproval` first. The next `RunModel` gives the framework the recorded results, so it does not run those calls again. A turn that looks up an order runs `RunModel`, `CallTool`, `ResumeTurn`, and `RunModel`. The Claude Agent SDK is the exception: it runs reads that need no approval inside `RunModel`. With Pi, Dex runs the loop itself, so every Pi tool call runs in its own Step.

The tabs show how each framework is stopped and resumed, and where a framework differs.

The Claude Agent SDK runs Claude Code as an agent. Its agent loop runs in the Claude Code CLI, a subprocess of the Worker. The Dex adapter runs that loop inside a durable session. It is available for Python and TypeScript.

**When to use it**

Use it when you want the Claude Code agent loop, its context management, and its tools. Use it when your agent already uses the Claude Agent SDK.

Use the [Dex Agent Framework](https://docs.superdurable.io/build-ai-agents/dex-agent-framework.md) when you want one model call per Step, parallel tool Steps, or context compaction by Dex.

**How a session runs**

Claude Code runs a whole turn, so the adapter splits a turn into segments. One `RunModel` Step runs the CLI for one segment. Model calls run inside the segment. So do read tools that need no approval: a deferred read would restart the CLI. A read that needs approval leaves the segment like a write. A Connector tool call is the exception: it always leaves the segment, even a read. See [Connect Connectors](https://docs.superdurable.io/build-ai-agents/connectors-as-tools.md#connect-connectors).

A write tool call ends the segment. It waits in `AwaitToolApproval` when it needs approval. Then it runs in its own Step: `CallTool` for an idempotent write, `CallSingleAttemptTool` for any other write. `ResumeTurn` then returns to `RunModel`, which resumes the same Claude session. The CLI gets the recorded result and does not run that call again.

A failed segment retries within its attempts and reruns whole. Model calls and reads inside it run again. A write that ran in its own Step does not run again when the segment retries.

A turn that looks up an order runs one `RunModel` Step. A turn that cancels an order runs `RunModel`, `AwaitToolApproval`, `CallSingleAttemptTool`, `ResumeTurn`, and `RunModel`.

<a id="limits"></a>

## Limits

Each tab lists the limits of one adapter that change how you write an agent, with what to do instead. The Dex Agent Framework has its own [limits](https://docs.superdurable.io/reference/agents/dex-agent-framework.md#limits).

- One write call per segment leaves the turn. A reply with two writes costs one more segment and model call. The writes of one reply never run as parallel Steps.
- Tools that run inside the CLI, such as **Bash** or **Edit**, are at least once. They run again when a segment reruns. Files the CLI changes are not recorded.
- A segment must finish within the `RunModel` method timeout, 15 minutes by default. Raise it with `run_model_limit` in Python or `runModelLimit` in TypeScript.
- Claude Code compacts its own transcript, and context compaction by Dex stays off. A long session ends at the state limit, not the context window: the active state of one session, 64 MiB by default ([Session limits](https://docs.superdurable.io/reference/agents/session-limits.md)).
- A recorded tool result keeps text only.
- A write call inside a subagent is denied. The model is asked to call it from the main conversation.
- The Claude Code CLI inherits the Worker's environment, including any other Anthropic or Claude Code sign-in setting. Set the options' `env` so that `ANTHROPIC_API_KEY` is its only credential, as the examples' `build_claude_cli_environment` does.

[Limits for long sessions](https://docs.superdurable.io/reference/agents/session-limits.md) has the server limits.

<a id="latency-and-cost"></a>

## Latency and cost

Every session Step is SYNC: Dex saves its start before a Worker gets it, and its result before the session moves on. Take a turn whose model asks for three ordinary tools without approval, in one response, and then answers, with one model call in each `RunModel`. The turn runs two `RunModel` Steps, three tool Steps in parallel, and one `ResumeTurn`, so it waits on four Steps in a row. [Performance](https://docs.superdurable.io/evaluate-dex/performance.md#latency-below-the-peak) measured a p50 of about 105 ms for a SYNC Step on a 2-vCPU server at half of its peak load. At that p50, the four Steps add about 0.4 seconds to the turn, on top of the model and tool time.

To retry an expensive model call fewer times, lower its attempts; [Step timeouts](https://docs.superdurable.io/reference/agents/workers.md#timeouts) lists the option and the defaults.

<a id="complete-files"></a>

## The complete files

The quick start program is three files per language. Apart from the example's order desk and settings, they use only Dex, Dex Agents, and your agent SDK:

| File                                                              | Python                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | TypeScript                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Go                                                                                                                 |
| ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| Your agent module, plain and durable, with every import           | [claude_agent_sdk](https://github.com/superdurable/dex/blob/main/examples/python/agent-harnesses/agent_harness_examples/quick_start/claude_agent_sdk_quick_start.py) · [google_adk](https://github.com/superdurable/dex/blob/main/examples/python/agent-harnesses/agent_harness_examples/quick_start/google_adk_quick_start.py) · [langchain](https://github.com/superdurable/dex/blob/main/examples/python/agent-harnesses/agent_harness_examples/quick_start/langchain_quick_start.py) · [openai_agents](https://github.com/superdurable/dex/blob/main/examples/python/agent-harnesses/agent_harness_examples/quick_start/openai_agents_quick_start.py) · [pydantic_ai](https://github.com/superdurable/dex/blob/main/examples/python/agent-harnesses/agent_harness_examples/quick_start/pydantic_ai_quick_start.py) | [claude-agent-sdk](https://github.com/superdurable/dex/blob/main/examples/typescript/src/products/agent-harnesses/quick-start/claude-agent-sdk-quick-start.ts) · [mastra](https://github.com/superdurable/dex/blob/main/examples/typescript/src/products/agent-harnesses/quick-start/mastra-quick-start.ts) · [openai-agents](https://github.com/superdurable/dex/blob/main/examples/typescript/src/products/agent-harnesses/quick-start/openai-agents-quick-start.ts) · [pi](https://github.com/superdurable/dex/blob/main/examples/typescript/src/products/agent-harnesses/quick-start/pi-quick-start.ts) · [vercel-ai](https://github.com/superdurable/dex/blob/main/examples/typescript/src/products/agent-harnesses/quick-start/vercel-ai-quick-start.ts) | [eino](https://github.com/superdurable/dex/blob/main/examples/go/agent-harnesses/quickstart/eino_quick_start.go)   |
| The runner: Registry, Worker, Client, and one turn with approvals | [session.py](https://github.com/superdurable/dex/blob/main/examples/python/agent-harnesses/agent_harness_examples/quick_start/session.py)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | [quick-start-session.ts](https://github.com/superdurable/dex/blob/main/examples/typescript/src/products/agent-harnesses/quick-start/quick-start-session.ts)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | [session.go](https://github.com/superdurable/dex/blob/main/examples/go/agent-harnesses/quickstart/session.go)      |
| The smallest host: one Worker, one Client, one turn               | [embed.py](https://github.com/superdurable/dex/blob/main/examples/python/agent-harnesses/agent_harness_examples/quick_start/embed.py)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | [quick-start-embed.ts](https://github.com/superdurable/dex/blob/main/examples/typescript/src/products/agent-harnesses/quick-start/quick-start-embed.ts)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | [embed.go](https://github.com/superdurable/dex/blob/main/examples/go/agent-harnesses/quickstart/embed.go)          |
| The entry point that asks for approval at the prompt              | [\_\_main\_\_.py](https://github.com/superdurable/dex/blob/main/examples/python/agent-harnesses/agent_harness_examples/quick_start/__main__.py)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | [quick-start-main.ts](https://github.com/superdurable/dex/blob/main/examples/typescript/src/products/agent-harnesses/quick-start/quick-start-main.ts)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | [main.go](https://github.com/superdurable/dex/blob/main/examples/go/agent-harnesses/cmd/agent-quick-start/main.go) |

The other packages that the install commands list are your agent SDK and the packages the example uses, such as its model client; install the ones your agent uses. Tools the agent SDK runs itself, such as MCP servers and hosted tools, need the changes in its [Limits](https://docs.superdurable.io/reference/agents/agent-sdk-adapters.md#limits) tab. The Order Support host registers the Claude agent only when `ANTHROPIC_API_KEY` is set, and serves the other harnesses without it.

<a id="web-handler"></a>

## Serve sessions from a web app

A web app splits the host across routes:

1. The Registry, Worker, and Client. The Worker connects out to Dex, so it needs no open port. Both use a [blob cache](https://docs.superdurable.io/reference/server/workers.md#blob-cache), a local cache for large values.
2. A route that starts a session. The session ID is the Flow ID.
3. A route that sends a user message, and one that reads the session snapshot with the agent's reply or streams it.
4. A route that approves or rejects a waiting tool call; see [Approve from your application](https://docs.superdurable.io/reference/agents/approvals.md#approve-from-your-application).

The handler that sends a message queues it on the session and returns. It replaces the agent SDK call that waited for the reply:

| Agent SDK         | Call it replaces   |
| ----------------- | ------------------ |
| Claude Agent SDK  | `query`            |
| Eino              | `Runner.Query`     |
| Google ADK        | `Runner.run_async` |
| LangGraph         | `agent.invoke`     |
| Mastra            | `agent.generate`   |
| OpenAI Agents SDK | `Runner.run`       |
| Pi                | `agent.prompt`     |
| Pydantic AI       | `agent.run`        |
| Vercel AI SDK     | `generateText`     |

The reply arrives on the session's [AgentEvents Stream](https://docs.superdurable.io/reference/agents/event-stream.md#read-the-stream), which a chat UI reads as server-sent events. Polling the snapshot suits scripts and tests. The [Order Support Agent](https://docs.superdurable.io/examples/order-support-agent.md) example has these routes over HTTP, for every agent SDK.

**Python**

The whole module, `quick_start/web.py`, is a complete app: it hosts the Worker and the Client and serves every route a chat UI needs.

```python
"""A complete web app for a durable agent: start, message, read, stream, approve.

It hosts the Worker and the Client in the web process. Add your own
authentication before you expose these routes: anyone who knows a session ID
can read and change that session here.
"""

from __future__ import annotations

import uuid
from pathlib import Path
from typing import Any

from dex_agents import AgentSessionFlow
from dex_agents.ui_stream import (
    AGENT_EVENT_STREAM_HEADERS,
    agent_snapshot_to_json,
    stream_agent_event_frames,
)
from quart import Quart, Response, jsonify, make_response, request

from agent_harness_examples.quick_start.safe_send import send_user_message_once
from agent_harness_examples.quick_start.session import QuickStartApp

def create_web_app(
    session_flow: AgentSessionFlow, server_address: str, blob_cache_dir: Path
) -> Quart:
    """Returns a Quart app whose routes run one durable agent's sessions."""
    web = Quart(__name__)
    apps: list[QuickStartApp] = []

    def dex() -> QuickStartApp:
        return apps[0]

    # The Worker and the Client bind to the event loop that serves the app.
    @web.before_serving
    async def start_worker() -> None:
        apps.append(QuickStartApp(session_flow, server_address, blob_cache_dir))
        await dex().start_worker()

    @web.after_serving
    async def stop_worker() -> None:
        await apps.pop().close()

    @web.post("/sessions")
    async def start_session() -> Response:
        session_id = f"web-{uuid.uuid4().hex}"
        await dex().sessions.start_session(session_id)
        return jsonify(session_id=session_id)

    @web.post("/sessions/<session_id>/messages")
    async def send_message(session_id: str) -> Response:
        body: dict[str, Any] = await request.get_json()
        await send_user_message_once(dex().sessions, session_id, str(body["text"]))
        return jsonify(accepted=True)

    @web.get("/sessions/<session_id>")
    async def read_session(session_id: str) -> Response:
        return jsonify(agent_snapshot_to_json(await dex().sessions.get_agent_snapshot(session_id)))

    @web.get("/sessions/<session_id>/events")
    async def stream_events(session_id: str) -> Response:
        resume_token = request.headers.get("Last-Event-ID", "")
        frames = await stream_agent_event_frames(
            dex().client, session_flow, session_id, resume_token=resume_token
        )
        response = await make_response(frames, dict(AGENT_EVENT_STREAM_HEADERS))
        assert isinstance(response, Response)
        response.timeout = None
        return response

    @web.post("/sessions/<session_id>/interrupts/<interrupt_id>")
    async def resolve(session_id: str, interrupt_id: str) -> Response:
        body: dict[str, Any] = await request.get_json()
        accepted = await dex().sessions.resolve_interrupt(
            session_id, interrupt_id, approved=body.get("approved") is True
        )
        return jsonify(accepted=accepted)

    return web
```

`send_user_message_once` retries a send with best-effort duplicate detection; [Retry a message send](https://docs.superdurable.io/reference/agents/upgrades.md#send-a-message-once) has the module and its limits.

Example: [examples/python/agent-harnesses/agent_harness_examples/quick_start/web.py](https://github.com/superdurable/dex/tree/main/examples/python/agent-harnesses/agent_harness_examples/quick_start/web.py)
