How AI Coding Agents Are Built: From Writing Correct Functions to Working Autonomously

    This article traces how AI coding agents evolved from single-function code generation into autonomous systems that operate inside real repositories. It breaks the journey into four stages, explains the core perceive-plan-act-verify loop, and covers context engineering, permission and safety tiers, rollback via version control, team collaboration, long-task state management, evaluation metrics, and common anti-patterns. Readers will learn why objective verification, permission control, and externalized state matter more than raw model capability, and how to expand agent autonomy pragmatically.

    Introduction: Writing Code Is Not the Same as Getting Work Done

    When people discuss “intelligent coding agents,” a common mistake is to conflate two different things: whether a model can generate a correct piece of code, and whether an agent can independently complete a task inside a real repository. The former is a capability threshold; the latter is systems engineering. A real codebase means a large number of implicit conventions, cross-file dependencies, build and test pipelines, permission boundaries, and legacy issues. The model has to loop through trial and error in this friction-heavy environment until verification passes.

    This evolution roughly breaks into four stages: a capability-building phase aimed at “writing one small function correctly,” an assistant phase centered on completion and conversational edits, an autonomous-agent phase that lands in the terminal, and an engineering phase embedded in team collaboration workflows. Understanding what each stage solved is more valuable than memorizing product release dates.

    1. Capability Building: Turning Evaluation into a Closed Loop

    The goal of early work was simple: make the functions a model writes pass tests written by humans. That simple goal actually defined the methodology of the whole field—driving iteration with executable, objective signals.

    The concrete approach is a loop that keeps narrowing:

    1. Take a minimal task (implement one function);
    2. Have the model generate candidate implementations;
    3. Use unit tests to judge correctness;
    4. Collect failure samples and categorize them (a misunderstanding of requirements, a missed boundary condition, or incorrect API usage);
    5. Adjust data mix and training strategy for each failure type, then return to step 1.

    The key insight here is that structured attribution of failure samples drives capability improvement more effectively than simply piling on volume. Only after the “function-level correctness rate” crosses a usable threshold does capability begin to spill over into multi-file, multi-step tasks.

    2. The Assistant Phase: From Generating Code to Modifying Code

    The change in the second stage is not a bigger model, but a shift in interaction mode from “generation” to “modification.” Completion solves local typing efficiency, whereas modification requires the model to understand the intent and style of existing code and make minimal changes without breaking other parts. This brings two design requirements that remain valid over the long term:

    • Expressing diffs beats full rewrites: submitting changes as patches makes them easy for humans to review, easy to roll back, and easy to resolve conflicts;
    • Prioritizing context: not all files are equally important—entry files, interface definitions, tests, and configuration are usually more worth including in context than implementation details.

    3. Terminal First: Why Agents Ran in the Command Line Earliest

    Agents first landed in the terminal not as an aesthetic choice, but as the optimal solution under engineering constraints:

    • Isomorphic with the existing toolchain: reading and writing files, running builds, and executing tests are already things the command line does, so the agent doesn’t need to reinvent an execution environment;
    • Naturally complete observability: every tool call is a readable log entry, which makes debugging and auditing easier;
    • Clear permission boundaries: the file system and processes are the boundaries where whitelists, sandboxes, and confirmation gates are easiest to enforce;
    • Easy to compose: pipes, scripts, and CI can all be reused directly.

    The cost is a high interaction barrier, which is why the approach later extended gradually toward editors and code-hosting workflows.

    4. The Core Loop: Perceive, Plan, Act, Verify

    A usable agent is essentially a controlled loop, not a single question-and-answer exchange:

    1. while not done and budget remains:
    2. ctx = retrieve_context(goal, repo) # perceive: retrieve + layered loading
    3. plan = decompose(goal, ctx) # plan: split into verifiable subgoals
    4. act = apply_patch(plan.step) # act: minimal-diff changes
    5. obs = run(verify_cmd) # verify: build / test / lint
    6. if obs.failed:
    7. ctx = summarize_failure(obs) # feed failure info back into context
    8. else:
    9. commit_checkpoint(plan.step) # record a checkpoint to support rollback

    Among the four stages, the one most often underestimated is verification. An agent without an objective verification signal is just producing plausible-looking code at high speed; only with compilation, static checks, and tests as feedback does the loop gain convergence.

    Context Engineering

    Context is not “the more the better,” but a three-layer structure: a resident layer (project conventions, a directory map, build and test commands), an on-demand layer (retrieved relevant files and call chains), and a temporary layer (the current failure log and a summary of completed steps). The temporary layer must be compressible, otherwise long tasks will inevitably overflow.

    Permissions and Security

    Autonomy is proportional to risk, so it needs to be tiered: read-only operations can run automatically; write operations are limited to the workspace and whitelisted paths; high-risk actions such as deletion, pushing, deployment, and outbound network access must be explicitly confirmed. In production, this should also be paired with containerized sandboxes, least-privilege credentials, and complete operation auditing.

    Rollback

    Treat version control as the agent’s “transaction log”: land a checkpoint for every subgoal that passes verification, and roll back to the last green state on failure. This is far more reliable than having the model “remember what it changed” within a long context.

    5. Moving Toward Collaboration: From Personal Tool to Team Workflow

    When an agent enters a team, the focus shifts from “can it do the work” to “can it be trusted”:

    • Diverse integration points: the terminal, the editor, and the task and review stages of code-hosting platforms each fit different granularities;
    • Externalized rules: writing the tech stack, directory conventions, test commands, and prohibited actions into a convention file inside the repository makes behavior versionable and reviewable;
    • Shifting gates earlier: running formatting, static checks, and unit tests before commits catches problems ahead of review;
    • Human in the loop: the agent handles first drafts and mechanical refactoring, while humans handle design decisions and final sign-off.

    For deployment, a common approach is to run the agent on a container platform, paired with object storage for build artifacts, a message queue to decouple long tasks, and logging services with monitoring and alerting for observability. Product catalogs such as Baidu AI Cloud also offer the general capability categories above, which can be combined as needed rather than relying on a single proprietary interface.

    6. Long Tasks and Autonomy: State Must Be Externalized

    Once a task exceeds a single context window, the design focus turns to state management: write todos, completed items, and ruled-out approaches into external files; load only the necessary fragments at each step; make retries carry a summary of “what has already been tried” to avoid spinning in place; and set step, time, and cost budgets, stopping and returning control once the budget is exceeded.

    7. Evaluation: Use Data Instead of Gut Feeling

    It is advisable to track at least four metrics: the first-pass task success rate, the manual rework rate, the number of manual interventions per task, and the density of review comments. Adding regression test pass rate and rollback rate on top of these is what lets you judge whether the agent is genuinely improving efficiency or simply shifting cost into review and troubleshooting.

    8. Common Anti-Patterns

    • Hallucinating nonexistent interfaces and parameters—this needs to be forced back to reality through retrieval and compilation checks;
    • Context pollution—piling up failure logs and old approaches leads the model to repeat wrong paths;
    • Over-autonomy—without confirmation points and rollback, a single misoperation can overwrite the work of many people;
    • Poor repository hygiene—when tests and conventions are missing, the agent’s output cannot be verified and the benefit drops to zero.

    Conclusion

    The maturity of intelligent coding agents has never been the victory of a single point of model capability, but the combined result of “capability threshold + objective verification + permission control + externalized state.” For teams, the pragmatic path is: first fill in tests and conventions, then start with low-risk, verifiable tasks, gradually expand the scope of autonomy, and continuously calibrate the trust boundary with metrics.