Agent systems that survive production.
A working reference drawn from production agent platforms: where requests go, who owns which record, how a run survives a closed tab, and how to tell which layer failed. Generalised from real systems, with no client internals.
§ 1 · System map
The gateway routes short requests and starts durable runs.
The gateway is the backend for the frontend. It exposes one API over product services and starts the agent harness where a request needs reasoning, tools and a user-visible result. Workers execute the harness and publish progress; the client reads the resulting conversation and workspace through authorised APIs.
control plane
- 01 client
- 02 gateway
- 03 coordinator
- 04 child turn
execution and state
- 05 worker
- 06 conversations
- 07 object storage
- 08 shared cache
| Component | Responsibility |
|---|---|
| API gateway | Authorise requests, validate contracts, call product services, start or observe workflows. |
| Worker and harness | Assemble context, choose models and tools, execute a turn, emit typed events. |
| Workflow engine | Coordinate turns, hold execution state, support retry, replay and cancellation. |
| Conversation store | Own conversation records, sharing rules and saved messages. |
| Object storage | Hold workspace artifacts and, under a private prefix, execution checkpoints. |
| Shared cache | Cache recomputable results across processes. Eviction means recompute, never loss. |
§ 2 · Identify the right record
Five identities, five different questions.
Most “the agent lost my work” incidents are identity confusion. Name each record, give it one owner, and log all of them on every line.
| Record | What it represents |
|---|---|
| Conversation ID | The user-visible thread and its access boundary. |
| Turn ID | One submitted question, stable across a retry of that same submission. |
| Workflow ID | The durable execution address for streaming, query and control. |
| Event index | A position in the turn’s replay stream. Treat it as a cursor. |
| Request ID | Correlates one HTTP request with its log events. |
§ 3 · Durable turns
One active turn per conversation, reserved atomically.
A conversation coordinator uses Update-With-Start to reserve exactly one active child turn. The same immutable request can rejoin its child; a conflicting request gets a busy result. Rewind records turn IDs so late starts are rejected. The child owns a bounded event history; workers group model deltas and tool events into signal batches, and clients query slices by cursor.
POST /v0/chat → text/event-stream
POST /v0/chat/sync → final result
GET /v0/chat/{conversation}/stream
?workflow={id}&cursor=045 → replay from cursor
event task_plan · task_update · tool_start · tool_result
text_delta · message_complete · error{code}§ 4 · Checkpoints and retries
Four records answer four questions.
| Record | Question it answers |
|---|---|
| Workflow history | What happened, and which client-visible events can I replay? |
| Graph checkpoint | Which graph boundary and completed model or tool work can an activity resume? |
| Workspace files | What evidence, graphs, workpapers and outputs exist for this analysis? |
| Conversation | Which questions, saved messages and sharing rules does the user see later? |
Execution windows separate the lifetime of one activity from the turn’s total deadline. The harness yields at a valid model boundary and validates pending tool calls before resuming. Workspace files flush before a checkpoint that depends on them is acknowledged. Anything interrupted before its durable boundary can run again, so external effects must be idempotent or reconciled.
§ 5 · Streaming and ending an answer
A connection is a view of execution, not the execution.
- Explicit answer
- The lead finishes; message_complete with reason=answer.
- Tool-round guard
- Repeated or failing tools hand over to synthesis with tools disabled.
- Final-write reserve
- Time is held back so evidence gathering gives way to writing.
- Interrupted write
- Complete lines are retained at a safe boundary, continued without resending, or delivered with an explicit incomplete marker.
§ 6 · Observability
Start with the failing layer.
| Symptom | First evidence to check |
|---|---|
| Turn stays queued | Task queue pollers, namespace, workflow state and concurrency. |
| Client stopped updating | SSE response, heartbeat and reconnect cursor, event query, latest persisted message. |
| Run stalled after a tool | Route mode, tool timeout, provider first-token and inter-chunk timing, execution window, final reserve. |
| Answer partial or missing | Terminal event and reason, persistence step, streamed prefix, checkpoint state, retry guard. |
| Slow file and graph reads | Server-Timing phases, mirror listing and download counts, cache version. |
| Inconsistent evidence | Source date and units, tool payload, workpaper, output tags, then rendering, in that order. |
§ 7 · Build a small version first
Six steps, in this order.
- 01
Define the contract
Request schema, caller context, evidence reference, terminal answer, minimal event vocabulary. One owner per durable record.
- 02
Ship one streamed turn
A stub tool, a trace, and a typed error for each expected failure, including unauthorised and valid-empty.
- 03
Add a durable boundary
Task ID, cursor, one terminal state, safe retry of completed work, idempotent save.
- 04
Add evidence and one specialist
Explicit write scopes, result schemas, budgets and stop conditions.
- 05
Split the read model
Only when profiling says so. Version a complete view, validate with ETags, check access before shared caches.
- 06
Roll out by tenant
Measure against one baseline, keep an escape hatch, document which flags affect the path.