How AI Coding Agents Are Built: From Code Generation to Closed-Loop Execution

    This article examines how coding agents evolved from models that merely write code into tools that can operate inside real codebases. It outlines the four capability thresholds required for this shift, explains context engineering across repository, symbol, and snippet layers, and covers the permissions, rollback, and observability designs needed to make agent-based coding practical. It also discusses long-task orchestration, human-agent collaboration, evaluation metrics, and how teams can adopt these tools incrementally while being clear about their limitations.

    1. Why “Writing Code” Is Not the Same as “Doing the Work”

    Around 2021, a newly founded AI research organization placed an unusually high priority on coding ability. The researchers’ approach was straightforward: have the model write a small function, use unit tests to judge correctness, collect failure cases, decompose tasks, adjust training, and iterate repeatedly. What came out of this stage was “a model that can write code,” not “an agent that can do work inside a codebase.” A full set of engineering capabilities sits between the two.

    Understanding this dividing line is key to understanding how AI coding tools evolved. Function-level generation only requires a model to produce a self-consistent snippet within a short, given context. Real codebase tasks, by contrast, require a tool to complete a closed loop of locating, retrieving, modifying, validating, and rolling back. The former is a capability problem; the latter is a systems engineering problem.

    By 2022, coding assistants were formally put on the agenda. In early 2025, the first tool closest in form to a terminal agent appeared: it could read code, modify files, execute commands, and continue correcting itself based on execution results. By mid-2025, it had been integrated into editors and code-hosting workflows, becoming part of everyday code review and task assignment. In the second half of 2025, the focus shifted toward more autonomous workflows, longer tasks, and more controllable rollback. By 2026, this class of tools had become a core benchmark for measuring whether AI can enter real work environments.

    2. Capability Thresholds: From Completion to a Closed Loop

    A leap in usability usually comes from crossing four thresholds simultaneously:

    • Instruction following and structured output become stable, and tool-call parameters no longer fail frequently;
    • Long-context retrieval and localization accuracy improve, allowing relevant files to be found in large repositories;
    • Multi-turn self-correction becomes effective, with the ability to read errors and adjust the approach rather than repeating the same mistake;
    • Cost and latency fall into an acceptable range, making “run a few more validation rounds” economically viable.

    Only when all four are met does the product form shift from “completion” to “agentic closed loop.”

    3. Context Engineering: The Variable That Really Determines Success

    1. task description → repository retrieval → relevant files and symbols → change plan → patch → build/test → result feedback → rollback or continue

    In engineering practice, context is usually organized in three layers: the repository structure layer (directories, module boundaries, dependencies), the symbol layer (definitions and references), and the snippet layer (code and tests directly relevant to the task). For retrieval, keyword search and semantic search complement each other; layering in reference-graph expansion can significantly reduce the probability of “editing the wrong file.” At the same time, injection volume must be strictly controlled: irrelevant context not only wastes budget but also dilutes attention, causing the model to focus on the wrong things.

    4. Permissions, Rollback, and Observability

    For agent-based tools, risk concentrates on two actions: “write” and “execute.” Mature solutions typically include:

    1. Tiered authorization: read operations are allowed by default, write operations are restricted to a directory allowlist, and command execution is graded by risk level and requires confirmation;
    2. Rollback-capable design: changes land as patches or branches, with one operation corresponding to one undoable unit;
    3. Sandboxing and isolation: builds and tests run in containers or isolated workspaces to avoid contaminating the environment;
    4. Full-chain logging: prompts, tool calls, command output, and timing are recorded to support review and auditing.

    An illustrative policy configuration:

    1. permissions:
    2. read: allow
    3. write: { allow_paths: ["src/", "tests/"] }
    4. exec: { level: medium, confirm: true }
    5. rollback: { unit: patch, keep_history: true }

    5. Long-Task Orchestration and Human-Agent Collaboration

    The stability of long tasks comes from three things: “decompose—checkpoint—converge.” Break the goal into small, verifiable steps; set a checkpoint for each step and preserve intermediate artifacts; when a deviation appears, return to the nearest checkpoint rather than starting from scratch. On the division of labor, humans are responsible for defining goals, setting constraints, and final review, while the agent handles retrieval, implementation, and validation. The review step requires output of a change summary, impact scope, and test results to reduce review cost.

    6. Measuring Effectiveness and Team Adoption

    Evaluation should cover three layers: task success rate, first-pass rate, and human rework rate make up the effectiveness layer; time per task and number of calls make up the efficiency layer; and privilege-boundary violations and erroneous-edit rate make up the safety layer. For adoption, start from low-risk scenarios (writing tests, fixing minor defects, writing documentation), accumulate team convention files (directory standards, test commands, commit requirements), then gradually expand to cross-module changes. In practices of this kind, Baidu AI Cloud is often used to provide general-purpose infrastructure such as container platforms, logging services, and monitoring/alerting, giving agents an isolated environment and observability support.

    7. Capability Boundaries

    It excels at locally well-defined tasks that can be automatically validated; it struggles with ambiguous goals, cross-system contract changes, and legacy modules lacking test coverage. A clear boundary statement builds team trust and delivers more real value than overstating capabilities.