AI Agent Architecture Design Space: Why 98% of the Code Is Not the Model

    This article breaks down the architecture design space of modern AI coding agents. It explains why deterministic engineering scaffolding, not prompt engineering or raw model calls, accounts for more than 98% of the system, and details the five core values, seven decoupled components, and the operational responsibilities handled by that scaffolding. Readers will learn how to structure a thin decision layer on top of a thick execution layer, including permission gating, sandbox isolation, and state management, along with practical guidance for building enterprise-grade agents on Baidu AI Cloud.

    Introduction: The Misread “Intelligence” and the Real Engineering Skeleton

    When people discuss cutting-edge AI coding tools, a common assumption is that their power comes from almost magical prompts. Yet an abstract analysis of the underlying logic of modern complex agent systems reveals a counterintuitive fact: the code that actually drives the model to reason and decide typically accounts for less than 2% of the total. The remaining 98% or more consists entirely of a deterministic operational harness.

    This means the core competitiveness of an agent system is not simply “calling a model,” but the precise execution infrastructure built around it. The model is responsible only for thinking and proposing actions, while parsing, executing, intercepting, rolling back, and trimming context for those actions are all handled by the underlying deterministic code. This article systematically dissects the construction methodology of such systems from an architecture design space perspective, providing a theoretical foundation for developers building enterprise-grade applications on Baidu AI Cloud.

    Part 1: Five Core Values Driving Architecture Design

    Any large distributed or agent system is inevitably driven by a clear set of values. When building an autonomous coding agent, five principles form lines that cannot be crossed:

    1. Human-in-the-Loop: The architecture must guarantee that humans hold final veto power. This applies not only at the interaction layer but at the architectural layer: any write, delete, or network request must be suspended pending human review. The architecture needs an interrupt signal channel so humans can stop and redirect a long-running task at any time.
    2. Default Deny: Security should not depend on humans never being careless. The system starts in a zero-permission state, and every sensitive operation, such as writing to the file system or reading environment variables, must be explicitly requested. This allowlist mechanism keeps the sandbox intact even when the model hallucinates or is fed malicious instructions.
    3. Reliable Execution: Getting a single task right is only the passing grade; state consistency across long conversations is the real difficulty. The architecture must solve the context rot problem and use deterministic state management to keep system behavior from drifting after multiple turns.
    4. Capability Amplification: Use the thinnest possible decision layer to leverage the strongest execution environment. The goal is not to make the model do more, but to make it do fewer, more critical things and hand the heavy work to a deterministic toolchain.
    5. Context Adaptability: The system should sense the user’s environment, such as the current project type and the user’s technical level, and dynamically adjust interaction verbosity and permission strictness to build human-machine trust.

    Part 2: Seven Core Components of the Macro Architecture

    From a macro perspective, such an agent system decomposes into seven decoupled core components. This decoupling is the physical basis for the “thin decisions, thick execution” philosophy.

    1. Interfaces

    Whether it is a command-line interface (CLI), an IDE plugin, or programmatic invocation through an SDK, the interface layer is responsible for protocol conversion. It normalizes heterogeneous input into a standardized internal message stream, hides front-end differences, and ensures all requests converge on the same core loop.

    2. Agent Loop

    This is the heart of the system, usually abstracted as a queryLoop function. Its logic is minimal: receive context, request model inference, parse the action intent in the model output, dispatch to the tool pool, collect results, and repeat. There is no complex magic here, only rigorous state machine transitions.

    Illustrative pseudocode:

    1. async function queryLoop(context: Context) {
    2. while (!context.isTerminated) {
    3. const response = await model.generate(context.getMessages());
    4. const action = parseAction(response);
    5. if (action.type === 'tool_use') {
    6. const result = await permissionGate.execute(action);
    7. context.append(result);
    8. } else {
    9. break;
    10. }
    11. }
    12. }

    3. Permission System

    Sitting between the core loop and the tool pool, this is the gatekeeper of the security architecture. It intercepts every tool call request and rules on it according to the current session’s permission policy (Allow/Ask/Deny). In related implementations on Baidu AI Cloud, this layer is often combined with identity and access management capabilities to achieve fine-grained resource control.

    4. Tools

    This pool contains atomic capabilities such as file read/write, shell execution, code search, and external API calls. Tool definitions must be deterministic, idempotent where possible, and equipped with thorough input validation (schema validation).

    5. Execution Environment

    This is the key to isolating risk. All generated code and shell commands run in a restricted container with limited access to the host machine. Container platforms or function compute services can be combined to achieve resource elasticity and isolation.

    6. State and Persistence

    Responsible for saving conversation history, file modification records, and task progress. Object storage or database services ensure the system can restore its state after a crash and support resuming long-running tasks from a checkpoint.

    7. User

    At the top of the architecture, interacting with the system through the interface layer, the user is the only decision initiator and risk bearer.

    Part 3: How the Deterministic Harness Handles 98.4% of the Work

    If the model handles only 1.6% of the thinking, what does the remaining 98.4% do? This engineering scaffolding is the foundation of stable operation:

    • Context compression and management: Long conversations inevitably lead to token overflow. The harness implements sliding windows, summary extraction, or vector retrieval to dynamically trim history while preserving key decision points.
    • Error recovery and retry: When a tool execution fails, such as a network timeout or syntax error, the harness catches the exception, formats it into an observation the model can understand, and feeds it back to the core loop to drive self-correction.
    • Streaming parsing and incremental rendering: Processing the model’s streaming output and parsing partial JSON or code blocks in real time to improve front-end interaction.
    • Security redaction and injection defense: Scanning user input and model output before execution to prevent prompt injection attacks from bypassing the permission gate.

    Part 4: Enterprise Implementation and Working with the Baidu AI Cloud Ecosystem

    For enterprise developers who want to integrate this architecture into their own products, the recommended implementation path is:

    1. Decouple the model from execution: Never hardcode business logic into prompts. Extract permission checks, logging, and sandbox scheduling into independent middleware.
    2. Use cloud-native infrastructure: On Baidu AI Cloud, container services can build isolated sandboxes, log services can provide full-chain auditing, and monitoring and alerting systems can track the health of the agent loop in real time.
    3. Build progressive trust: Start with a strict default-deny policy, then gradually open automatic execution permissions for low-risk tools as system stability improves.

    Conclusion

    Future AI coding tools are not omnipotent magic boxes but high-performance engines running on precise deterministic gears. Understanding the “thin decision layer plus thick execution layer” design space, shedding the overreliance on prompts, and focusing on hard engineering practices such as permission gates, sandbox isolation, and state management is the only path to building the next generation of reliable agent systems.