Architecture, Evaluation, and Production Practice for AI Coding Agents

    This article explains how AI coding agents differ from code completion, covering their evolution, layered architecture, task loop, key techniques, evaluation dimensions, and enterprise rollout and governance. Readers get a practical view of planning, verification, sandboxing, and auditability for delivering reviewable, rollback-ready changes.

    From generating code to completing engineering work

    An AI coding agent is not a simple upgrade of traditional code completion. It is an engineering system that uses a large language model as the reasoning core and connects the repository, build and test, version control, runtime, and human collaboration. The goal is not only to produce code that looks correct, but to understand requirements in a controlled environment, locate context, propose changes, run verification, iterate on feedback, and deliver reviewable, rollback-ready, reproducible diffs.

    Evaluating an agent therefore cannot rest on generation speed or completion hit rate alone. What matters is whether it can finish work under real engineering constraints: repository-level dependencies, project conventions, builds and tests, bounded change scope, exposed risk, and a full audit trail. For enterprises, the core value is standardizing repetitive maintenance, test backfill, defect localization, dependency upgrades, and documentation sync, while making quality, cost, and security measurable.

    Evolution: completion, chat, agents, and cloud autonomy

    AI coding capability has gone through several stages. They do not replace one another; they coexist for different tasks.

    Stage 1: line- or snippet-level completion. The system predicts the next code from the current file, cursor, and a small context. Emphasis is low latency and high frequency. Focus areas include code language models, caching, and local context compression. Cross-file refactoring, requirement understanding, and test verification remain limited.

    Stage 2: conversational assistance. Developers describe problems in natural language; the model returns explanations, examples, refactor suggestions, or tests. Knowledge retrieval improves, but people still drive the task, and the model has weak awareness of repository state and run results.

    Stage 3: tool-using coding agents. The model can call tools: read files, search symbols, generate patches, run tests, inspect static analysis, and repair from failures. The system needs planning, permission control, sandboxed execution, and audit. The boundary shifts from “suggest” to “execute.”

    Stage 4: long-horizon, cloud-based autonomous or semi-autonomous agents. Tasks run in remote environments. Agents may explore multiple approaches in parallel, keep task memory, and advance multi-round edits, delivering merge requests or patches. Browser entry points and networked control planes let developers manage many agent jobs, but production still needs human approval, policy gateways, and rollback. The industry is moving from single-turn interaction to orchestrated task loops, with evaluation, benchmarks, skill reuse, and engineering governance emerging around them.

    Core architecture: a layered, decoupled system

    A production-ready coding agent typically splits into six layers.

    1. Interaction layer

    This faces developers via IDE plugins, web consoles, CLIs, or task boards. It collects requirements, shows plans, presents diffs, requests approval, and reports results. The point is not a chat box, but presenting plans, tool calls, test reports, and risk signals so changes are not a black box.

    2. Orchestration layer

    A planner, executor, reviewer, memory module, and state machine. The planner decomposes requirements into a task graph; the executor calls tools; the reviewer checks patch quality and risk; memory holds task state and project preferences. Support timeouts, retries, rollback, human takeover, and parallel branches so agents do not loop on failure.

    3. Model layer

    Use a hybrid stack rather than one model for everything. Route low-latency completion, classification, and format checks to smaller models; complex planning, cross-file localization, and hard bug fixes to stronger models; review and security to specialized prompts or models. Route dynamically by complexity, latency budget, cost cap, and data sensitivity.

    4. Context layer

    Repository indexing, symbol search, dependency analysis, test mapping, and history retrieval. Vector similarity is not enough; combine ASTs, symbol references, call graphs, dependency graphs, and coverage. Manage context budget: prefer files, interfaces, tests, and conventions tied to the task; compress the rest; redact secrets, tokens, and sensitive config.

    5. Tool and execution layers

    Tools cover file read, patch generation, build, unit tests, static analysis, formatting, container sandboxes, and artifact storage. Execution provides isolation, quotas, network limits, timeouts, and log collection. Record inputs, outputs, versions, and duration for every tool call so issues are traceable and results reproducible.

    6. Governance layer

    Identity, permissions, policy checks, cost accounting, audit, and evaluation. Can the agent write protected directories, reach the public network, or read production data? Are patches scanned? Are model and prompt versions recorded? Only with this layer can agents leave demos and enter enterprise delivery.

    At the infrastructure layer, generic container, object storage, logging, and monitoring capabilities—such as those from Baidu AI Cloud—can host isolated runtimes. Choose based on existing stack, with tenant isolation, elastic scheduling, audit trails, and resource reclaim as priorities.

    Task loop: plan, execute, verify, remember

    The core workflow is: understand the task, select context, plan, generate a patch, verify, review and repair, deliver. Illustrative pseudocode:

    1. class CodingAgent:
    2. def run(self, task, repo, tools, memory):
    3. spec = self.clarify(task)
    4. plan = self.planner.decompose(spec, repo.index)
    5. for step in plan:
    6. ctx = self.retriever.collect(step, repo, memory)
    7. patch = self.coder.propose(step, ctx)
    8. report = self.verifier.check(patch, tools)
    9. if not report.passed:
    10. patch = self.coder.repair(step, ctx, report)
    11. if self.reviewer.risky(patch, report):
    12. return self.handoff_to_human(step, patch, report)
    13. memory.log(step, patch, report)
    14. return self.deliver(patch, report)

    Principles:

    First, clarify acceptance criteria. Input is more than a one-line request: target behavior, constraints, affected modules, tests, and off-limits areas.

    Second, plans must be executable and checkable. Split into locate, add tests, change implementation, verify, and write change notes, each with done conditions.

    Third, keep patches small. Agents tend to rewrite broadly, raising review load and regression risk. Limit scope, prefer the smallest viable patch, and confirm blast radius with static analysis and tests.

    Fourth, automate verification. Build, unit and integration tests, static analysis, security scans, and format checks should be a fixed suite. On failure the agent may repair from logs, but must not “pass” by deleting tests, skipping assertions, or weakening checks.

    Fifth, high-risk changes need human takeover. Auth, payments, data deletion, crypto, network boundaries, and core protocols should hit a policy gateway and wait for approval.

    Technical priorities

    1. Repository-scale context

    Real tasks span files and modules. Agents must find interfaces, callers, implementations, config, migrations, and tests. A practical mix is lexical + semantic + symbol-graph retrieval, reranked with recent changes, coverage, and dependencies. Indexes should update incrementally.

    2. Hybrid model routing

    High-frequency, simple work uses low-latency models; complex planning uses stronger models; review uses stricter prompts; security uses independent rules plus models. Routing should be configurable and observable, logging model version, prompt version, latency, and cost.

    3. Prompt and context security

    Comments, docs, fixtures, and dependencies may contain untrusted text. Treat retrieved content as data, not instructions; isolate task instructions from context so malicious comments cannot leak secrets or touch unrelated files. Redact and access-control sensitive files, env vars, and credentials.

    4. Tool use and sandboxing

    Builds and tests run in isolated containers with limited egress, filesystem, and resources. Tools should return structured results, not only natural-language logs. Default-deny or require confirmation for dependency installs, external scripts, and migrations.

    5. Memory and improvement

    Short-term memory holds the plan, tried approaches, and failures; long-term holds conventions, test commands, style, and domain knowledge. Filter and redact; do not store secrets, personal data, or debug dumps. After tasks, feed successful patches, review comments, and failures into eval sets.

    Evaluation: from local correctness to engineering trust

    Agent evaluation is harder than single-shot generation because of multi-step decisions, tools, environment state, and long horizons. Cover at least:

    1. Functional correctness: the patch meets the spec and hidden/regression tests.
    2. Repository understanding: cross-file deps, existing abstractions, project structure.
    3. Instruction following: scope, style, prohibitions, delivery format. Checklists of binary pass/fail items help, plus human review so surface compliance is not enough.
    4. Long-horizon stability: goal consistency across tool rounds and repairs; no loops, forgetting, or privilege creep.
    5. Engineering quality: patch size, duplication, complexity, readability, coverage, docs.
    6. Security and compliance: injection, leaks, dependency and license risk, unauthorized actions.
    7. Cost and efficiency: time, model cost, tool calls, human takeover rate, review time.

    Eval environments must be reproducible: tasks, dependency versions, test commands, and scoring scripts fixed. Avoid overfitting to public tests; add unseen tasks, adversarial cases, and real repo changes. Open eval platforms, repo-level instruction-following benchmarks, and containerized harnesses help fair comparison across languages, frameworks, and workflows, and allow third-party sets. Benchmarks are slices; enterprises still need shadow evals from real work.

    Rollout path and governance

    Do not start with full autonomy. Begin with low-risk, high-repeat, verifiable work: unit tests, static-check fixes, docs, small bugs, dependency upgrades; then cross-file refactors and feature work; only later cloud multi-agent orchestration.

    Build:

    • Least privilege: dedicated identity, limited readable repos, writable paths, and tools.
    • Protected branches: no direct writes to core branches; patches, MRs, and human review.
    • Observability: plans, prompts, model versions, tool I/O, tests, and approvals for tracing.
    • Cost control: per-task budgets, routing, and caching to avoid runaway context and retries.
    • Data governance: boundaries for code, logs, and artifacts; isolated or private deploy for sensitive projects.
    • Human collaboration: a delegable engineering assistant, not a substitute for review or architecture.
    • Metrics: first-pass rate, review accept rate, regressions, lead time, takeover rate, cost per task.

    Organizationally, combine a platform team (access, sandbox, tool gateway, eval pipeline), pilot teams (real tasks and feedback), and security/process teams (permissions, audit, compliance). Embed the agent in existing SDLC rather than as an isolated tool.

    Risks include hallucinated APIs, misuse of dependencies, over-editing, deleting tests to pass, prompt injection from repo text, leaks, supply-chain and license issues. Mitigation is policy, sandbox, automated verification, human approval, and audit—not model skill alone.

    Near-term directions: stronger repo context with symbol graphs and runtime feedback; finer routing and cost optimization; skill packs for tools, prompts, and domain knowledge; richer evals for languages, frameworks, and long tasks; cloud multi-agent roles for plan, implement, test, and review. Trust still comes from a verifiable, rollback-ready, auditable loop.

    Conclusion

    Competitiveness is not lines generated in one shot, but stably finishing work in real repos and processes. A sound path is layered decoupling of models, context, tools, and governance; a task loop that makes results verifiable; evaluation that calibrates quality; and security policy that bounds risk. Turning code generation into measurable, auditable, sustainable engineering productivity is the point of landing AI coding agents.