AI Agent System Architecture: A Deep Dive into the Design Space
An analysis of leading AI coding agent systems reveals a surprising fact: the code that actually invokes the large language model accounts for only about 1.6% of the codebase, while the remaining ~98.4% is deterministic engineering scaffolding, or operational harness. This article explores the architecture design space of AI agents through two lenses—design values and component structure. It covers five guiding principles (human-in-the-loop, default-deny security, reliable execution, capability amplification, and context adaptability), seven core components, a pseudocode walkthrough of the central agent loop, and practical lessons for developers building reliable agent systems.
1. A Counter-Intuitive Finding: Intelligence Is Only a Small Part of the Agent
When we discuss how to build a powerful AI coding agent, intuition tells us the key lies in crafting more sophisticated prompts, choosing stronger models, and refining reasoning logic to perfection. Yet an analysis of the public source code of a class of frontier agent systems reveals a truth that overturns conventional wisdom.
In these systems, the code that actually invokes the large language model and carries the responsibility of “thinking” and “proposing actions” makes up only about 1.6% of the total. The remaining ~98.4% is all hardcore deterministic engineering scaffolding—the operational harness. In other words, the model only makes decisions at key points, while the “dirty work”—execution scheduling, security sandboxes, permission checks, context management, and state persistence—is entirely handled by the underlying infrastructure.
This ratio is itself the most important architectural signal. It means the competitive moat of agent systems lies not in model parameters or prompt tricks, but in the precise, reliable, controllable engineering infrastructure built around the model. The agents of the future are not omnipotent magic but an engine running on a set of precision gears: the model is the ignition, while the gear assembly (the harness) is what actually transmits power.
Understanding this is the starting point for understanding the entire agent architecture design space. Below, we explore it along two dimensions: design values and component structure.
2. The Five Core Values Driving the Architecture
The architecture of a mature agent system is not the arbitrary pile-up of an engineer’s choices; it is derived in reverse from a set of clear value orientations. We can distill it into five principles.
1. Human-in-the-Loop
No matter how automated the agent becomes, humans always retain the final decision-making authority. The system must support auditing, rejecting, or interrupting every key action. This means users have the right to intervene in any irreversible or high-risk operation. Architecturally, this requires the agent to proactively “pause” before executing an action and hand the decision back to the human, rather than executing all the way through and leaving people to clean up the aftermath.
2. Security and Privacy: Default Deny
The underlying logic of the security system should be “default deny, explicit allow.” Faced with an unknown operation, the system’s default answer is “not allowed,” and the operation executes only when it is explicitly added to the allow list or confirmed by the user. The benefit of this design is that even if a human overlooks a review for a moment, the defense system can still provide a safety net. Security should not depend on human vigilance; it should be built into the system’s rules.
3. Reliable Execution
An agent needs to guarantee reliability at two scales: first, the correctness of a single task—whether “this operation was done right this time”; second, the coherence of long-horizon interactions—whether the system can maintain context consistency, stay on track, and avoid forgetting across multiple rounds of interaction and multi-step tasks. The latter is especially difficult, because it demands strict lifecycle management over context.
4. Capability Amplification
The ultimate goal of the architecture is to push AI productivity to its limit. This depends on a subtle trade-off: pairing a minimal decision-making harness with the most powerful execution environment. Keeping the model side “thin” and delegating complexity to the tools and execution layer actually reduces the model’s opportunities for error, while amplifying the real value of each of the model’s actions through a strong tool pool and sandbox.
5. Context Adaptability
The same system serves vastly different users: some are performing large-scale engineering refactors, while others are beginners who just want to tweak a configuration. A strong architecture dynamically adapts based on the user’s context (project type, skill level, past behavior)—neither over-interrupting experts nor making novices feel out of control. Adaptability ultimately points to trust: the more the system understands the user, the more willing the user is to grant authorization.
3. Breaking Down the Seven Core Components
From a macro perspective, this class of agent system can be decomposed into seven core components that work together to complete the full loop from “the user expressing intent” to “safe execution and result feedback.”
- User: The initiator of intent and the final arbiter, present throughout the entire flow.
- Interfaces: Whether interacting via the command line, an IDE plugin, or SDK integration, all requests ultimately converge on the same core agent loop, ensuring consistent behavior.
- Agent Loop: The heart of the entire system, responsible for driving the repeated iteration of “reason—decide—execute—feedback.”
- Permission System: A mandatory checkpoint that every tool call must pass through, implementing default deny and human confirmation.
- Tools: The set of capabilities the agent can invoke, such as file read/write, command execution, and external service calls.
- State & Persistence: Saves session history, task state, and intermediate artifacts to support long-horizon coherence.
- Execution Environment: An isolated runtime environment that lets commands and code run safely within a controlled boundary.
4. Engineering the Core Loop
Among the components above, the agent core loop is the most worthwhile part to explore in depth. Its essence is a continuous loop of “reason—decide—execute,” and the permission gateway and execution sandbox are embedded precisely at the key nodes of this loop. The following illustrative pseudocode sketches its skeleton:
async def agent_loop(user_input, session):# 1. Assemble context: integrate history, project info, and current inputcontext = build_context(user_input, session.history, session.project)while True:# 2. Model reasoning: propose the next action or give a final answerdecision = await llm.invoke(context)# 3. If it is a final answer, return it directly to the userif decision.type == "final":return decision.content# 4. If it is a tool call, pass through the permission gateway first (default deny)tool_call = decision.actionpermission = await permission_gateway.check(tool_call)if permission == "deny":context.append(rejection(tool_call))continueif permission == "ask":if not await ask_human(tool_call): # Humans can audit, reject, or interruptcontext.append(rejection(tool_call))continue# 5. Execute the tool in the isolated sandboxresult = await sandbox.execute(tool_call)# 6. Write the result back to context and proceed to the next iterationcontext.append(tool_result(result))
This skeleton distills the core idea of the entire architecture: the model makes decisions only in step 2, while the permission gateway and sandbox in steps 4 and 5 are the real source of reliability. Note the position of permission_gateway and sandbox—they are not appendages of the model but mandatory gates that all of the model’s actions must pass through. This is exactly where the “98.4% engineering scaffolding” comes into play.
5. Architectural Lessons for Developers
Pulling it all together, building a reliable agent system yields several practical guidelines:
- Keep the model “thin” and the infrastructure “thick.” Push security, execution, and context management down into deterministic code, and let the model handle only the decisions it is good at. This significantly reduces uncontrollable risk.
- Make security a closed loop of default deny. The permission gateway should exist as mandatory middleware that no tool call can bypass.
- Isolate the execution environment. Run commands and code inside a sandbox to keep the blast radius to a minimum.
- Invest in state management for long-horizon coherence. Session history, task progress, and intermediate artifacts must be persisted and traceable—this is the foundation for keeping long tasks on track.
- Converge multiple interfaces onto a single core. The interface layer can be many, but the core loop must be unique to avoid behavioral fragmentation.
- Adapt the system to the user, not the other way around. Dynamically adjusting the level of intervention based on context is the key to building trust.
The conclusion is clear: the future of AI agents does not depend on whether a single inference is dazzling, but on whether the architecture built around the model is precise, controllable, and auditable. When we shift our attention from “smarter models” to “more reliable scaffolding,” we truly step deep into the agent architecture design space.
