Why the Same LLM Behaves Differently: An AI Agent Architecture Guide

    The same large language model can behave very differently depending on the agent system built around it. This article breaks an agent down into its core parts—model inference, task orchestration, tool execution, state management, safety controls, and external interaction—and shows how context assembly, tool execution, and the task loop shape actual behavior. It then walks through four general architecture dimensions (a lightweight execution core, shared services, experience memory, and multi-channel access), the engineering foundations every architecture must include (permissions and approvals, untrusted-content isolation, observability, and cost budgets), and a practical way to choose and validate an architecture against real business constraints.

    1. Same Model, Different Agent Behavior

    Connect the same large language model to different application systems and they can work in strikingly different ways. Some handle only the current task; some carry out multi-step operations continuously; some reuse past experience; and some receive requests across multiple communication channels, resume tasks, and return results.

    These differences do not mean the model itself has changed. What changed is the runtime environment around the model.

    The model is mainly responsible for generating output from input. An agent system has to decide further: what context to give the model, which tools it may call, how to persist execution state, when to keep running, and when it must stop and hand off to a human.

    So it helps to think of an agent as a combination of components:

    Agent system = model inference + task orchestration + tool execution + state management + safety controls + external interaction

    This is a conceptual breakdown for architecture, not a scoring formula for capability. A flaw in any single area can limit the final result.

    For example, a model may correctly judge that it should “read the configuration first, then modify the file,” but if the runtime environment grants no read permission, the task still cannot be completed. Conversely, if the system grants excessive permissions, even a model that is right most of the time can cause serious damage with a single wrong action.

    Understanding agent architecture starts with separating “can the model do it” from “can the system do it safely and reliably.”

    2. First, Map the Agent’s Basic Execution Path

    A typical agent task can unfold along this path:

    User request → identity and permission check → context assembly → model decision → tool call → result validation → state update → return result or continue

    The path looks simple, but each step carries its own engineering responsibility.

    2.1 Context Assembly: Deciding What the Model Sees

    Context usually includes the current user request, relevant conversation, task state, retrieved material, tool descriptions, and system constraints.

    More information is not always better. Excessive input raises cost and latency, and can introduce contradictory instructions that lead the model to ignore key conditions.

    A sound approach is to distinguish:

    • Constraints that must be preserved, such as permission boundaries and output requirements;
    • Facts directly relevant to the current task;
    • Historical information that can be retrieved on demand;
    • Execution records meant only for auditing, which need not be sent to the model.

    The goal of context management is not to “keep everything,” but to “provide enough and trustworthy content for the current step.”

    2.2 Tool Execution: Turning Generated Output into Real Actions

    A model proposing a tool call does not mean the call should run immediately. The execution layer still needs to check whether the parameters are valid, whether the target resource is allowed, and whether the operation requires approval.

    A successful tool return does not necessarily mean business success. After a file write completes, for instance, you still need to check that the content meets requirements; after a request is submitted, you may need to wait for downstream results.

    So tool results should, as far as possible, separate execution status, business status, and validation conclusions—avoiding the mistake of treating “the call succeeded” as “the task is done.”

    2.3 The Task Loop: Controlling Continuation, Termination, and Failure

    Agents usually need to run repeatedly through “observe—decide—execute—validate.”

    Without clear stopping rules, a system may keep repeating similar operations and consume large amounts of time and resources. The task loop should set a maximum number of steps, a total time budget, a repeated-failure threshold, and conditions for human takeover.

    These thresholds must be determined through scenario testing; a single set of numbers should not be treated as a universal configuration for all tasks.

    3. Four General Architecture Dimensions, Not Four Mutually Exclusive Products

    You can approach agent design from four dimensions:

    1. Whether the execution core is lightweight;
    2. Whether shared services host multiple clients;
    3. Whether task experience is persisted and reused;
    4. Whether multiple interaction channels are supported.

    These are not strictly mutually exclusive categories. A system can fully combine a lightweight execution core, shared services, long-term memory, and a multi-channel adaptation layer at the same time.

    What really needs comparing is not how many features a framework has, but which capabilities the business needs and whether the team can bear the corresponding complexity.

    4. Lightweight Execution Core: Make the Minimal Loop Reliable First

    A lightweight architecture is usually built around a small number of core components:

    Task input → context building → model call → tool execution → result return

    Its advantages are a short control path and clear dependencies. Developers can easily observe what happens at each step, and it is convenient to modify the task loop and tool strategy.

    For single-task applications with a well-defined scope—analyzing a document, checking a set of files, or generating a structured result—a lightweight core is often easier to build with stable behavioral boundaries.

    4.1 Lightweight Does Not Mean Missing Safety Mechanisms

    Even a system with only a few components still needs:

    • A tool-access allowlist;
    • Input and parameter validation;
    • Timeout and cancellation mechanisms;
    • Call logging and error classification;
    • A confirmation flow for high-risk actions.

    “Lightweight” should mean removing unnecessary abstraction, not removing necessary engineering controls.

    4.2 Put the Unstable Parts at the Boundaries

    Model choice, tool sets, context sources, and persistence methods can all change as the business evolves. Placing these capabilities behind clear component boundaries avoids rewriting the execution core every time something is adjusted.

    But guard against over-engineering, too: a system with only a few fixed tasks has no need to build a massive plugin system in advance.

    4.3 Applicable Conditions and Limitations

    A lightweight architecture suits applications with clear task boundaries, limited concurrency requirements, and operation mainly within a controlled environment.

    When a system needs to support multi-person collaboration, cross-device recovery, and unified permission management, a local task loop alone is usually not enough; you need to add service-oriented and persistence capabilities.

    5. Shared Service Architecture: Let Different Clients Access the Same Task System

    When multiple clients need to use the same agent capabilities, you can place the core execution logic in a shared service, with clients handling input, display, and interaction.

    Its logical structure can be expressed as:

    Multiple clients → authentication and request entry → session and task services → execution nodes → tools and data resources

    This approach helps maintain tool configuration, model strategy, task records, and permission rules in one place, and reduces duplicated implementation of complex logic across clients.

    5.1 Shared Services Do Not Mean Sharing All Session State

    This is the most easily confused boundary.

    Multiple users can share the same service, but they should not share conversation history, access credentials, or business data by default. The system must at least distinguish ownership across users, organizations, sessions, tasks, and resources.

    Every tool call should be checked against the authorization scope of the current task, rather than verifying identity only once at login.

    5.2 Multiple Clients Bring Concurrency and Recovery Problems

    The same task may be viewed from different clients, and duplicate requests may arise from network reconnections.

    So the system needs to consider:

    • How to detect duplicate submissions;
    • Whether the same task allows concurrent modification;
    • Whether execution nodes can promptly sense a task cancellation;
    • Whether background tasks continue after a client disconnects;
    • Whether a task can recover after an execution node fails.

    For important state changes, use persisted task records and version checks to avoid clients or execution nodes each maintaining conflicting state.

    5.3 Long Tasks Should Be Decoupled from the Interactive Connection

    If a task takes a long time, its lifecycle must not depend entirely on a single connection.

    A more robust pattern is to create the task first, have execution nodes process it, and let clients obtain progress through queries or event notifications. This way, even if the page is closed or the network drops, the task is not necessarily lost.

    However, recovery capability depends on persisting task state and necessary intermediate results; it cannot be achieved by reconnecting alone.

    6. Experience Memory: Reuse the Process, but Do Not Store Errors Long-Term

    Task memory can help a system reduce repeated exploration, but “remembering history” is not the same as “having learned a capability.”

    Start by distinguishing three types of information:

    • Session state: which step the current task has reached and what is still missing;
    • Long-term facts: confirmed information suitable for continued use;
    • Process experience: methods, conditions, and validation steps reusable when completing a certain class of task.

    These three types differ in validity period, retrieval method, and access permissions, and should not all be mixed in a single store.

    6.1 Reusable Experience Should Have a Clear Structure

    A piece of process experience should at least state:

    • The applicable task and preconditions;
    • Required permissions and resources;
    • Recommended execution steps;
    • Known failure modes;
    • How results are validated;
    • Source, version, and last-updated time.

    Storing only “it worked last time when we did this” makes it hard to judge whether it applies next time. The same operation can produce completely different results under different environments, permissions, or data versions.

    6.2 Writing Experience Should Go Through Validation

    A sound flow is:

    Task complete → validate result → extract candidate experience → check for sensitive content and applicable conditions → review or rule-based validation → save → retrieve on demand

    Here, model summarization can be used to generate candidate experience, but it cannot automatically prove the experience is correct.

    Validation should rely on observable external evidence where possible, such as check results, user confirmation, or an explicit business status. For experience with a large impact, add human review.

    6.3 Memory Needs Updating and Eviction

    After the environment changes, old experience may become invalid. The system should support revision, revocation, and deletion, rather than only adding and never removing.

    At the same time, memory storage must not become an unbounded collection area for sensitive information. Access credentials, private data, and unnecessary raw content should be handled under a minimization principle; experience should also inherit the access restrictions of its source data.

    7. Multi-Channel Access: The Core Issues Are Semantic and Identity Consistency

    Connecting different interaction channels is not just adding message send/receive interfaces.

    Channels can differ in message format, identity systems, attachment support, notification methods, and interaction duration. If these differences flow directly into the task core, the system accumulates many channel-specific branches, and maintenance difficulty rises quickly.

    A more reasonable structure is:

    Channel entry → adaptation layer → unified message and event model → session routing → agent execution core

    7.1 Use a Unified Event to Isolate Channel Differences

    A unified event can express the sender, session, message identifier, time, content type, attachment reference, and originating channel.

    These fields are internal design examples, not the interface specification of any specific product. In real implementation, define them according to business semantics, and avoid treating one channel’s special rules as the standard for the whole system.

    The adaptation layer converts formats; the core execution layer understands the business. The two responsibilities should be kept separate.

    7.2 Identity Linking Must Go Through Authorization

    The same person’s accounts on different channels should not be deemed the same identity based on display name alone.

    If cross-channel task recovery is needed, provide an explicit account-binding or authorization flow, and re-check whether the target channel is permitted to access the relevant session.

    Otherwise, a convenient cross-channel experience can turn into a path for sensitive-information leakage.

    7.3 Async Messages Must Handle Duplicates and Out-of-Order Delivery

    External messages may be resent or arrive late. The system needs to detect duplicate events and prevent old messages from overwriting newer task state.

    For operations that produce external side effects, use business-layer idempotency. For example, when the same request is received again, return the existing task status rather than executing the same submission again.

    The number of connected channels is only a measure of coverage; it cannot replace an assessment of reliability and security.

    8. The Engineering Foundation Every Architecture Must Complete

    8.1 Permissions and Approvals

    Permissions should be enforced by a deterministic execution layer, not written only in prompt text.

    Reading data, modifying content, sending messages, and deleting resources carry different risks and should be authorized separately. When a high-risk operation requires human confirmation, the confirmation target should include the specific object and operation content; if the content changes, confirmation should be requested again.

    8.2 Untrusted-Content Isolation

    Text in documents, web pages, and external messages should be treated as data to be processed, not as inherently trustworthy system instructions.

    If external content demands expanded permissions, information disclosure, or skipping review, the system should not change its security rules as a result. Constraints in the prompt are helpful but cannot replace access control at the execution layer.

    8.3 Observability

    Run records should be able to link user requests, model decisions, tool calls, and task state changes.

    Key observations include task duration, tool failures, retry counts, cancellations, and reasons for human takeover. Logs should also be redacted, with retention time and access scope limited.

    The purpose of observability is to locate faults and review behavior, not to store all user content indefinitely.

    8.4 Cost and Resource Budgets

    Set budgets for a single task’s inference calls, tool calls, runtime, and resource consumption.

    As the budget limit approaches, the system can ask the user to confirm continuation, save current progress, or present the completed portion and the unresolved issues. Stopping when the budget runs low is easier to manage than unbounded execution.

    9. How to Choose: Work Backward from Business Constraints

    Before choosing, answer five questions:

    1. Is the task single-step processing, or does it need continuous execution and recovery?
    2. Are the users individuals, or multiple organizations and roles?
    3. Is there a need to reuse validated experience over the long term?
    4. Do requests come from one entry point, or from multiple async channels?
    5. What is the cost of a failed operation, and which actions must be approved?

    Then add capabilities step by step according to need:

    • Single task, single entry: prioritize a reliable execution loop;
    • Multi-person, multi-device use: add shared services, identity isolation, and task persistence;
    • Many repeated tasks: add validated experience management;
    • Multiple communication entry points: add an adaptation layer, identity linking, and event deduplication;
    • Important business operations: strengthen permissions, approvals, validation, and auditing.

    This path is not a fixed build order, but a way of thinking that reduces unnecessary complexity.

    10. Finally, Prove Architecture Value with Evaluation

    An architecture diagram can only express design intent; it cannot prove a system works.

    Prepare a test set covering normal tasks, missing information, tool failures, duplicate requests, insufficient permissions, malicious external content, and service interruptions. For multi-step tasks, also test whether errors can be detected and whether recovery re-executes operations that were already completed.

    When evaluating, do not look only at whether the final answer is fluent. Also observe:

    • Whether the task is actually completed;
    • Whether results are effectively validated;
    • Whether permission boundaries are crossed;
    • Whether failures can be explained and recovered;
    • Whether resource consumption stays within budget;
    • Whether the system stops in time when human takeover is needed.

    The value of an agent architecture ultimately shows in predictable, traceable, and controllable behavior.

    The same model can present different capability boundaries because the task loop, state, memory, tools, and channels together shape how it runs. For developers, the most important thing is not to find the solution with the most features, but to choose a design that matches the task’s risk, collaboration scale, and maintenance capacity—then use real tasks to verify whether each added capability is worth keeping.