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.

7 sectionsRevised Nov 2026Temporal · FastAPI · LangGraph

§ 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.

0102030405060708control plane01 client02 gateway03 coordinator04 child turnexecution and state05 worker06 conversations07 object storage08 shared cacheactivity ↓signal batches ↑

control plane

  • 01 client
  • 02 gateway
  • 03 coordinator
  • 04 child turn

execution and state

  • 05 worker
  • 06 conversations
  • 07 object storage
  • 08 shared cache
Fig. 1 — Control plane above, execution and state below.
ComponentResponsibility
API gatewayAuthorise requests, validate contracts, call product services, start or observe workflows.
Worker and harnessAssemble context, choose models and tools, execute a turn, emit typed events.
Workflow engineCoordinate turns, hold execution state, support retry, replay and cancellation.
Conversation storeOwn conversation records, sharing rules and saved messages.
Object storageHold workspace artifacts and, under a private prefix, execution checkpoints.
Shared cacheCache 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.

RecordWhat it represents
Conversation IDThe user-visible thread and its access boundary.
Turn IDOne submitted question, stable across a retry of that same submission.
Workflow IDThe durable execution address for streaming, query and control.
Event indexA position in the turn’s replay stream. Treat it as a cursor.
Request IDCorrelates 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.

contract.http
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.

RecordQuestion it answers
Workflow historyWhat happened, and which client-visible events can I replay?
Graph checkpointWhich graph boundary and completed model or tool work can an activity resume?
Workspace filesWhat evidence, graphs, workpapers and outputs exist for this analysis?
ConversationWhich 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.

SymptomFirst evidence to check
Turn stays queuedTask queue pollers, namespace, workflow state and concurrency.
Client stopped updatingSSE response, heartbeat and reconnect cursor, event query, latest persisted message.
Run stalled after a toolRoute mode, tool timeout, provider first-token and inter-chunk timing, execution window, final reserve.
Answer partial or missingTerminal event and reason, persistence step, streamed prefix, checkpoint state, retry guard.
Slow file and graph readsServer-Timing phases, mirror listing and download counts, cache version.
Inconsistent evidenceSource date and units, tool payload, workpaper, output tags, then rendering, in that order.

§ 7 · Build a small version first

Six steps, in this order.

  1. 01

    Define the contract

    Request schema, caller context, evidence reference, terminal answer, minimal event vocabulary. One owner per durable record.

  2. 02

    Ship one streamed turn

    A stub tool, a trace, and a typed error for each expected failure, including unauthorised and valid-empty.

  3. 03

    Add a durable boundary

    Task ID, cursor, one terminal state, safe retry of completed work, idempotent save.

  4. 04

    Add evidence and one specialist

    Explicit write scopes, result schemas, budgets and stop conditions.

  5. 05

    Split the read model

    Only when profiling says so. Version a complete view, validate with ETags, check access before shared caches.

  6. 06

    Roll out by tenant

    Measure against one baseline, keep an escape hatch, document which flags affect the path.