What Is an AI Agent? Principles and Engineering Practices

    This article explains what an AI Agent is and how it differs from a single LLM call: it runs a closed loop of reasoning, planning, and acting, observes the results, and feeds them back into the next decision. It breaks down the core components (reasoning core, tool layer, memory layer, and orchestration layer), explains why a hybrid architecture with the LLM as the central decision-maker is preferred, compares common architecture patterns, and lists key engineering practices such as observability, convergence controls, evaluation, least privilege, and context engineering, along with common pitfalls to avoid.

    1. From Answering to Acting: What an AI Agent Is

    If a large language model (LLM) is the “brain” of artificial intelligence, an AI Agent is the complete action system built around that brain: it uses the LLM to reason, make plans, and take action, then observes the results and adjusts its next move. Three keywords in this definition are worth unpacking.

    • Reasoning: Breaking a vague user goal into intermediate conclusions that can be evaluated, and deciding “what to do now.”
    • Planning: Decomposing the goal into ordered subtasks, handling dependencies, branches, and fallback paths.
    • Acting: Actually changing the state of the environment by invoking external capabilities (retrieval, computation, writing files, sending requests, operating interfaces, and so on).

    Compared with the traditional “one question, one answer” model call, the essential difference is the closed loop. A single call is open-loop: input goes in, output comes out, and the model is not accountable for the result. An Agent is closed-loop: an action produces side effects, the side effects are observed, and the observation is written back into the context as the basis for the next decision. In engineering terms, this loop is usually implemented as a cycle:

    1. # Illustrative pseudocode: the Agent main loop
    2. messages = [system_prompt, user_goal]
    3. while not done and step < MAX_STEPS:
    4. decision = llm.invoke(messages, tools=tool_schema) # reasoning + planning
    5. if decision.type == "tool_call":
    6. result = dispatch(decision.tool, decision.args) # acting
    7. messages.append(tool_result(result)) # observation written back to context
    8. else:
    9. done = True
    10. messages.append(decision.content)

    This loop looks simple, but the complexity of a real system lies almost entirely “outside the loop”: how context is organized, how tools are described, how failures converge, and how cost is controlled.

    2. Core Components: What an Agent Is Made Of

    2.1 Reasoning Core

    The LLM handles semantic understanding, intent clarification, and strategy selection. It is stateless, has no memory, and cannot execute anything on its own; all “autonomy” comes from external engineering constraints. As a result, the prompt (especially the system prompt) effectively serves as program configuration: role boundaries, the list of available capabilities, prohibited behaviors, and output format conventions should all be stated explicitly.

    2.2 Tool Layer (Tool Use)

    Tools are the Agent’s interface to the real world. Three principles should guide their design:

    • The description is the contract: Tool names and parameter descriptions must let the model unambiguously determine “when to use it and how,” because ambiguity leads directly to wrong calls.
    • Moderate granularity: Tools that are too coarse (such as “handle this order”) are hard to observe and cannot be rolled back; tools that are too fine cause the number of planning steps to explode.
    • Idempotence and rollback: Write operations should be designed to be retryable and reversible as much as possible, avoiding half-completed states that pollute subsequent reasoning.
    1. {
    2. "name": "query_metrics",
    3. "description": "Query the average monitoring metric for a service over a time range; the range is a closed interval in minutes",
    4. "parameters": {
    5. "service": {"type": "string"},
    6. "start": {"type": "integer"},
    7. "end": {"type": "integer"}
    8. }
    9. }

    2.3 Memory Layer

    Memory is usually divided into three types: short-term memory is the current context window; working memory is structured task state (a to-do list, conclusions reached so far, a variable table); and long-term memory relies on vector retrieval or a database to store user preferences and past conclusions across sessions. The key engineering judgment is: do not stuff everything into the context. Context is both a cost center and an attention bottleneck; irrelevant content significantly dilutes how well the model follows key constraints.

    2.4 Orchestration Layer

    This layer handles loop control, concurrent scheduling, timeouts and retries, and human intervention points. A mature practice is to hard-code the “process skeleton” and leave only “local decisions” to the model, rather than letting the model freely decide the entire process topology—the latter is hard to test and hard to debug when failures occur.

    3. Why the LLM Must Be the Central Hub

    Traditional workflow engines excel at deterministic processes, but when facing natural-language goals, the very first step—mapping intent to parameters—cannot be exhaustively covered by rules. The value of the LLM is turning this fuzzy mapping into executable candidate solutions; the value of a traditional engine is guaranteeing that execution stays within bounds. The form widely accepted in the industry today is therefore a hybrid architecture: the model handles selection and generation, while code handles validation and execution. All tool call parameters should pass schema validation and business validation; when validation fails, the error message should be fed back to the model for self-correction rather than thrown out to terminate the run.

    4. Common Architecture Patterns and How to Choose

    • Single agent + tools: Suitable for tasks with clear goals and a countable number of steps. It has the lowest debugging cost and should be the default starting point.
    • Separation of planning and execution: Produce a structured plan first, then execute it step by step, which makes mid-course review and loss cutting easier.
    • Multi-agent collaboration: Split into roles such as research, coding, and review, cross-checking through message passing. It suits long-chain tasks but multiplies context and call costs, and errors propagate and amplify across roles.
    • Human in the loop (HITL): Add confirmation checkpoints for high-risk write operations. This is a necessary design in production, not an optional one.

    5. Key Engineering Practices

    1. Observability first: Fully record the input, tool parameters, return values, and latency of every step, and combine them with logging services and monitoring alerts to pinpoint “which step went off track.” An Agent without trace-level tracking cannot be operated.
    2. Convergence design: Set a maximum number of steps, timeouts, repeated-call detection, and budget caps to ensure the system always stops.
    3. Evaluation first: Build an offline evaluation set containing typical tasks and adversarial samples, and track three dimensions: task success rate, average number of steps, and cost per task. Regression testing before and after changes is mandatory.
    4. Least privilege: Grant tool credentials scoped to the task, separate write operations from read operations, and keep audit records for sensitive actions.
    5. Context engineering: Rerank and trim retrieval results, place key constraints in the system prompt and restate them at the end, and reduce instruction drift in long contexts.

    6. Common Pitfalls

    The first is treating an Agent as “a longer prompt” while ignoring state management and failure recovery. The second is letting the number of tools grow without limit, which lowers selection accuracy. The third is lacking a deterministic fallback, so the whole system stalls as soon as the model hesitates. The fourth is looking only at demo results and not at the cost curve, since call volume for long-chain tasks often exceeds expectations. The standard for judging whether an Agent is mature is not how many tricks it can demo, but whether it remains predictable, stoppable, and accountable under abnormal input.

    In the general capability systems of cloud platforms such as Baidu AI Cloud, categories like model services, object storage, message queues, container platforms, and logging and monitoring can be combined into the foundation that carries the architecture described above, but whether the architecture succeeds still depends on how solid the tool contract design and evaluation system are.