Designing an Agent Client Protocol: Runs, Threads, and Storage
As LLM apps move from one-shot Q&A to lasting collaboration, the protocol layer often becomes the bottleneck before the model does. This article explains how a vendor-neutral agent client protocol can organize runs, threads, and storage, plus streaming, introspection, and practical concurrency and lifecycle rules for editors and backend services.
As large language model applications shift from one-shot Q&A to sustained collaboration, the protocol layer is often a tighter bottleneck than the model. Editors, terminal tools, and backend services ask different things of an agent: the former need low latency, interruption, and visible context; the latter need orchestration, auditability, and long-term memory. Abstracting those needs into stable interfaces usually lands on three concepts: a run (one agent execution), a thread (a state container for multi-turn sessions), and storage (memory that outlives a session). The following sections start from those requirements and describe how a neutral, implementable agent client protocol can be organized.
Core problems the protocol must solve
In production, an agent is rarely “call an API once and stop.” A single user action can trigger tool calls, multi-step reasoning, and streaming output, and it can be interrupted, rolled back, or continued in the background. Without a shared protocol, each client invents its own request bodies, state machines, and error codes. The result is that the same agent implementation cannot be reused, sessions cannot be shared between an editor and a backend, and concurrency, timeouts, and memory cannot be governed consistently.
Protocol design should therefore center on three questions: how to execute one agent (a run); how to group many executions into a recoverable session (a thread); and how to isolate cross-session knowledge and user preferences (storage). Message and streaming primitives cut across all three so that UX and observability stay aligned.
Runs: stateless, waitable one-shot interactions
Stateless runs fit short tasks: explaining a snippet, completing a single file, or a one-off tool call. Clients should not have to create a durable session or poll. Protocols typically offer two semantics:
- Wait: create a temporary run and block until a terminal state; the response carries the final result. Fits scripts, batch jobs, and tests.
- Stream: create a temporary run and push increments (text deltas, tool-call events, state changes). Fits live display in an editor.
Implementation notes: a run must have a clear lifecycle (queued, running, interrupted, failed, completed). Temporary runs should reclaim thread or state after they finish so idle sessions do not accumulate. Timeouts, cancellation, and idempotency keys belong in the protocol so duplicate submits do not duplicate side effects. Stateless does not mean no context: a request can still carry short context; the server simply does not promise persistence across requests.
Threads: state containers for multi-turn work
Multi-turn work needs durable state: conversation history, intermediate tool results, user-confirmation nodes, and replayable checkpoints. A thread is an append-only log for that state. The protocol should at least cover:
- Create and list: create threads by user, workspace, or business key; list by idle, interrupted, error, or completed.
- Read and write state: fetch current state and apply patch-style updates. Updates should produce a new revision rather than overwrite in place, for audit and rollback.
- History: browse versions by run or patch. Prefer storing diffs to control cost.
- Concurrency: only one active run per thread at a time. Conflict policy should be configurable—reject, enqueue, interrupt the current run, or roll back to the last checkpoint.
- Copy and delete: copy for branching experiments; delete for compliance and space.
A typical flow is: create thread → get thread → create a run on that thread → wait or subscribe. An editor can also show “awaiting user confirmation” at interrupt points, then submit the next run. That does not conflict with background “atomic” agent execution: background work should still hang on a thread so the foreground can attach, watch progress, or cancel.
Storage: long-term memory decoupled from threads
Threads fit session-level state, not memory across days or projects. Storage should be a separate interface: CRUD entries by namespace, with metadata and expiry. The agent retrieves relevant memory before a run and writes conclusions after. Permission boundaries matter: memory must be isolated by user or tenant; sensitive content should be markable as not for long-term storage. The protocol only needs operation semantics, not a specific database. Object storage, key-value stores, or vector search can implement it; the external model remains a unified entry.
Messages, streaming, and introspection
The message model should distinguish user input, assistant output, tool request/result, and system events. Streaming primitives work best as events: text deltas, tool start/end, token usage, errors. Editors can then render incrementally and still let the user interrupt.
Introspection is equally important. Before calling, a client needs to know accepted input modes, output shape, streaming support, background-run support, tool list, and permission scope. A machine-readable capability description (not only docs) reduces integration errors and lets editors generate forms and confirmation UIs dynamically.
Two (plus memory) implementation paths
- Session path: create thread → query state → create run → wait or subscribe. Fits ongoing pair programming and multi-file refactoring in an editor.
- Ephemeral path: create-and-wait or create-and-stream, then drop the thread. Fits one-shot Q&A and automation scripts.
- Memory path: insert storage reads and writes into the paths above so the agent has continuity across sessions without stuffing full history into the context window.
Editors emphasize streaming, interruption, and visible state; terminals and backends emphasize orchestration, retries, and audit. The same run/thread/storage model should serve both, rather than a private editor-only contract.
Engineering practice
- Make run side effects compensatable: failed tool calls should be marked in the state machine, not silently dropped.
- Use revision numbers as optimistic locks so concurrent writes do not overwrite each other.
- Align logs and traces with run IDs and thread IDs for debugging.
- Define an attach point for background runs: work continues after disconnect; on reconnect, events catch up.
- Do not bind the protocol to one model vendor or orchestration framework; describe lifecycle and the data plane only.
Summary
The value of an agent client protocol is not extra REST paths. It is splitting one-shot execution, multi-turn state, and long-term memory, then joining editor UX and backend reliability with shared streaming and introspection. Landing run, thread, and storage, plus concurrency policy and event streams, supports the path from brief interaction to durable collaboration without locking to a particular vendor. Teams can define a minimal interface first, implement it on object storage, queues, containers, and logging, and evolve agents from demo scripts into operable production services.
