AI Coding Agents: A Three-Layer Architecture Explained

    This article breaks down the three-layer architecture behind AI coding agents—model, execution system, and orchestration layer—and explains how they work together to turn model outputs into real actions. It compares chat and execution loops, outlines three common agent types, and offers practical guidance on evaluation dimensions, permission boundaries, testing, sandboxing, and audit logging.

    1. Separating the Three Layers

    Many discussions conflate “model capability” with “the work AI can complete.” In practice, a system that can actually get things done typically consists of three layers.

    The first layer is the model. The model receives text or multimodal input and outputs reasoning results, code, or structured instructions. It does not read files or run tests itself; it only generates the next piece of content based on context.

    The second layer is the execution system. The execution system is responsible for turning the model’s output into real actions—reading files, searching code, editing files, running commands, calling APIs—and feeding results back to the model. It determines what the model can see, what it can do, and how to roll back when something goes wrong.

    The third layer is the orchestration layer. When a task requires multiple models, multiple tools, or multiple execution environments to work together, the orchestration layer handles task allocation, model selection, context management, and result aggregation.

    The relationship among the three layers can be summarized as: the model makes judgments, the execution system takes action, and the orchestration layer organizes resources.

    2. What Separates Chat from Execution

    The basic loop in a chat scenario is: the user asks a question, the model answers, and the user decides whether to accept the response. The execution scenario involves a longer loop, illustrated below:

    1. while task is not complete and step limit is not exceeded:
    2. observe = collect current state (file contents, command output, test results)
    3. plan = model proposes next step based on goal and observations
    4. validate = check whether the plan is within permitted boundaries
    5. act = execute tool call
    6. record = write action and result to log
    7. after task ends, run verification; if it fails, return to the loop

    This loop has three key differences.

    The first is context acquisition. A chat model can only see what the user pastes in; an execution system can proactively search the codebase, read configuration, and inspect error logs. The quality of context often matters more than model parameters in determining outcomes.

    The second is state persistence. When executing multi-step tasks, the system needs to remember which files have been modified, which approaches have been tried, and why they failed. Otherwise, the model will repeat the same mistakes.

    The third is the verification loop. Execution without tests or checks only produces unverified changes faster. Mature execution systems incorporate compilation, unit tests, and static analysis into the loop.

    3. Three Typical Forms

    Based on their positioning, common execution systems today fall roughly into three categories.

    1. Development Workbench

    These systems are embedded directly in an editor or terminal and focus on writing, modifying, and debugging code. They excel at well-bounded tasks—adding tests for a function, fixing a specific error, or implementing a new endpoint following an existing pattern.

    Their advantage is fast feedback with changes landing directly in the project. The risk is that when task scope is too large, the model can drift further along a local optimum. Task descriptions therefore need to be explicit, and changes should be committed in stages.

    2. Structural Understanding

    These systems emphasize a global understanding of large codebases, including module dependencies, call chains, architectural layers, and historical evolution. They are suited to answering questions like “where is this feature distributed?” or “which modules are affected by changing a shared interface?”

    The value of these tasks lies primarily in building accurate indexes and dependency graphs; how much code is generated is secondary. Output typically takes the form of analysis reports, impact scope lists, or refactoring plans, and final changes still require engineer review.

    3. Multi-Model Orchestration

    Orchestration systems do not bind to a single model. Instead, they provide a unified interface and treat different models as replaceable capability units. They can select models based on task type, cost budget, response latency, or data sensitivity, and can have multiple models cross-check each other’s results.

    Below is a simplified interface sketch illustrating the basic orchestration approach:

    1. interface ModelAdapter:
    2. name
    3. function complete(prompt, available_tools) -> structured_result
    4. class Orchestrator:
    5. init(adapter_list, routing_policy)
    6. function run(task):
    7. selected_adapter = routing_policy.select(task)
    8. result = selected_adapter.complete(task.prompt, task.tools)
    9. if result validation fails:
    10. switch to fallback adapter and retry
    11. return result

    Routing policies can be as simple as matching on task tags, or they can dynamically adjust based on quality assessments and cost data. The key is that the orchestration layer itself must retain logs that explain the basis for each selection.

    4. Dimensions for Comparison

    When discussing which type of system is better, you should first define comparison dimensions and then evaluate each one. Vague comparisons of “intelligence” are of limited value. The following dimensions are more practical:

    Dimension Question to Ask
    Task type Single-file edit, cross-module refactor, or global analysis
    Code scale Project size and dependency complexity, which determine context retrieval difficulty
    Permission boundaries Which directories can be read or written, which commands can be executed
    Auditability Whether every action is logged and can be replayed
    Model replaceability Whether switching models requires changes to business processes
    Data compliance Whether code and data are allowed to be sent to external services

    Teams should run small-scale pilots with real tasks, record success rates, rework counts, and manual review time, and then decide on broader adoption.

    5. Practical Guidelines for Adoption

    Least privilege. By default, the execution system should only expose the directories and commands required for the current task. High-risk operations such as deletion, deployment, and permission changes should require human confirmation.

    Write tests before letting the system modify code. Converting expected behavior into executable tests gives the system’s changes an objective acceptance standard.

    Commit in stages. Break large tasks into multiple reviewable steps, each of which can be independently rolled back.

    Isolate the execution environment. Run commands in a container or sandbox to avoid uncontrolled impact on the host environment.

    Retain complete logs. Record model inputs, tool calls, command output, and final results—this supports both post-mortem debugging and compliance auditing.

    Below is a sketch of a permission check illustrating the “validate first, execute second” principle:

    1. allowed_action_types = {read_file, search_code, run_tests}
    2. forbidden_path_prefixes = [production_config_dir, secret_store_dir]
    3. function execute_tool(action):
    4. if action.type not in allowed_action_types:
    5. log rejection
    6. return requires_human_confirmation
    7. if action.path starts with any forbidden_path_prefix:
    8. log rejection
    9. return denied
    10. return execute(action)

    6. Conclusion

    The core shift as AI moves from answering questions to completing tasks lies in the maturation of the surrounding execution system. Model capability determines judgment quality, the execution system determines the scope of actions, and the orchestration layer determines how resources are organized. When evaluating options, consider all three layers together, make choices based on task type, project scale, permissions, and compliance requirements, and continuously calibrate through pilots and logs.