---
title: "It durably runs agent swarms on any model, without your laptop · Tempo AI Platform docs"
description: "How an agent's turn runs in its own Durable Object, fans out to subagents on any model, and survives disconnects, crashes and deploys."
url: "https://gateway.tempo-dev.workers.dev/docs/guides/swarms"
---

> Every page of the Tempo AI Platform is Markdown at its URL with .md, or with Accept: text/markdown. The index of every page is https://gateway.tempo-dev.workers.dev/llms.txt, the API https://gateway.tempo-dev.workers.dev/openapi.json and the MCP server https://gateway.tempo-dev.workers.dev/mcp.

# It durably runs agent swarms on any model, without your laptop

A cloud agent is a nanocode session in its own Cloudflare Durable Object. Its turns run there instead of on your machine, so they keep going when you disconnect and come back after a crash. Its subagents run in the same object, each on its own harness and model, and every model call goes through the platform's own model routes, paid from your key.

[Get your Tempo Key](https://gateway.tempo-dev.workers.dev/key.md) · [Agents reference](https://gateway.tempo-dev.workers.dev/docs/agents.md)

## Architecture

```text
you, your app or a nanocode client
  |  POST /v1/agents/:id/turns
  |  Authorization: Bearer sk-tempo-...
  v
Worker: checks the key and the agent's row in D1, then forwards
  |
  v
+- AgentSession: a Durable Object for this agent ------------------+
|                                                                  |
| nanocode runtime (WebAssembly)                                   |
|   lead   codex   deepseek-v4.1-flash                             |
|   +- 1   claude  claude-sonnet-5.5     subagents: same session,  |
|   +- 2   codex   gpt-6.1-sol           each its own harness,     |
|   +- 3   claude  glm-5.3               model and thinking        |
|                                                                  |
| Code Mode cells (QuickJS)       bash workspace at /workspace     |
| SQLite: turns, events, checkpoints, cell and subagent journals   |
|                                                                  |
+-------+----------------------+--------------------------+--------+
        | model calls          | tools                    | hands
        v                      v                          v
  /v1/responses           /mcp, in process          HandHub, Machine
  /v1/messages            kv, git, compute,         your laptop, a tab,
  paid from the key       email, phone ...          a sandbox
```

A turn's path: the Worker checks the key and forwards the turn to the agent's Durable Object, where the lead and its subagents run and call models, tools and hands.

| Part                | What it does                                                                                                                                                                                                                                          |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Worker              | The router every request reaches first. It finds the Tempo Key by the SHA-256 of its token, and the agent's row in D1 under the key's chain, wallet, app and key, and only then forwards the request to the agent.                                    |
| AgentSession        | A Durable Object per agent: a single-threaded actor with its own SQLite storage, which Cloudflare starts near the request that first reaches it. It runs nanocode's Cloudflare app.                                                                   |
| nanocode runtime    | The Codex and Claude agent loops, rebuilt by nanocode and compiled to WebAssembly, with Code Mode cells in QuickJS and a bash workspace under /workspace whose files live in the object's SQLite.                                                     |
| Egress              | Where the harness's model calls go. Codex asks for api.openai.com/v1/responses and Claude for api.anthropic.com/v1/messages, and the egress sends both to the Worker's own /v1/responses and /v1/messages, in process, with the agent's key attached. |
| gateway MCP server  | The platform's tools, reached in process as the session's gateway server, so a cell calls them as tools.mcp__gateway\_\_\*.                                                                                                                           |
| HandHub and Machine | Durable Objects that carry hands: one per account for the machines you attach, and one per sandbox the gateway drives itself.                                                                                                                         |

## How a turn runs

1. You post a prompt to `POST /v1/agents/:id/turns`. The Worker resolves the id or persona with the key in one D1 read and forwards the turn to the agent's session with its harness and model. The session records the turn in its storage before it answers, so from then on the turn belongs to the object: it answers `202` with the turn's id, or streams its events with `Accept: text/event-stream`.
2. The harness calls its model. The egress turns the call into a request to the Worker's model route, which pays it from the key's session channel and streams it from the provider that serves the model: Workers AI, Vercel AI Gateway, OpenRouter or Boundless. The model's text and tool input reach you as live frames while it writes them.
3. The model works through tools. In Code Mode it writes a cell, a JavaScript program that runs in QuickJS inside the same object and calls the agent's tools: the shell and files, web search, the platform's tools over MCP and a `fetch` that pays any MPP service. A tool call that names a hand runs on that machine. [Code Mode](https://gateway.tempo-dev.workers.dev/docs/guides/code-mode.md)
4. The lead fans out. `spawn_agent` starts a subagent in the same session with its own harness, model and thinking; the lead messages it with `send_agent_message`, waits on it with `wait_agent` and builds its answer from theirs. The session keeps the tree, each subagent's id and parent, in its subagent journal.
5. The turn ends. Its result and every event stay in the object's storage: `GET turns/:turn` answers the result, and `GET events` pages the log from any cursor or streams it.

A prompt sent while a turn runs steers it instead of queueing: the session hands it to the model at its next step and answers `{"status":"steered"}`.

## What it survives

- **You disconnect**\
  Nothing in a turn depends on your connection. Reconnect to `events?after=` the last cursor you read, and the stream goes on from there.
- **The object restarts**\
  A Durable Object can be reset by a crash, an eviction or the platform. The session's alarm brings the turn back from its last checkpoint. Cells replay from journals written ahead, so a call that finished answers from the journal instead of running again, and an operation sent to a hand resumes from its logged request and stored reply. On 2026-10-30 a full reset of the local Worker, about 11 s down, in the middle of a cell on a laptop hand, a nested call and a timed wait left all three turns completed with their real output.
- **You deploy**\
  Running objects keep running across a deploy: in two deploys measured on 2026-10-30, a 40 s and a 90 s command on a hand and a timed cell each finished on their own, without a recovery.
- **A hand drops**\
  The account's hub keeps the agents attached for 30 s; a hand that comes back as the same process finishes what it was running, and its replies reach the agent. [Machines](https://gateway.tempo-dev.workers.dev/docs/machines.md#how)
- **The context grows**\
  Long sessions compact their history in a window that fits the model: at most 200,000 tokens for Claude sessions, and 128,000 for Workers AI models, whose prompt cache is best effort.

## Any model, any harness

- **The agent's model**\
  Any platform model that calls tools; `GET /v1/capabilities` lists them under `agents`, DeepSeek V4.1 Flash by default. [Models](https://gateway.tempo-dev.workers.dev/docs/models.md)
- **Both harnesses in one session**\
  Every session opens with Codex and Claude, so a Codex lead can spawn a Claude subagent and the other way round, each on the model it names. A subagent with `model: null` inherits its parent's model, and across harnesses it runs on the agent's own model.
- **Steering from outside**\
  `/v1/agents/:id/subagents` lists the tree as nanocode's `list_agents` does, sends a subagent a message (`urgent` steers its running turn, `deferred` queues behind it), interrupts or closes it, or asks it a side question from its last turn.

## Who owns it and who pays

- **Scope**\
  An agent belongs to its wallet and its `Gateway-App`, and pays from the key that created it. Every key of the wallet reaches it; another wallet gets a 404 for it, its turns, events and files unless it holds an `agents` grant.
- **Payment**\
  The agent routes are free. Each model call and paid tool is paid from the key as it runs, at the price of the route it calls, so a swarm costs what its calls cost: on 2026-10-30 a lead and three subagents that each started a sandbox, ran a benchmark and terminated it took 52 s and 0.024 MACH.
- **Lifetime**\
  An agent ends with its key. Revoke or stop the key and the agent stops at its next payment, and every minute the cron deletes the sessions of keys that expired, were revoked or used up their limit. Deleting an agent deletes its transcript and workspace.
- **An app can pay**\
  Set a `payer` and the platform asks your app for an MPP voucher for each call the agent makes instead of paying from the key, as Swarms does for crowdfunded agents. The agent's data stays the key's. [Payers](https://gateway.tempo-dev.workers.dev/docs/agents.md#payers)

## Try it

**1. Create an agent**

```sh
curl https://gateway.tempo-dev.workers.dev/v1/agents -H "authorization: Bearer $TEMPO_KEY" -H content-type:application/json -d '{"harness":"codex","persona":"bench"}'
```

**2. Give it a turn**

```sh
curl https://gateway.tempo-dev.workers.dev/v1/agents/bench/turns -H "authorization: Bearer $TEMPO_KEY" -H content-type:application/json -H accept:text/event-stream -d '{"prompt":"Benchmark zlib, bz2 and lzma in sandboxes"}'
```

**watch and steer the subagents**

```sh
curl https://gateway.tempo-dev.workers.dev/v1/agents/bench/subagents -H "authorization: Bearer $TEMPO_KEY"

curl https://gateway.tempo-dev.workers.dev/v1/agents/bench/subagents/1/messages -H "authorization: Bearer $TEMPO_KEY" \
  -H content-type:application/json -d '{"message":"Skip lzma","priority":"urgent"}'
```

## Go deeper

- [Quickstart](https://gateway.tempo-dev.workers.dev/docs/quickstart.md): an agent, a turn, a hand and a steer, with curl.
- [Agents](https://gateway.tempo-dev.workers.dev/docs/agents.md): every agent, subagent and session route.
- [Machines](https://gateway.tempo-dev.workers.dev/docs/machines.md): hands on your laptop, a tab or a sandbox.

[<- Quickstart](https://gateway.tempo-dev.workers.dev/docs/quickstart.md) · [It's multiplayer ->](https://gateway.tempo-dev.workers.dev/docs/guides/multiplayer.md)
