AI Agent Architecture: Components and Data Flow

A language model can generate text and tool-call requests, but that alone is not an AI agent. An agent is a system around the model: it accepts a goal, supplies instructions and context, tracks state, chooses actions, observes results, and decides when to stop.
Architecture matters because each of those responsibilities needs an owner. If memory, permissions, state updates, and stopping rules are left implicit, a capable model can still produce an unreliable system.
This explainer builds a modern AI-agent architecture from first principles and follows data through one complete execution loop.
TL;DR
- The model is the reasoning engine; the agent is the complete goal-directed system.
- Instructions, context, state, and memory influence decisions but serve different purposes.
- Tools let the agent affect or inspect an environment; observations report what actually happened.
- The application should own permissions, durable state, limits, and stopping conditions.
- Architecture defines components and boundaries. A workflow defines how those components execute for a task.
The complete architecture
A modern agent combines model judgment with application-managed context, state, memory, tools, guardrails, and an explicit execution loop.
The diagram separates the agent into three layers:
- Decision layer: the model interprets the goal, reasons, plans, and proposes an action.
- Execution layer: tools or APIs perform work in an external environment.
- Control layer: the application manages state, memory access, permissions, validation, retries, and stopping.
These layers may run in one process or across many services. The logical boundaries matter more than the deployment shape.
Goal or user input
An agent begins with a desired outcome: “Find the cause of this invoice mismatch and prepare a correction for approval.” The goal defines success, while the user input supplies details and constraints.
A vague request is not automatically a safe goal. The application may need to establish scope, identity, deadlines, allowed systems, and approval requirements before the first model call.
The goal should be represented in [agent state](/glossary/agent-state/) so later steps can compare progress against it. Otherwise, a long-running agent may keep taking locally reasonable actions without moving toward the original outcome.
Agent instructions
[Agent instructions](/glossary/agent-instructions/) define the agent’s role, operating rules, available capabilities, response contract, and boundaries. They might say:
- investigate using read-only tools first;
- never issue a refund without approval;
- preserve invoice IDs exactly;
- cite the evidence used;
- stop after two unsuccessful retrieval attempts.
Instructions are trusted control input. Retrieved documents, tool results, and user-provided files are data, even if they contain text that looks like an instruction. Keeping that boundary explicit reduces prompt-injection risk.
Instructions guide the model, but code must enforce critical permissions and limits. A sentence saying “do not transfer money” is not a substitute for a tool permission that makes transfer impossible.
LLM or reasoning engine
The LLM interprets the goal and available context, evaluates alternatives, and produces a response or structured action request. Reasoning-capable models can adapt when observations differ from expectations.
The model does not directly change the outside world. It emits tokens. The surrounding runtime parses a tool call, validates it, invokes the tool, and returns the result.
This is the clearest distinction between a model and an [AI agent](/glossary/ai-agent/):
- Model: performs inference over supplied input.
- Agent: manages a goal-directed cycle of inference, action, observation, state change, and stopping.
A model can be replaced without redesigning every component, provided the new model satisfies the tool, context, and output contracts.
Context
Context is the information available to the model for the current inference. It can include:
- the current goal and instructions;
- recent conversation;
- selected state fields;
- retrieved memories;
- tool definitions;
- recent observations;
- relevant documents.
Context is temporary and bounded by the model’s context window. The system decides what to include, summarize, retrieve, or omit. More context is not automatically better: irrelevant history increases token cost and can distract the model from the evidence that matters.
State
State is the current operational snapshot of the run. For an invoice investigation, it might contain:
- case ID and active user;
- current step;
- invoice and purchase-order identifiers;
- tools already called;
- candidate discrepancy;
- approvals received;
- retry count;
- pending action;
- completion status.
State should be structured and application-managed. The model can propose updates, but the runtime should validate and commit them.
State answers “Where is this run now?” Memory answers “What information from the past may be useful?” They can use the same database without becoming the same concept.
Memory
[Memory](/memory-in-ai-agents/) preserves information beyond the immediate model call. It may include conversation summaries, user preferences, prior task outcomes, reusable facts, or learned procedures.
Memory needs a lifecycle:
- decide what is worth storing;
- record it with provenance and scope;
- retrieve it when relevant;
- update or forget it when it becomes stale.
The complete memory store should not be placed into every prompt. Relevant memories are selected into context. This is why context and memory are related but distinct.
Reasoning and planning
Reasoning evaluates the current situation: what the input means, what evidence is missing, and which option best satisfies the goal. [Planning](/glossary/planning/) organizes future work into steps, dependencies, checkpoints, or subgoals.
An agent may reason without producing a long-lived plan. A one-step lookup needs only a decision. A multi-system reconciliation may benefit from an explicit plan that can be inspected and revised.
Planning is therefore one possible output of reasoning, not a synonym for it. The plan belongs in state if later steps need to track it.
Tool selection, tools, and actions
The model may choose among declared tools such as:
get_invoicegetpurchaseordercomparelineitemsdraft_correctionrequesthumanapproval
A tool is a capability with a defined input and output contract. An action is a particular invocation: calling get_invoice with invoice ID INV-2048.
The runtime should validate arguments, inject trusted identity, enforce permissions, set timeouts, and convert the result into a typed observation. The model should not be able to expand its own tool permissions by changing an argument.
Read [Tool Use in AI Agents](/tool-use-in-ai-agents/) for the complete tool-use boundary.
Environment and observations
The environment is everything outside the agent’s decision process: databases, applications, files, browsers, users, and physical or simulated systems.
An observation is evidence returned after an action. It may contain data, success, failure, an error code, or a human decision. An observation is not the model’s expectation of what happened.
That distinction prevents a serious failure mode: treating a proposed action as completed. The runtime should update state only from confirmed results.
For example:
- Proposed action: “Submit the correction.”
- Tool observation: “Rejected: approval token missing.”
- State update:
correction_status = blocked, notsubmitted.
Guardrails
A [guardrail](/glossary/guardrail/) is a control that restricts or validates behavior. Useful guardrails can operate at multiple points:
- validate the incoming request;
- restrict tool availability;
- inspect tool arguments;
- filter data by permission;
- require human approval;
- validate outputs and citations;
- stop the run when risk or cost exceeds a threshold.
No single prompt-level rule is sufficient. Strong architectures combine instructions, deterministic checks, least-privilege tools, structured outputs, monitoring, and human control where consequences are significant.
The execution loop

The environment changes at the action step. Observations and state updates determine whether the agent repeats or finishes.
The [agent loop](/glossary/agent-loop/) works as follows:
- Goal: establish the active objective and constraints.
- Reason: assess state, context, and missing information.
- Decide: select the next action or final answer.
- Act: execute an allowed tool or produce an output.
- Observe: capture the actual result.
- Update: commit validated state changes.
- Repeat or finish: continue only when another step is useful and allowed.
The ReAct research pattern formalized the value of interleaving reasoning and actions with observations from an environment. Production systems usually add stronger application controls around that conceptual loop.
Stopping conditions
A [stopping condition](/glossary/stopping-condition/) tells the runtime when the run must end. Completion is one condition, but not the only one.
Common stopping conditions include:
- goal satisfied and output validated;
- user input or approval required;
- evidence is insufficient;
- no permitted action can make progress;
- maximum steps, time, tokens, or cost reached;
- repeated failure indicates a blocked path;
- guardrail or policy prevents continuation.
Stopping should be enforced outside the model. The model can recommend finishing, but the runtime owns hard limits.
Architecture vs workflow
Architecture describes stable responsibilities and boundaries: model, state store, memory, tools, guardrails, and runtime.
A workflow describes a task-specific execution path through those capabilities. The same architecture can support a support agent, research agent, and reconciliation agent with different workflows.
An architecture without a workflow is a set of components. A workflow without sound architecture often hides state, permissions, and failure behavior inside prompts.
Common architectural mistakes
Treating conversation history as state
Free-form messages are difficult to validate and query. Store critical status, identifiers, counters, and approvals in structured state.
Treating every past message as memory
Unfiltered history increases cost and noise. Write memories selectively and retrieve them by relevance and scope.
Letting the model execute tools directly
Put a controlled runtime between the model and the environment. Validate schemas, identity, permissions, and results.
Updating state from intention
Commit changes from confirmed observations, not from what the model said it planned to do.
Using only a “task complete” stop
Blocked and unsafe runs also need terminal outcomes. Add limits, escalation, and insufficient-evidence states.
Adding multiple agents too early
A single agent with clear tools and structured state is easier to evaluate. Add specialized agents only when role separation creates measurable value.
Practical example: resolving an invoice mismatch
The user goal enters state with invoice ID, account, and approval rules. Instructions require read-only investigation. The model reasons that it needs both invoice and purchase-order data, then selects the corresponding tools.
The runtime validates the IDs and user scope. Tool observations show a quantity mismatch on one line. State records the evidence and unresolved status. The model plans a correction, but the guardrail exposes only draftcorrection, not submitcorrection.
The draft is generated and sent to a human approval step. If approved, a separate permitted action submits it. If rejected, the observation updates state and the agent finishes with the decision and evidence.
This example shows why the architecture is useful: reasoning remains flexible, while permissions, state, evidence, and consequential actions remain controlled.
My take
The most reliable agent architecture makes model judgment narrow and valuable. Let the model interpret ambiguity, select among permitted actions, and adapt to observations. Keep durable truth, access control, side effects, limits, and validation in deterministic application components.
The question is not “How autonomous can this model be?” It is “Which decisions benefit from model judgment, and which responsibilities must remain explicit and enforceable?”
Sources
- A Practical Guide to Building AI Agents covers models, tools, instructions, orchestration, and guardrails as agent design foundations.
- Building Effective Agents distinguishes predefined workflows from systems where models dynamically direct their own processes.
- ReAct: Synergizing Reasoning and Acting in Language Models describes interleaving reasoning, actions, and observations.
Continue learning
Use [Anatomy of an AI Agent](/anatomy-of-an-ai-agent/) for the foundation, then study [How AI Agents Work](/how-ai-agents-work/) to deepen the execution-loop model.