AI Agent Engineering: From System Architecture to Governance Practices

    This article presents a practical engineering framework for building AI agents that can reliably complete end-to-end tasks in open environments. It covers the capability boundaries of agent systems, a reference architecture with key modules such as tool registration, memory, execution sandboxes, observability, and governance, along with core engineering challenges including planning reliability, deterministic tool calls, context management, and compute cost. It also outlines a three-layer evaluation approach and essential governance and compliance practices for moving agents from demos to production.

    1. Introduction: From Chatting to Doing

    Several recent technology signals point in the same direction: intelligent coding tools can now write code, search the web, and operate applications; model training is increasingly dependent on domestic chips; and some vendors are adjusting the pace of investment in consumer-facing AI applications. Taken together, these signals suggest a shift in industry focus—from demonstrating model capabilities to whether agents can reliably complete end-to-end tasks.

    For developers, this raises a new engineering challenge: how to make a large language model (LLM)-driven system autonomously decompose tasks, call external tools, handle exceptions, and deliver verifiable results in an open environment. Rather than focusing on any specific product, this article abstracts a general technical framework and discusses the architecture design, key modules, evaluation methods, and governance boundaries of agent systems.

    2. Capability Boundaries: What Can Agents Actually Do?

    An agent is typically defined as a software system that uses a model as its decision-making core and possesses capabilities for perception, planning, action, and reflection. Its capabilities can be broken down into four layers:

    1. Understanding layer: Parses natural language instructions and identifies intent, constraints, and implicit assumptions.
    2. Planning layer: Decomposes complex goals into executable subtasks and determines their execution order.
    3. Action layer: Interacts with the external environment through tool calls, such as reading and writing files, making network requests, and operating graphical interfaces.
    4. Reflection layer: Adjusts plans based on execution feedback and handles failure retries and strategy fallbacks.

    It is important to emphasize that the stronger the action layer, the larger the risk surface. An agent that can “control applications” essentially has operating permissions over local resources, which requires engineering-grade design for permission isolation, operation auditing, and rollback mechanisms.

    3. Reference Architecture: A Deployable Agent System

    A production-ready agent system typically includes the following modules:

    • Model inference layer: Responsible for understanding, planning, and generation, with support for multi-model routing to balance quality and cost.
    • Tool registration and scheduling layer: Describes tool names, inputs, outputs, and side-effect levels using a unified protocol.
    • Memory layer: Distinguishes between short-term context and long-term memory, with long-term memory generally implemented via vector retrieval.
    • Execution sandbox layer: Provides isolated environments for code execution and file operations.
    • Observability layer: Records full-chain tracing, token consumption, and tool call success rates.
    • Governance layer: Handles permission validation, content safety, and secondary confirmation for sensitive operations.

    A tool description can be abstracted into the following illustrative structure:

    1. {
    2. "name": "file_write",
    3. "description": "Write text to a specified path",
    4. "parameters": {
    5. "path": "string",
    6. "content": "string"
    7. },
    8. "risk_level": "medium",
    9. "requires_confirmation": true
    10. }

    The risk_level and requires_confirmation fields are often overlooked in engineering practice, yet they are critical for preventing agents from producing irreversible side effects.

    4. Key Engineering Challenges

    4.1 Planning Reliability

    Models are prone to goal drift when performing multi-step planning. Common mitigation approaches include explicitly modeling tasks as a directed acyclic graph, setting acceptance criteria for each subtask, and introducing a three-stage “plan-execute-verify” loop. The illustrative logic is as follows:

    1. plan = planner.decompose(goal)
    2. for task in plan.tasks:
    3. result = executor.run(task)
    4. if not verifier.check(task.acceptance, result):
    5. plan = planner.replan(goal, failed=task, feedback=result)

    4.2 Determinism of Tool Calls

    Model output is essentially probabilistic sampling, whereas tool calls require structured parameters. In engineering, constrained decoding or JSON schema validation is typically used, along with parameter validity checks before invocation, to avoid execution failures caused by hallucinated fields.

    4.3 Memory and Context Management

    The context window is limited, and long-term memory requires a retrieval strategy. In practice, recall is scored based on three factors—relevance, recency, and importance—and memories are summarized and compressed to prevent context expansion from driving up costs.

    4.4 Compute and Cost Structure

    Increased reliance on domestic chips on the training side implies that the inference side must also consider heterogeneous compute adaptation. Systems should support tiered model routing based on task complexity: simple tasks go to smaller models, while complex reasoning goes to larger models, thereby reducing the cost per task while maintaining quality.

    5. Evaluation System: How to Prove an Agent Is “Really Usable”

    Traditional single-turn evaluation cannot cover agent scenarios. A three-layer evaluation approach is recommended:

    1. Unit layer: Parameter accuracy and exception handling rate for individual tool calls.
    2. Task layer: End-to-end task completion rate, average number of steps, and proportion of ineffective steps.
    3. Safety layer: Unauthorized operation interception rate, sensitive operation confirmation rate, and rollback success rate.

    The evaluation set should include normal paths, boundary inputs, and adversarial samples, and failed cases should be fed back as regression test cases to form a closed loop.

    6. Governance and Compliance Essentials

    • Least privilege: Agents are granted only the resource access scope necessary to complete tasks.
    • Operation traceability: All tool calls record inputs, outputs, and execution context for auditing.
    • Human gates: Irreversible operations such as deletion, payment, and external publishing require mandatory human confirmation.
    • Content safety: Bidirectional filtering of inputs and outputs to prevent prompt injection and data leakage.

    7. A General Approach to Cloud Deployment

    In cloud environments, agent systems typically combine container platforms to host execution sandboxes, object storage to save task artifacts, message queues to decouple long-running tasks, and logging services with monitoring and alerting to ensure observability. The general cloud product categories offered by Baidu AI Cloud in such scenarios can serve as a reference foundation for building similar systems, though specific selection still needs to be evaluated against actual workloads and compliance requirements.

    8. Conclusion

    Agents are moving from demonstrations to production, and the competitive focus is no longer on isolated model capabilities but on the combined engineering capabilities of “planning reliability + tool determinism + security governance + cost efficiency.” If developers can establish measurable, regression-testable, and auditable practices across these four dimensions, they can genuinely embed agents into business processes rather than leaving them at the proof-of-concept stage.