Agent Architectures
A fixed workflow is enough when every step and branch can be specified before execution. An agent becomes useful when the next operation depends on information that is not yet available: a test result, a search result, a user decision, or a changed environment. Its architecture is the closed decision loop that turns those observations into the next bounded action.
That loop needs more than a model and a list of tools. It needs a controller, an assembled context, an action interface, an environment, a state transition, and a termination rule. Tool calling is one action interface; executable code, graphical-interface operations, messages, and environment-native commands are others. Planning and memory are choices within the loop, not a universal list of boxes from which every agent must be built.
Two influential 2023 systems established parts of this design space. ReAct interleaved explicit verbal reasoning with task-specific actions so that later decisions could use new observations (Yao et al. 2023). Toolformer generated, executed, and filtered candidate calls to five fixed APIs, then fine-tuned a model on the retained calls (Schick et al. 2023). They showed that models can learn and use action interfaces, but neither paper defines the only valid agent architecture.
One turn is a state transition
At turn , the runtime constructs a model input, the controller proposes a decision, and the runtime updates durable state:
Here, is the turn index; is the task goal; contains user instructions and constraints; is the durable session state before the turn; is the set of action specifications exposed on that turn; is the remaining token, action, time, and cost budget record; and is the context assembler. Its output is the bounded input sent to the controller. The controller , with parameters , samples output ; decoder parses that output into decision . The updater combines the old state, the decision, and observation to produce the next state . Every symbol in the equations refers to a runtime object that can be logged and tested.
The parsed decision must have an explicit type. A useful minimum is
Here, is a requested action or an explicit action batch; is a question for the user, is a proposed final response, and is a structured stop reason. An action can produce a tool result, an execution error, or a policy denial as . A user reply can also become an observation. A final response leaves the loop only after its completion condition passes. A stop reason records success, terminal failure, cancellation, budget exhaustion, or another declared termination condition.
The state and the model context are not the same object. The state may contain a full event log, approval records, handles to external resources, and data that should never enter a prompt. The context is a selected and formatted view of that state. Keeping the two separate makes redaction, summarization, replay, and model changes possible without rewriting the session record.
ReAct is one way to instantiate the controller in Figure 38.2. It places visible verbal reasoning between actions (Yao et al. 2023). The general loop does not require such a trace. A model may reason internally, an external planner may supply a plan, or a deterministic workflow may choose some transitions. What must remain observable is the decision record: selected branch, action arguments, observation provenance, approval result, budgets consumed, and completion evidence.
Architecture is a set of contracts
The familiar labels planning, memory, and tool use are useful topics, but they mix policy, state, and interface concerns. A production architecture is clearer when each runtime role has a contract:
| Role | Contract | Failure if omitted |
|---|---|---|
| Controller | Propose one typed decision from the assembled context. | Free-form output is mistaken for an executable command. |
| Context assembler | Select, order, label, and bound the model input. | Durable state is confused with whatever happens to fit in one prompt. |
| State store and updater | Preserve events and derive the next working state. | A retry loses history or applies an observation twice. |
| Action catalog | Define available operations, argument schemas, side effects, and result schemas. | The controller cannot distinguish legal operations from plausible text. |
| Reference monitor | Validate, authorize, request approval, and enforce budgets. | Model output bypasses the product's authority boundary. |
| Dispatcher and environment | Execute allowed actions and return normalized observations with status and provenance. | Timeouts and partial failures are mistaken for task results. |
| Completion checker | Test the requested end state independently of the controller's claim. | A confident final response ends an unfinished task. |
| Termination policy | Stop on success, failure, cancellation, or exhausted resources. | The loop wanders, retries forever, or spends without a bound. |
This decomposition also separates architecture from harness implementation. The architecture says that state must survive and actions need a guard. The harness in Chapter 41 supplies queues, leases, retries, checkpoints, and crash recovery that make those contracts durable.
Choose the control pattern from the task
Agent architecture is plural because the controller need not use the same control pattern for every task.
| Pattern | Use it when | Required feedback | Main failure mode |
|---|---|---|---|
| Fixed workflow | Steps and branches are known before execution. | Status at declared checkpoints. | An unencoded case has nowhere to go. |
| Reactive next action | The latest observation determines the next small step. | Observation after nearly every action. | The controller wanders or loses the global objective. |
| Receding-horizon plan | Several future steps help coordination, but the world can change. | Replan after each action or checkpoint. | Replanning cost dominates, or a stale prefix is executed. |
| Plan then execute | Dependencies are predictable and observations rarely change the plan. | Validation at step boundaries. | An early assumption invalidates later steps. |
| Hierarchical planner and executor | High-level decomposition and low-level action selection need different contexts or models. | Subgoal completion and escalation. | Planner and executor disagree about state or success. |
| Evaluator and refiner | A candidate can be checked more cheaply than it can be produced correctly once. | Actionable verifier feedback. | The evaluator rewards superficial changes or refinement never stops. |
| Branching search | Alternatives are cheap to generate and can be compared reliably. | A scorer and an explicit search budget. | Cost grows faster than useful diversity. |
A workflow is usually preferable when it can express the task. It is cheaper, easier to test, and easier to authorize. A model-controlled loop earns its extra cost when it must choose among actions using observations that were unavailable at design time.
Planning is a cadence, not a binary choice
An immutable plan can become stale, but that does not make planning useless. The design question is when a plan is made, how far it reaches, and what causes revision. ReAct demonstrated stepwise adaptation with explicit reasoning and actions (Yao et al. 2023). Reason for Future, Act for Now instead plans a future trajectory, executes the first action, incorporates feedback, and plans again (Liu et al. 2024). Plan-and-Act separates a trained high-level planner from an executor and reports results on long-horizon web tasks (Erdogan et al. 2025). These are different planning cadences, not successive versions of one correct architecture.
A written plan is state, not authority. Each step still passes through current preconditions, permissions, and budgets. Useful replan triggers include a failed precondition, an unexpected observation, a changed user constraint, a denied action, a timeout, a failed completion check, or a remaining-budget threshold. Plans should also record which observations support them; otherwise a summary can preserve the step while dropping the assumption that justified it.
A visible reasoning trace is not required for adaptive control. It can be useful in research systems such as ReAct, but operational inspection should rely on stable artifacts: the plan version, decision type, action arguments, verifier output, and state transition. Reflexion is a specific alternative that turns task feedback into textual reflection stored for later trials (Shinn et al. 2023). It demonstrates one way to update contextual state without updating model weights; it does not make self-critique a general correctness guarantee.
Choose an action representation
An action interface determines what the controller can express and what the runtime can validate. Three common representations make different trades:
| Representation | Strength | Boundary the runtime must enforce |
|---|---|---|
| Structured function call | Explicit operation name and typed arguments support schema validation, per-call approval, and stable logs. | Validate semantics after syntax, authorize the operation and target, and normalize every result and error. |
| Executable code | Loops, variables, filtering, and several operations can be composed inside one action. | Run in a sandbox, mediate every external capability, bound CPU, memory, network, and time, and retain the code plus effects. |
| Environment-native action | Text commands, robot controls, clicks, keystrokes, or messages match the environment directly. | Constrain the legal action set, identify the target state, and verify effects from fresh observations. |
Toolformer concerns how a model learned when and how to call a small fixed set of APIs (Schick et al. 2023). CodeAct concerns a different action representation: executable Python. Across 17 models on API-Bank and M³ToolEval, its authors report up to 20 absolute percentage points higher success than their compared text and JSON formats (Wang et al. 2024). That result is scoped to those models, interfaces, and benchmarks. It does not show that code is always safer or cheaper.
Interface design itself can change agent performance. SWE-agent introduced an agent-computer interface for repository navigation, editing, and testing, then evaluated it on software-engineering tasks (Yang et al. 2024). The broader lesson is not that every agent needs that interface. It is that action names, argument shapes, observation formats, and feedback latency are part of the architecture, not neutral plumbing.
Regardless of representation, the model proposes and a reference monitor decides whether execution is allowed. A side-effecting request needs a stable idempotency key so a transport retry does not repeat a purchase, message, or write. Long-running work needs a durable handle rather than a live connection as its identity. Parallel actions are safe only when their dependencies and effects do not conflict.
Make every branch explicit
The minimal loop is not “call a model until it emits no tool.” No call may mean a final answer, a clarification request, a refusal, malformed output, or a model failure. A safer architectural skeleton is:
state = initialize(task, user_constraints, permissions, budgets)
loop:
stop = check_termination(state)
if stop exists:
return recorded_outcome(stop, state)
context = assemble_context(state)
raw = controller(context)
decision = decode_typed_decision(raw)
if decision is invalid:
state = record_parse_error(state, raw)
continue # bounded by the parse-retry budget
if decision is ask_user:
suspend until reply or cancellation
state = record_user_reply(state, reply)
continue
if decision is final_response:
evidence = verify_completion(state, decision)
if evidence passes:
return recorded_outcome(success, state, evidence)
state = record_failed_completion(state, evidence)
continue
if decision is requested_action:
verdict = validate_authorize_and_budget(decision, state)
if verdict denies:
state = record_observation(state, verdict)
continue
request_id = idempotency_key(session_id, turn_id, decision)
result = execute_with_timeout(decision, request_id)
state = record_observation(state, normalize(result))
This skeleton can ask the user, request an action, return a final response, or stop. Parser errors, authorization denials, timeouts, and tool failures become typed observations rather than exceptions that silently erase a turn. The termination check covers success, failure, cancellation, and budget exhaustion. The harness may implement retries and resumption differently, but it must preserve these outcomes.
Separate autonomy from authority
Autonomy describes who chooses the next operation. Authority describes which operations the system may perform. They are independent axes. A controller can autonomously search a read-only corpus with little authority, while a fixed workflow can have broad authority to deploy software or transfer funds.
This distinction changes architecture reviews. Adding a planner, longer horizon, or dynamic tool discovery may increase autonomy without changing permissions. Mounting a write-capable credential, widening a filesystem scope, or removing an approval gate increases authority even if the control loop stays fixed. Blast radius follows authority, reachability, and reversibility, not an informal label such as “agentic.” Security and authorization controls are developed in Chapter 56; the architecture must expose the decision points at which those controls apply.
Lower-layer constraint: context is a shared budget
The context window must hold instructions, task data, working state, action schemas, and room for output. Its token accounting is
Here, is the total tokens reserved for turn ; covers system and policy instructions; covers the user goal and fixed task data; covers selected session state; covers the mounted action schemas; reserves controller output; and is the model's supported context limit. The set contains actions exposed on turn , and is the serialized token length of action specification . The equality is accounting, not a claim that all allocations have equal value.
Mounting another action therefore has a certain token cost. Its effect on action selection is empirical, not a universal exponential curve or a fixed tool-count threshold. It depends on the model, task, schema similarity, descriptions, and prompt. BFCL evaluates serial and parallel calls, abstention, and stateful multi-turn behavior (Patil et al. 2025). ACEBench adds ambiguous and incomplete instructions plus multi-turn agent scenarios (Chen et al. 2025). These benchmarks expose several failure modes, but they do not establish one catalog size at which every model fails.
Choose among a flat catalog, phase-based mounting, retrieval, or explicit discovery by measuring the actual workload. Measure selection quality with the needed action present, add irrelevant tools and similar schemas, test abstention when no action applies, and report retrieval recall when schemas are selected dynamically. Tool retrieval can save context while also hiding the only action that would solve the task.
There is no general winner between explicit and implicit planning. Explicit plans can improve long-horizon coordination and support review, while reactive control can adapt with less planning overhead. Plan-and-Act provides scoped evidence for a separate planner and executor (Erdogan et al. 2025); ReAct and receding-horizon systems provide scoped evidence for tighter feedback (Yao et al. 2023; Liu et al. 2024). The task distribution, model, verifier, and cost budget determine which result transfers.
Action exposure is also unsettled. A flat catalog is simple and auditable; retrieval or discovery saves context but introduces a recall failure. Structured function calls are easy to gate individually; executable code composes operations but moves more responsibility into the sandbox and reference monitor. These are choices to compare under the same operating envelope, not stages of a universal agent maturity ladder.
Verify the architecture as a system
An architecture comparison must keep the same model checkpoint, same task distribution, same tool implementations, same permissions, and same budgets. Otherwise a stronger model, broader credential, or larger token allowance can be mistaken for a better loop.
| Layer | Measurements |
|---|---|
| Task outcome | Completion rate with confidence intervals; completion by task family and horizon; independent end-state verification; user corrections. |
| Control quality | Invalid-action rate; unnecessary-action rate; replan frequency; recovery rate after denied, failed, or misleading actions; premature-final rate. |
| Safety and authority | Approval frequency; permission-denial rate; unintended side effects; duplicate side effects; operations outside the requested scope. |
| State quality | Replay success; missing or duplicated events; context truncation; observation provenance; dynamic-action retrieval recall. |
| Cost and service | Model calls, input and output tokens, action count, tool and model latency, wall-clock time, and cost per completed task. |
Inspect failures by transition, not only by final score. Determine whether the needed fact never entered context, the controller chose the wrong decision type, the action schema was ambiguous, authorization rejected a valid operation, the environment returned a misleading observation, the state updater dropped it, or the completion checker accepted too early. Each cause belongs to a different contract and requires a different fix.
The architecture now has a precise state boundary, but it has not yet decided what should survive for one turn, one session, or many sessions. That is the subject of Chapter 39.
Further reading
- Yao et al., “ReAct: Synergizing Reasoning and Acting in Language Models” (Interleaves explicit verbal reasoning traces with task-specific actions), 2023. arXiv:2210.03629ReAct interleaves model reasoning with environment actions in experiments on question answering and interactive tasks; it is an agent-loop method, not a framework, runtime, or safety boundary.
- Schick et al., “Toolformer: Language Models Can Teach Themselves to Use Tools” (Learns when and how to invoke five fixed APIs from filtered generated calls), 2023. arXiv:2302.04761Toolformer generates candidate API annotations, executes and filters them by language-model loss, and fine-tunes a model to decide when and how to use five fixed APIs.
- Liu et al., “Reason for Future, Act for Now: A Principled Architecture for Autonomous LLM Agents” (Plans a future trajectory, executes its first action, then replans from feedback), 2024. proceedings.mlr.pressRAFA implements receding-horizon control: it plans over future actions, executes the first one, stores feedback, and plans again from the updated state.
- Erdogan et al., “Plan-and-Act: Improving Planning of Agents for Long-Horizon Tasks” (Separates a trained high-level planner from an environment-specific executor), 2025. proceedings.mlr.pressPlan-and-Act trains a planner to produce high-level plans and uses a separate executor to translate those plans into environment actions on long-horizon web tasks.
- Shinn et al., “Reflexion: Language Agents with Verbal Reinforcement Learning” (Stores textual reflections from task feedback for later trials without updating weights), 2023. proceedings.neurips.ccReflexion turns task feedback into textual reflection kept in episodic memory, changing later decisions through context rather than parameter updates.
- Wang et al., “Executable Code Actions Elicit Better LLM Agents” (Compares executable Python with text and JSON action formats on API-Bank and M3ToolEval), 2024. arXiv:2402.01030CodeAct uses executable Python as an action representation and reports up to 20 absolute percentage points higher success than compared formats across its evaluated models and benchmarks.
- Yang et al., “SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering” (Studies how an agent-computer interface changes behavior on software-engineering tasks), 2024. proceedings.neurips.ccSWE-agent designs a model-facing interface for repository navigation, editing, and testing, showing that the action and observation interface is part of agent performance.
- Patil et al., “The Berkeley Function Calling Leaderboard (BFCL): From Tool Use to Agentic Evaluation of Large Language Models” (Evaluates serial and parallel calls, abstention, and stateful multi-turn behavior), 2025. proceedings.mlr.pressBFCL evaluates function calling across serial, parallel, abstention, and stateful multi-turn settings instead of reducing tool use to one argument-matching score.
Comments
Log in to comment