From Generation to Execution: Technical Architecture and Practices for AI Agent Systems

    This article explains how AI agent systems evolve from content generation to task execution, and what it takes to run them reliably in production. It outlines a five-layer reference architecture, key components such as task planning, tool invocation, context and memory management, retrieval, and sandboxed code execution, along with engineering constraints for stability, evaluation, observability, security, and compliance. Readers will also find a phased implementation path for building and validating agent systems.

    1. The Shift: From Answering to Getting Things Done

    Over the past two years, the narrative around large models has centered on generation: writing copy, completing code, summarizing documents. Once models are placed into real business workflows, however, users care less about whether the output sounds right and more about whether the task actually gets done. This shift has three direct consequences.

    First, evaluation criteria change. Generation tasks can be approximated with human preference or similarity metrics, but execution tasks must be measured with engineering metrics such as task completion rate, average number of steps, failure rollback rate, and end-to-end latency. Second, system boundaries change. The model is no longer an isolated inference endpoint; it is embedded in a larger system made up of scheduling, permissions, data, and auditing. Third, cost structure changes. Execution pipelines amplify the number of calls and the length of context, so the cost of a single request is no longer predictable. Budgeting and rate limiting become necessary.

    An analogy helps explain this evolution. One type of capability is like electricity: it keeps the entire execution pipeline running, emphasizing low latency, high concurrency, and stable power. The other is like light: it lets people see that the system is moving work forward on their behalf, emphasizing explainability, intervention, and continuity of ideas. Without either one, an agent either cannot run or is not trusted enough to be used.

    2. Reference Architecture: A Five-Layer Breakdown

    A practical agent system should be split into five layers, rather than cramming all logic into a single model call.

    1. Access layer: handles multi-channel sessions, identity recognition, quota validation, and request normalization.
    2. Orchestration layer: handles task decomposition, plan generation, state machine progression, and failure retries.
    3. Capability layer: model inference, retrieval, tool invocation, and code execution sandboxes.
    4. Data layer: session memory, vector indexes, business databases, and object storage.
    5. Governance layer: logs, metrics, tracing, evaluation, permissions, and auditing.

    The orchestration layer is the engineering focus. For long-running workflows, use an explicit state machine instead of implicit free-form conversation, as illustrated below:

    1. class TaskState:
    2. def __init__(self, goal):
    3. self.goal = goal
    4. self.plan = [] # pending steps
    5. self.context = {} # structured intermediate results
    6. self.retry = {} # step -> retry count
    7. def next_step(self):
    8. return self.plan.pop(0) if self.plan else None
    9. def commit(self, step, result):
    10. self.context[step] = result

    The value of an explicit state is recoverability: after a process restart, the context can be rebuilt from persistent storage instead of rerunning everything from scratch.

    3. Key Capability Components

    3.1 Task Planning and Decomposition

    Planning quality sets the upper bound. In practice, use “coarse planning plus fine execution”: the model first produces a high-level plan of three to seven steps, and each step then makes local decisions internally. Plans must be verifiable. For example, each step declares its inputs, outputs, and preconditions, and the executor runs a contract check before invocation to prevent errors from propagating downstream.

    3.2 Tool Invocation and Interface Governance

    Tools are the source of execution power and also the source of risk. Engineering practice requires three things: structured interface descriptions (name, purpose, parameter schema, side-effect level); side-effect classification (read-only, write, irreversible); and mandatory secondary confirmation for irreversible operations. Parameter validation belongs on the executor side, not in the model’s self-discipline.

    1. {
    2. "name": "query_order_status",
    3. "risk": "read_only",
    4. "params": {"order_id": "string"}
    5. }

    3.3 Context and Memory Management

    Context is the scarcest resource. Use three tiers of memory: a short-term window that keeps the most recent turns; working memory that stores intermediate task state in structured fields; and long-term memory that relies on retrieval, recalling by relevance rather than injecting everything. Also apply compression and summarization to fold long histories into conclusion-style descriptions, which can significantly reduce latency and cost.

    3.4 Retrieval and Knowledge Access

    Knowledge tasks should prioritize retrieval over parametric memory. The key points are chunking strategy, hybrid recall (keyword and semantic), reranking, and citation traceability. Answers without traceability are unusable in execution scenarios because they cannot be verified.

    3.5 Sandboxes and Code Execution

    When computation or code generation is involved, execute in isolated containers with restricted network egress, file system access, and runtime duration. Route output through a unified structured result channel.

    4. Engineering Constraints for Stability

    • Idempotency: all write operations carry a business idempotency key, so retries do not produce duplicate side effects.
    • Timeout and circuit breaking: apply dual thresholds for per-step timeout and overall budget. When the budget is exceeded, degrade to “provide suggestions” instead of continuing execution.
    • Rollback compensation: design compensating actions for multi-step workflows and undo them in reverse order on failure.
    • Canary and shadow runs: a new version first runs in shadow mode, recording only without committing changes. Compare completion rates before increasing traffic.

    5. Evaluation and Observability

    An execution system must establish an offline evaluation set and an online monitoring loop. On the offline side, maintain a set of typical tasks with annotated expected results, and track completion rate and step count during regression. On the online side, collect each step’s input summary, tool return codes, elapsed time, and failure reasons to form trace links. Metrics should include at least task success rate, average steps, tool failure rate, end-to-end latency percentiles, and cost per task.

    6. Security, Permissions, and Compliance

    Least privilege is the baseline: credentials used by the agent are issued temporarily within the task scope, with read-only preferred; sensitive data is masked before entering the model; the full pipeline is logged and supports session replay. Set human gates for high-risk actions and include confirmation records in the audit trail.

    7. Infrastructure and Implementation Path

    On the infrastructure side, general cloud product categories can support the needs of each layer: container platforms host sandboxes and inference services, object storage holds sessions and artifacts, message queues decouple asynchronous tasks, logging services and monitoring alerts support observability, and key management capabilities host credentials. The capabilities that Baidu AI Cloud provides in these general categories can serve as a resource foundation for building similar systems.

    Proceed in four phases: start with read-only question answering and retrieval to validate knowledge quality; then connect a small number of read-only tools to validate planning and parameter validation; next, open write actions that require confirmation; finally, gradually enable low-risk automation while using the evaluation set as a gatekeeper.

    8. Conclusion

    Moving from generation to execution is essentially about containing model capabilities within an engineering framework: use state machines to manage workflows, contracts to manage tools, budgets to manage cost, and evaluation and auditing to manage risk. When the “electricity” is stable enough and the “light” is clear enough, agents truly move from demonstration to production.