Agent Runtime vs. Client: A Layered Architecture for AI Agents
This article explains why the agent runtime and the agent client are often confused, and why separating them matters for building reliable AI agents. It covers the limits of the common single-loop implementation, a four-layer architecture that decouples interface, orchestration, runtime, and execution, the key runtime abstractions such as serializable session state, tool routing, permissions and sandboxes, context governance, and structured event streams, plus a practical three-step path from a working demo to an operable system.
1. Two Concepts That Get Confused: Runtime and Client
In discussions about agentic coding tools, the most common misunderstanding is treating the “runtime” and the “client” as the same thing. Most people picture an agent tool as a downloadable application: log in, open a chat box, start writing code, and see a surprisingly small bill afterward. So when a release offers only an underlying runtime, many are immediately confused: what is this, and why is there no ready-to-use interface?
A clearer division of labor helps. If you think of the large language model as a horse, the user-facing agent client is the carriage: seats, windows, and handles that make the ride comfortable, the view clear, and getting on and off easy. The saddle, reins, and connecting straps on the horse are the runtime. The carriage shapes the experience; the saddle determines whether the horse can be driven reliably, controllably, and repeatably.
Under a stricter definition, the runtime is the agent’s underlying execution layer, playing a role similar to a hardware abstraction layer in an operating system: it exposes a unified, stable capability interface upward and hides the differences between specific models and execution environments downward. It is not responsible for looking good or feeling easy to use; it is responsible for being controllable and replaceable.
2. Why Current Implementations Look Like Single-Board Firmware
Most agent implementations today share one structure: a hard-wired loop where all logic lives inside a single while loop.
At startup, a very long system prompt is injected to set the role (for example, “You are an engineer”), declare available capabilities (reading files, writing files, executing commands, searching the web), and feed in all tool interface descriptions at once. The model reasons and emits a tool call; the local process intercepts it, runs the corresponding code, converts the result to plain text, appends it to the context, and starts the next round.
loop:context = system_prompt + tools_schema + historyaction = model.infer(context)result = dispatch(action) # local execution, result converted to texthistory = history + action + result
This structure is highly efficient for teaching and demos, but it hits clear bottlenecks when treated as long-term infrastructure:
- Hard-wired logic: prompt assembly, tool allowlists, retry policies, and context trimming are all coupled in one place, so changing one policy means touching the whole system.
- Non-migratable state: session state is bound to process memory, so a restart wipes it, making checkpoint resume and multi-user collaboration difficult.
- Blurred permission boundaries: a model-emitted call is nearly equivalent to local shell access, with no declarative constraints or approval step.
- Not observable: the process is a single text stream, making structured tracing, replay, and cost accounting hard.
- Hard to swap models: models differ widely in function-calling format, long-context behavior, and instruction following, and a hard-wired implementation cannot route by task.
3. Layering: Separating the Carriage from the Saddle
A more sustainable structure splits the system into four layers, each depending only on the stable interface of the layer below.
- Interaction layer (client): chat interface, diff views, review and merge, plugin entry points. It only handles presentation and interaction and contains no execution policy.
- Orchestration layer: task decomposition, plan generation, subtask scheduling, parallelism, and rollback. It decides what to do first and what to do when something fails.
- Runtime layer: session state, context management, tool registration and routing, permissions and sandboxing, and a structured event stream. It provides stable capabilities without being aware of the interface.
- Model and execution environment layer: model inference interfaces, code execution sandboxes, file and object storage, message queues, logging, and monitoring and alerting infrastructure.
After layering, swapping the interface does not affect policy, swapping the model does not affect interaction, and swapping the execution environment does not affect orchestration. This is exactly the value of calling out the runtime separately.
4. Key Runtime Abstractions
To make the runtime truly composable, at least the following must be abstracted into explicit contracts.
Session and state. State should be a serializable data structure rather than an in-process variable, so it can be persisted, migrated, and replayed.
{"session_id": "s-001","messages": [{"role": "user", "content": "..."}],"checkpoints": [{"step": 12, "state_ref": "obj://ckpt/12"}],"budget": {"tokens": 120000, "cost_limit": 2.0}}
Tool registration and routing. Tools register with capability descriptions containing name, purpose, input/output schema, permission level, and timeout; the runtime validates arguments, applies rate limits, retries, and normalizes results, instead of scattering validation across prompts.
Permissions and sandboxing. Classify by least privilege: read-only, write to workspace, run restricted commands, access the network. High-risk actions go through explicit approval, execution happens in an isolated environment, and outputs land in the workspace or object storage rather than acting directly on the host.
Context governance. This includes layered memory (in-session, task-level, long-term), retrieval augmentation, summarization and compression, and trimming policies. Context is a finite resource, and governance policies should be pluggable and measurable.
Structured event stream. Model each step as an event (plan, call, result, error, cost), persisted as an append-only log for tracing, replay, and auditing.
event{ts, session, step, type, payload, tokens, cost}
5. The Path from “It Works” to “It Can Be Operated”
The sign of a mature underlying runtime is not more features but a clear ecological niche. Look at the historical rhythm of operating systems and graphical interfaces: after a usable kernel, terminal interfaces, window systems, and desktop environments were filled in layer by layer before an explosion of applications. The evolution of agents will likely compress this timeline, but the order will not change: first a stable kernel, then the interaction shell, and only then the application ecosystem. Many interface-layer attempts already exist in the market, while a stable public runtime interface is still taking shape, so it is too early to declare the endgame.
For teams, a practical rhythm is three steps:
- Step one, decouple. Extract prompts, the tool table, and executors from the main loop into configuration and plugins, so you can change policy without changing code.
- Step two, make it observable. Add structured events, trace identifiers, and cost aggregation for every step, connect logging and monitoring and alerting, and form a replayable chain.
- Step three, make it governable. Introduce permission tiers, sandbox isolation, budget caps, and approval flows, turning “it runs” into “it is safe to run in production.”
6. Common Pitfalls and Engineering Advice
- Pitfall one: treating a long prompt as architecture. A prompt is part of the policy, not the runtime; when policy changes frequently, the architecture must absorb it.
- Pitfall two: pursuing a one-shot interface. The interface layer changes fastest, and investing too early gets the gains eaten by rework.
- Pitfall three: ignoring cost observability. Without cost aggregation by step, tool, and model, you cannot locate the source when a bill spikes.
- Pitfall four: deferring permissions. Adding approval and isolation only after an incident costs far more than designing them in from the start.
Engineering-wise, prioritize four things: stable tool contracts, serializable session state, structured events and tracing, and tiered permissions with sandboxing. On the cloud, you can reuse general-purpose capabilities: object storage for checkpoints and artifacts, message queues to decouple long tasks, container platforms for isolated execution, and logging with monitoring and alerting for observability, so attention stays on orchestration and policy itself.
7. Conclusion
The discussion around the underlying runtime is essentially a return to architectural layering: no matter how luxurious the carriage, you still need a saddle and reins to transmit power. Separating the runtime from the client, replacing the hard-wired loop with explicit contracts, and replacing “it runs” with observability and governance are the key steps for agents to move from demos to long-term operation.
