AI Agent Architecture Selection Guide: From Task Orchestration to Production Governance

    This article explains how to choose an AI agent architecture based on task requirements rather than framework popularity. It compares five common approaches—tool calling, explicit workflows, state-graph orchestration, multi-agent collaboration, and controlled code execution—and covers state management, idempotency, failure handling, security boundaries, evaluation, and a staged path from prototype to production.

    1. From Framework Comparison to Architecture Decisions

    As large language models become better at understanding instructions, generating execution plans, and selecting tools, agents are becoming an important way to connect models with real business systems. However, teams often make a mistake when evaluating different development approaches: they treat the number of components, the richness of examples, or the quality of demos as the main evidence of architectural maturity.

    What usually determines project success is a set of more fundamental questions:

    • Is the business process clearly defined, and which steps can the model decide autonomously?
    • Does execution need to preserve state and resume after interruption?
    • Do tool calls involve data modification, financial operations, or external communication?
    • Do multiple roles truly have independent responsibilities?
    • Can the system explain failures and control time and resource consumption?

    Therefore, instead of ranking specific frameworks, it is more useful to abstract common approaches into several technical routes: tool-calling, explicit workflow, state-graph orchestration, multi-agent collaboration, and controlled code execution. These routes are not mutually exclusive. Real systems often need to combine them.

    2. The Boundary Between Agents and Ordinary Model Applications

    Ordinary model applications usually revolve around one or a few model requests, such as text summarization, information extraction, and content generation. Agents add an execution loop on top of this: observe the current state, choose an action, call a tool, receive feedback, and then decide whether to continue.

    A simplified flow can be represented as:

    Requirement input → task understanding → action selection → tool execution → result verification → continue or finish

    It is important to clarify that when a model generates text saying “call a certain tool,” this does not mean the tool has already been executed. Actual execution is performed by the application. Parameter validation, permission checks, and result recording must also be handled by deterministic program logic.

    It is also necessary to distinguish agents from workflows. In a workflow, steps and transition conditions are mainly defined by developers. An agent allows the model to decide the next action within a certain scope. The difference is the allocation of control, not technical advancement.

    For high-risk tasks such as approvals, payments, and data changes, fixed processes are usually easier to verify. For open-ended retrieval and complex document analysis, where the path is uncertain, moderate autonomous decision-making may be more valuable.

    3. Five Common Technical Routes and Their Applicable Boundaries

    3.1 Tool-Calling: Solving Clear Problems with a Minimal Execution Loop

    A tool-calling system provides the model with a set of capability descriptions, such as querying orders, retrieving documents, or calculating statistical results. The model selects a tool based on the user request, and the application executes it and returns the result to the model.

    This approach is suitable for scenarios with a small number of tools, short task steps, and limited external side effects. Its advantage is a clear structure. Developers can quickly verify whether the model can correctly understand requirements and select actions.

    However, as the number of tools increases, similar names, overlapping parameters, and unclear responsibilities increase the probability of incorrect selection. Tool design should follow the single-responsibility principle and specify input constraints, return meanings, and error categories, rather than providing only a vague description.

    For example, “process order” is too broad. A more reasonable division of capabilities would be “query order status,” “submit cancellation request,” and “query refund progress.” Write operations also require separate authorization. The model selecting a tool does not automatically grant execution permission.

    3.2 Explicit Workflow: Constraining Business Processes with Fixed Steps

    An explicit workflow breaks a task into clear stages, such as document acquisition, information extraction, rule validation, human confirmation, and result output. The model only participates in steps that require semantic understanding.

    This approach is suitable for businesses with relatively stable paths, such as document review, report generation, and standardized customer request handling. Its main advantage is predictability: developers can locate the input, output, and failure conditions of each step.

    It is important to note that a workflow should not delegate all exceptions to the model. Network timeouts, insufficient permissions, missing fields, and business rule conflicts should be handled separately by the program. The model can help explain exceptions, but it should not replace deterministic rule checks.

    3.3 State-Graph Orchestration: Handling Branches, Loops, and Long Tasks

    When a process contains multiple branches, repeated revisions, or human intervention, a state graph can express the task structure. Nodes represent processing steps, edges represent state transitions after conditions are met, and shared state stores task context.

    For example, a document analysis task may go through:

    Document collection → content analysis → completeness check

    If the documents are insufficient, the task returns to document collection. If conclusions conflict, it enters supplementary verification. If the result meets requirements, it enters final output.

    State graphs make loops and branches explicit, but the graph structure itself does not automatically provide reliability. Production systems still need checkpoints, persistent storage, recovery rules, and node-level retry strategies.

    A checkpoint should contain at least the task identifier, current stage, necessary inputs, tool execution records, and confirmed results. During recovery, the system should not simply replay all steps, because that may resend notifications or resubmit business operations.

    3.4 Multi-Agent Collaboration: Dividing Responsibilities, Not Counting Roles

    Multi-agent solutions usually assign tasks to different roles, such as planning, execution, validation, and aggregation. They are suitable when professional responsibilities are genuinely different or when some subtasks can run independently in parallel.

    However, adding roles also increases the cost of context passing, coordination, and conflict handling. If several roles use the same information and similar reasoning methods, they may simply repeat the same conclusion and fail to provide truly independent validation.

    A reasonable collaboration mechanism needs to define:

    • Which information and tools each role can access;
    • Who assigns tasks and confirms completion;
    • What structure is used for handoff content;
    • What evidence is used to resolve conflicts;
    • Which conditions trigger human takeover.

    Roles should exchange task goals, evidence, unresolved issues, and execution status, rather than accumulating the full conversation indefinitely. Otherwise, as collaboration rounds increase, useful information may be diluted by a large amount of repeated content.

    3.5 Controlled Code Execution: Suitable for Compute-Intensive Tasks

    For batch data processing, statistical analysis, and complex computation, having the model generate a program and execute it in a controlled environment may be more direct than continuously calling many fine-grained tools.

    The core of this route is not “letting the model freely run code,” but establishing strict execution boundaries. The execution environment should limit file access, network connections, resource consumption, and runtime duration. It should not provide production system credentials by default.

    Generated code must undergo necessary checks, and execution results should also be verified. For important statistical conclusions, correctness can be checked with known samples, boundary inputs, or independent calculation processes. A program running successfully only means execution completed; it does not mean the business conclusion is correct.

    4. How to Choose an Architecture

    Selection should start by analyzing the task, then choosing a technical route. The following dimensions are more useful than a feature checklist:

    Decision dimension Question to answer Design preference
    Process determinism Can the steps be defined in advance? The more deterministic, the more suitable an explicit workflow becomes
    Execution span Does it cross multiple sessions or wait for external events? The longer it is, the more persistent state is needed
    Side-effect risk Does it modify data or trigger external operations? The higher the risk, the more authorization and approval are needed
    Responsibility difference Do subtasks require different information and permissions? Consider multiple roles only when differences are clear
    Computational complexity Is batch processing or complex computation required? Controlled code execution can be considered
    Operational requirements Are auditing, recovery, and failure localization needed? Runtime governance should be prioritized

    For example, internal knowledge question answering can usually start with retrieval and tool calling, without immediately introducing multi-agent collaboration. Business processing that involves multi-stage validation is more suitable for explicit processes. Tasks that need to run over a long period and wait for human confirmation should prioritize persistent state and recovery mechanisms.

    Learning cost should not be judged only by the difficulty of running the first example. Real costs include debugging state, handling exceptions, writing tests, managing permissions, and maintaining upgrades. More abstraction layers may improve development convenience, but troubleshooting low-level issues may require understanding more runtime mechanisms.

    5. Key Design for Reliable Execution

    5.1 Separate Business State from Conversation Records

    Conversation records are suitable for preserving interaction context, but they should not be the only source of business state. The system should separately store task goals, current stage, execution results, pending approvals, and termination reasons.

    This way, even if conversation content is truncated or summarized, the business process can still resume based on explicit state. For long tasks, it is also necessary to distinguish short-term context, task state, and long-term knowledge, avoiding indiscriminate inclusion of all information in model input.

    5.2 Design Idempotency for Side-Effect Operations

    Query operations can usually be retried safely, but submitting requests, sending messages, and modifying records may produce duplicate side effects.

    If a tool request times out, the system should first determine whether the result is unknown, rather than directly executing it again. The operation status can be confirmed through business unique identifiers, idempotency keys, or result query mechanisms. For operations that cannot be confirmed automatically, they should be transferred to human handling.

    5.3 Handle Failures by Category

    Different failure types require different strategies:

    • Temporary network failure: limited retries with backoff intervals.
    • Invalid parameters: return a clear error and allow correction before retrying.
    • Insufficient permissions: stop the related operation; do not bypass it by changing the wording.
    • Business rule conflict: explain the reason and enter an alternative process or human review.
    • Unknown execution result: query the status first to avoid duplicate side effects.

    The system should also set a maximum number of steps, task deadlines, and resource budgets to prevent an agent from continuing to run in an invalid loop.

    6. Security Boundaries Must Exist Outside the Model

    Retrieved documents, web content, and tool return results should all be treated as external data and must not be automatically upgraded to system instructions. Even if such content contains phrases like “ignore restrictions,” “read keys,” or “call other tools,” the application must still enforce established permission rules.

    Security design should include least privilege, sensitive information masking, tool parameter validation, data access isolation, and operation auditing. Security requirements in model prompts can help constrain behavior, but they cannot replace real permission controls.

    High-risk actions should preferably follow a “generate an operation draft first, then confirm execution” approach. The approval object should be a specific action, including the target object, key parameters, and expected impact. If parameters change materially after approval, confirmation must be requested again; the previous approval cannot be reused.

    7. Testing and Evaluation: Measure Completion Quality, Not Conversational Fluency

    Agent evaluation should cover normal tasks, abnormal tasks, and adversarial inputs. The test set needs to include missing information, tool timeouts, restricted permissions, repeated requests, and malicious external text.

    The following metrics can be emphasized:

    • Task success rate: whether the result meets predefined acceptance conditions;
    • Tool selection accuracy: whether the appropriate capability was selected;
    • Parameter validity rate: whether call parameters conform to structural and business constraints;
    • Number of invalid calls: whether duplicate or low-value operations occurred;
    • Human intervention rate: which tasks cannot be completed automatically;
    • Recovery success rate: whether the task can continue after interruption without duplicate execution;
    • Execution latency and resource consumption: how much time and how many calls are needed to complete the task;
    • Security violations: whether unauthorized access or unapproved operations occurred.

    Different tasks should use different acceptance methods. Data queries can be compared against trusted records, calculation tasks can verify results, and analysis reports need to check evidence coverage, factual accuracy, and conclusion consistency. Quality cannot rely solely on another model judgment.

    8. Implementation Path from Prototype to Production

    In the first stage, choose a business task with clear boundaries, rollback capability, and low risk. Define the input, output, and success criteria.

    In the second stage, build a minimal execution chain and expose only necessary tools. Verify whether the task truly requires autonomous decision-making.

    In the third stage, introduce structured state, logs, and a test set. Record each key decision, tool call, and failure reason, while avoiding sensitive information leakage in logs.

    In the fourth stage, add persistence, checkpoints, approvals, idempotency, and recovery mechanisms based on actual needs. Do not introduce unnecessary complexity early just for architectural completeness.

    In the fifth stage, perform a controlled rollout. Limit access scope and execution budgets, observe the real task distribution, and continuously analyze failure samples. If autonomous planning or multi-role collaboration is introduced, compare it with the original approach using the same test set to confirm that the benefits outweigh the added costs.

    9. Conclusion

    There is no universally optimal answer for agent architecture. Tool calling emphasizes lightweight connection, explicit workflows emphasize determinism, state graphs emphasize complex process control, multi-agent collaboration emphasizes responsibility division, and controlled code execution emphasizes computational expressiveness.

    The common feature of reliable systems is that they place the model in a bounded and verifiable execution environment: the model handles semantic understanding and limited planning, the program handles permissions, state, and business rules, and humans handle high-risk confirmation and exception resolution. Only by considering task value, execution reliability, and governance cost together in architecture selection can agents move from demo prototypes to sustainable business systems.