The Evolution and Practice of General-Purpose AI Coding Agents

    This article traces the shift of AI agents from code completion toward general task execution, and explains what it takes to run them reliably in production. It breaks a general-purpose agent into five layers (model, context, tools, orchestration, governance), then covers context engineering, tool-call design, orchestration and termination conditions, a reference cloud architecture, a three-tier evaluation system, and a governance risk checklist. The key takeaway: reliability, auditability, and controllability—not human-like output—now determine whether an agent leaves the demo environment and becomes a measurable productivity unit.

    1. From “Writing Code” to “Doing Work”: Why the Product Form Is Changing

    Over the past two years, AI coding agents have delivered stable value in code completion, unit test generation, and defect localization. But when engineering teams extend the same capabilities to non-coding work—requirements gathering, log analysis, report reconciliation, document writing—they run into a consistent reality: what limits an agent is not the model’s language proficiency, but whether it can safely obtain context, call tools, and take responsibility for the results.

    This has produced a clear product evolution path: abstract coding-oriented agent capabilities into a general-purpose task execution framework, then port that framework to a broader set of office and business scenarios. The essence of the shift is moving from “the model is the product” to “the agent is the platform”—vendors no longer offer just an inference endpoint, but a complete foundation for task orchestration, tool integration, access control, and observability.

    For enterprises, this changes what selection criteria matter. Generation quality alone is not enough; what matters is the agent’s controllability, auditability, and extensibility inside real workflows.

    2. Capability Layers: What a General-Purpose Agent Is Made Of

    Broken apart, a general-purpose agent has five layers. Understanding the layering is the key to avoiding agents that “demo well but never ship.”

    1. Model layer: Understands intent, plans steps, and generates structured output. In engineering terms, it usually needs long context, stable instruction following, and switchable model routing.
    2. Context layer: Organizes enterprise knowledge, files, conversation history, and permission scope into model-ready input. This layer determines what the agent “knows.”
    3. Tool layer: Reads and writes files, searches knowledge bases, calls internal APIs, runs scripts, and operates on spreadsheets and documents. The quality of tool definitions directly determines the success rate.
    4. Orchestration layer: Handles task decomposition, loop control, failure retries, parallel and serial strategies, and termination conditions. It is the agent’s “cerebral cortex.”
    5. Governance layer: Handles authentication, least privilege, approval flows, redaction, audit logs, and cost quotas. An agent without a governance layer cannot enter production.

    A common mistake is conflating layers 2 and 3: stuffing large amounts of raw text into the prompt instead of building retrieval and tool capabilities. The former is expensive, noisy, and hard to update; the latter is the sustainable approach.

    3. Context Engineering: The Invisible Battlefield That Decides Success

    Context in general scenarios is dirtier, more scattered, and more sensitive than code. Three principles work well in practice.

    Principle 1: Retrieve on demand, do not feed everything. Use lightweight retrieval to locate candidate fragments first, then let the model decide whether to dig deeper, forming a “retrieve—read—retrieve again” loop.

    Principle 2: Structure first. Converting unstructured documents into a structured intermediate representation with heading hierarchy, tables, and fields significantly reduces misreading. Example:

    1. {
    2. "doc_id": "report_2026_03",
    3. "sections": [
    4. {"path": "2.1 Metric Definitions", "text": "...", "acl": ["finance"]}
    5. ],
    6. "tables": [{"name": "Monthly Summary", "columns": ["Month","Revenue","Cost"]}]
    7. }

    Principle 3: Let permissions flow with the context. Every fragment should carry an access control tag, and filtering should happen before the prompt is assembled—avoiding the fragile design of “fetch everything, then trust the model to behave.”

    4. Tool-Call Design: Turning “Able to Do” into “Doing It Right”

    Tools are the agent’s hands and feet. The design points concentrate in four areas.

    • The description is the contract: The tool name, purpose, when it applies and does not apply, and parameter constraints must be explicit, so the model can select correctly.
    • Idempotency and rollback: Write operations should support idempotency keys and an undo path, so retries are safe on failure.
    • Structured returns: Return JSON rather than free text, so the orchestration layer can make decisions and keep records.
    • Readable errors: Error messages should include actionable guidance, not just a stack trace.
    1. def search_docs(query: str, acl: list[str], top_k: int = 5) -> dict:
    2. # 1) validate permission scope 2) retrieve 3) filter 4) structured return
    3. return {"items": [...], "truncated": False}

    5. Orchestration and Termination: Avoiding Infinite Loops and “Confident Mistakes”

    The orchestration layer needs an explicit state machine rather than letting the model improvise. A recommended flow includes plan generation, step execution, result validation, fallback when necessary, and final summarization. Termination conditions should cover at least four cases: goal achieved, budget exhausted, consecutive-failure threshold reached, and human approval rejected.

    Also introduce a “validator” role: an independent prompt or set of rules checks output for consistency (do the numbers add up, do the citations exist, is the format compliant). This step markedly reduces conclusions that look plausible but cannot be traced.

    6. Reference Architecture: Building a Controllable Setup on the Cloud

    On Baidu AI Cloud, a general category combination works: object storage holds raw documents and intermediate artifacts, a message queue takes on long-running tasks and asynchronous callbacks, a container platform hosts the agent runtime and tool services, logging and monitoring with alerting provide full-chain tracing and a cost dashboard, and key management plus identity services handle credential custody and least-privilege issuance.

    1. User request -> Access & auth -> Orchestration service (container platform)
    2. -> Retrieval service (vector/keyword) -> Tool gateway (internal API/script sandbox)
    3. -> Validator -> Persist results (object storage) -> Audit & alerting

    Key engineering constraints: a unified exit through the tool gateway, sandboxed execution isolation, full call logging, and per-tenant quota-based rate limiting.

    7. Evaluation System: Judge With Data, Not Gut Feeling

    Build a three-tier evaluation: unit level (tool correctness rate, parameter validity rate), task level (end-to-end success rate, rework count), and business level (human hours saved, cost of errors). Keep a fixed regression set for each iteration, and track security metrics such as “unauthorized access count” and “hallucinated citation rate.” Any deterioration in any of these should block the release.

    8. Risk Checklist and Governance Recommendations

    1. Data minimization: take only the fields needed to complete the task, and redact sensitive fields by default.
    2. Two-person review: force approval for high-risk write operations.
    3. Explainable traceability: retain retrieved fragments, tool inputs, and return summaries.
    4. Cost guardrails: dual quotas on per-task tokens and tool calls.
    5. Fallback strategy: when the model or a tool misbehaves, fall back to a rules-based flow and prompt for human takeover.

    9. Conclusion

    The competition among general-purpose office agents has moved from “how human-like the generation looks” to “how reliably it executes.” Get the four things—context, tools, orchestration, and governance—solid, and an agent can genuinely leave the demo environment and become a productivity unit that is measurable, auditable, and continuously optimizable within enterprise workflows.