AI Agent Architecture Design Space: Why Coding Agents Are Mostly Deterministic Scaffolding
This article breaks down the architecture design space of AI coding agents, showing that model inference and output parsing make up only a small fraction of the codebase while the deterministic operational harness dominates. It covers four key dimensions—action space and tool protocols, permission models and security sandboxes, context engineering, and the execution loop with state persistence—plus observability, evaluation, and guidance for running such systems in the cloud. Readers will learn the core trade-offs and design principles behind building reliable, self-controlled coding agents.
1. A Counterintuitive Fact About Code: Intelligence Is Only a Small Part
When people discuss how to build a powerful coding agent, the most common instinct in the industry is “polish the prompt to perfection.” But a rough analysis of the public code structure of a frontier AI coding tool leads to a rather counterintuitive conclusion: the code that actually issues large-model inference and parses model output accounts for only a tiny fraction of the overall size (on the order of single-digit percentages). The vast majority is deterministic engineering scaffolding built around the model, commonly referred to in the industry as the Operational Harness.
This ratio is no accident; it is an inevitable result of architectural choices. The output of a large model is inherently probabilistic, natural-language-shaped, and capable of violating constraints. Meanwhile, a system that truly reads and writes files, executes commands, and accesses external services on your machine must provide deterministic boundaries. As a result, the architecture naturally splits into two layers:
┌─────────────────────────────────────────┐│ Probabilistic layer: inference & ││ decision (model calls, output parsing) │ ← small share├─────────────────────────────────────────┤│ Deterministic layer: execution, ││ validation, isolation, state, ││ observability │ ← large share└─────────────────────────────────────────┘
Understanding this is the entry point to the entire architecture design space: the upper limit of an agent’s capability is determined by the model, but the safe lower bound of that capability and its engineering usability are almost entirely determined by the deterministic layer.
2. The First Dimension of the Design Space: Action Space and Tool Protocols
An agent’s “hands” are its tools. Tool design is not a simple list of functions, but a constraint design over the model’s action space, typically involving four categories:
- Read/write: file reading, targeted editing, directory search. The key design is the “minimal parsable unit,” so the model does not have to swallow an entire large file.
- Execution: running commands. It must support streaming output, timeout interruption, and non-interactive environment variable control.
- Retrieval: content and symbol search. Replacing brute-force traversal with structured retrieval is a core means of controlling context cost.
- External access: network and external service access. Tightened by default, opened on demand.
The tool description itself is an interface contract. The industry-recognized best practice is that stating the applicable scenarios, non-applicable scenarios, parameter boundaries, and failure modes in the description is far more effective than piling on adjectives. Example:
{"name": "apply_patch","description": "Performs precise snippet replacement on an existing file; not suitable for full-file rewrites.","parameters": {"path": "string, must be within the workspace allowlist","old": "string, must match uniquely","new": "string"}}
3. The Second Dimension of the Design Space: Permission Model and Security Sandbox
Since the model can propose executing arbitrary commands, security cannot rely on the model’s “self-discipline” but must reside in the deterministic layer. Layered defense typically includes:
- Identity and scope: run under a least-privilege account, with everything outside the workspace non-writable by default.
- Rule engine: parse and classify commands, distinguishing read-only, write, network access, and destructive operations.
- Confirmation gates: high-risk actions require explicit human confirmation, while low-risk actions are automatically allowed, forming a “trust gradient.”
- Isolated execution: run in a container or separate sandbox, combined with read-only mounts, resource quotas, and egress policies.
- Full audit: leave a trace of all actions, replayable and accountable.
A simplified decision logic can be written as:
def decide(action, policy):if action.kind in policy.always_deny:return "deny"if action.matches(policy.auto_approve):return "allow"if action.is_destructive or action.touches_network:return "confirm"return "allow" if policy.default_open else "confirm"
The key point here is: default values determine the system’s character. A default-deny system is safer but dumber; a default-open system is smoother but more dangerous. Mature implementations make the choice a configurable policy rather than hard-coding it.
4. The Third Dimension of the Design Space: Context Engineering
Context is the agent’s scarcest resource. Engineering typically governs it from four directions:
- Layered loading: provide the directory structure and summary first, then pull specific content on demand, avoiding filling the window all at once.
- Compression and summarization: apply rolling summaries to long histories, retaining decisions and constraints while discarding redundant process.
- Structured memory: write project conventions, build commands, and code standards into separate files, injected on demand rather than permanently occupying the window.
- Retrieval first: use search to locate and reading to gather evidence, forming a “search-verify-modify-validate” loop.
There is a plain standard for judging whether context governance is adequate: as task duration grows, the context consumption per task should remain steady, rather than rising linearly or even exponentially.
5. The Fourth Dimension of the Design Space: Execution Loop and State Persistence
The main body of an agent is a loop: observe-reason-act-feedback. What is truly difficult in engineering is the interruption and recovery of the loop:
- Interruptible: the user can interrupt at any time, and child processes and network requests must be cleanly cancellable.
- Recoverable: session state, the to-do list, and the set of modified files must be persisted so execution can resume after a restart.
- Rollback-able: file changes form a reversible boundary through version control or snapshot mechanisms.
- Termination conditions: set maximum rounds, maximum elapsed time, and budget caps to prevent infinite self-loops.
while not done and budget.left:ctx = build_context(state)plan = model.decide(ctx, tools)result = harness.execute(plan, policy) # validation, isolation, audit trailstate = state.merge(result)
6. Beyond the Fourth Dimension: Observability and Evaluation
The deterministic layer also takes on the “observability” responsibility: structure and persist the input summary, tool calls, elapsed time, and failure reasons of each inference, and connect them to logging services and monitoring alerts; at the same time, build an offline evaluation set that uses fixed tasks to measure whether a change is an improvement or a regression. Architecture evolution without evaluation is just guesswork.
7. Recommendations for Cloud Deployment
To build a similar system in a cloud environment, you can compose it in layers by general-purpose capabilities: a container platform hosts sandbox execution, object storage holds session snapshots and artifacts, a message queue decouples long-running tasks, logging services and monitoring alerts provide observability, and a key management service manages credentials. Baidu AI Cloud has corresponding capabilities in these general categories and can serve as the underlying foundation; the architectural ratio should still follow the principle of “thin inference, thick scaffolding.”
8. Conclusion
The real moat of a frontier coding agent lies not in the prompt, but in the seemingly dull 90%-plus of deterministic code: the design of the action space, the default values of permissions, the budget for context, and the recoverability of the loop. Treating the model as an unreliable but highly productive “proposer” and the engineering scaffolding as a reliable “executor” is the core idea of this generation of agent architecture, and the direction most worth prioritizing when building a self-controlled agent.
