AI agent architecture explained: the six layers, the agent loop, five design patterns, per-layer failure modes, and the accountability layer most miss.
Most teams get an agent into production before they get an architecture. A model gets a tool, the tool gets a credential, the credential gets a cron job, and six weeks later nobody can say which system just issued a refund. The pattern is common enough that it has a shape, and the shape is an architecture problem.
AI agent architecture is the design of that system: the layers that turn a language model into something that can perceive a situation, decide what to do, act on real systems, remember what happened, and be held to account for it. This guide covers the six layers, the loop that runs through them, the five patterns worth knowing, what breaks in each layer, and one layer that almost every published diagram leaves blank.
AI agent architecture is the arrangement of components that turns a language model into a system that pursues a goal. It combines a model, retrieved context, a reasoning and planning step, memory, a tool layer that acts on external systems, and an orchestration layer that controls the loop, retries, and termination.
Two distinctions clear up most of the confusion around the term.
The architecture is not the model. The model is one component. Swapping GPT for Claude changes the quality of the reasoning step; it does not change whether your agent can call the refund API twice for the same ticket. That is a design decision made in the orchestration and tool layers, and it is where production failures actually live.
An agent is not a workflow. Anthropic's engineering team draws the line cleanly: workflows are systems where models and tools are orchestrated through predefined code paths, while agents are systems where the model dynamically directs its own process and tool use. Both are legitimate architectures. Only one of them requires you to design for decisions you did not enumerate in advance, and that is the one this page is about.
If the definitional question is what brought you here, start with what agentic AI is and how it differs from generative AI, which covers the concept and the vocabulary. For the taxonomy of agent kinds, from simple reflex agents to learning agents, see the types of AI agents and how they work. This page assumes you have those and want the blueprint.
Published component lists disagree. Some sources name four parts, some seven, some eight. The disagreement is mostly bookkeeping: everyone includes reasoning, tools, and memory, and then splits or merges the rest. Six layers is the smallest set where every production concern has an owner, and it maps cleanly onto how teams actually divide the work.
| Layer | What lives here | The design question it answers |
|---|---|---|
| Model | The reasoning engine, its context window, its latency and cost profile | How good does the thinking need to be, and what does it cost per step? |
| Context and retrieval | System prompt, task input, retrieved documents, live signals from the environment | What does the agent know at the moment it decides? |
| Reasoning and planning | Task decomposition, tool selection, self-critique | How does a goal become a sequence of steps? |
| Memory | Working state within a run, episodic history across runs, durable learned facts | What survives past the current turn, and who can read it? |
| Tool and action | Function definitions, API clients, MCP servers, the credentials behind them | What can this agent actually change in the world? |
| Orchestration | The loop, step budgets, retries, error handling, handoffs, termination | When does the agent stop, and what happens when a step fails? |
The model is the reasoning engine. Architecturally, the decisions that matter are not which vendor you pick but how many models you run and where. Mature designs are heterogeneous: a strong model for planning, a cheap fast model for classification and extraction, and sometimes a third for evaluation. Treating the model as a swappable dependency behind an interface is the difference between a version bump and a rewrite.
Everything the agent knows at decision time arrives through this layer: the system prompt, the task, retrieved documents, and live signals such as the current ticket status or account balance. Retrieval-augmented generation (RAG), which fetches relevant documents and injects them into the prompt, lives here. So does the discipline of context engineering, which is mostly the art of leaving things out. An agent with a bloated context does not reason better; it reasons more expensively and gets distracted.
This layer converts a goal into steps. It decides whether to answer directly, call a tool, ask a clarifying question, or give up. It also decides which tool, which is a harder problem than it sounds once the tool count passes a dozen. Planning strategies differ in when the plan is formed: continuously, one step at a time, or up front as a full sequence. Both approaches appear as named patterns further down.
Three kinds of memory, three different lifetimes. Working memory is the state of the current run: the conversation, the intermediate results, the scratchpad. Episodic memory is the record of past runs, which is what lets an agent say it already tried that. Semantic memory is durable knowledge the agent has accumulated, usually stored in a vector database or a knowledge graph.
Memory is the layer teams underestimate. It is a persistence system with a read path, a write path, and a retention policy, and once an agent can write to it, memory becomes an input that a previous run controlled. That is a security property, not just an engineering one.
Tools are how an agent changes the world: a database query, a Jira ticket, a payment, a deploy. A tool definition is a name, a description, and a typed schema the model uses to decide when and how to invoke it. This layer determines the blast radius of every mistake in the layers above it, which is why it gets its own section below.
The orchestration layer runs the loop. It enforces step budgets and token budgets, retries failed calls, catches malformed tool arguments, routes work between agents, and decides when the run is finished. If your agent has ever spun in a loop calling the same search tool nineteen times, the fault was here. This layer is also what platform teams buy rather than build; see the guide to choosing an AI agent platform for how AI agent platform architecture packages these layers into a runtime you configure instead of assemble.
The six layers are static. The interesting behavior is the loop that runs through them. The canonical version comes from the ReAct pattern, which interleaves reasoning traces with actions so the model can revise its plan using what the last action actually returned. Production loops add two steps that research papers rarely draw: an authorization check before the action, and a durable record after it.
Trace one concrete run. A support agent receives "customer says the September charge was duplicated." It observes the ticket and retrieves the account. It plans a lookup_charges call, which is read-only and passes authorization instantly. It observes two charges seven seconds apart. It plans an issue_refund call for $240. Now the authorize step earns its place: refunds above $100 require a step-up, so the run pauses, a human approves in Slack, and the refund executes with the approver's identity attached to the audit record. Remove step three and the same agent refunds $240 on a duplicate that was actually two legitimate orders, with nothing but a shared service-account credential in the log.
Patterns are how experienced teams talk about agent design without drawing the whole stack. Five cover the vast majority of real systems, and a survey of emerging agent architectures found that the meaningful divergences between them are exactly these: how planning is structured, whether there is a leader, and how components communicate.
The model alternates between a reasoning step and a tool call, using each observation to revise what it does next. There is no separate plan; the plan is emergent. ReAct is the default for a reason: it is simple, it recovers naturally from surprising results, and it needs no extra infrastructure. Its weakness is drift on long tasks, where the agent wanders because nothing holds the overall goal.
A planner produces an explicit multi-step plan, then an executor carries out each step, with the planner revising when reality disagrees. The separation buys two things worth having: the plan is inspectable before anything executes, which is a governance win, and the executor can run on a cheaper model. The failure mode is specific and worth naming, because it propagates: a weak plan poisons every step downstream, and the executor rarely has the standing to object.
A generator produces a result and an evaluator critiques it against explicit criteria, looping until the critique is satisfied or a budget runs out. Anthropic calls this evaluator-optimizer; the research literature calls the self-critique variant Reflexion, in which an agent reflects on feedback from prior attempts to improve later ones. It works when you have clear evaluation criteria and the first draft is reliably improvable: code that must pass tests, copy that must satisfy a brief, extractions that must match a schema. It is wasted on tasks with no measurable notion of better.
A lead agent decomposes a task, dispatches subtasks to specialized workers, and synthesizes their results. Anthropic describes this as orchestrator-workers, and it is the same shape as the supervisor pattern in most frameworks. Use it when subtasks are genuinely parallel and genuinely different, such as a research task that needs a code searcher, a document searcher, and a summarizer. Use it far more carefully than the diagrams suggest: every worker multiplies token cost, and the synthesis step is where quality quietly leaks.
Multiple agents with distinct roles collaborate without a single leader, negotiating or handing off directly. This is the most expensive pattern to run and by far the hardest to debug, because failures are emergent rather than located. It earns its place when the domain genuinely has separate actors with separate authority, such as a procurement agent and an approval agent that must not be the same principal. Our guide to multi-agent systems and how to secure them covers the coordination models and the trust boundaries between agents in more depth.
| Pattern | Use it when | Do not use it when | Cost and latency |
|---|---|---|---|
| ReAct | The path is unknown and tasks finish in a handful of steps | Runs stretch past roughly ten steps and the agent starts drifting | Low |
| Plan-and-execute | The plan needs review before anything executes, or steps are numerous | The task is short enough that planning overhead exceeds the work | Medium, cheaper per step |
| Reflection | Quality is measurable and drafts reliably improve | There is no objective notion of a better answer | Medium to high, multiplies calls |
| Orchestrator-workers | Subtasks are parallel, distinct, and independently verifiable | Subtasks share state or must happen in strict order | High |
| Peer multi-agent | Separate actors genuinely need separate authority | You are modeling one job that one agent could do | Highest, hardest to debug |
The honest default: start with the simplest thing that works. Anthropic's own guidance is to reach for the added complexity of an agent only when simpler compositions fall short, because agents trade latency and cost for better performance on open-ended tasks. Most systems that describe themselves as multi-agent architectures are one ReAct agent with good tools and an org chart imposed on top.
Every architectural choice above encodes an assumption about how much rope the agent gets. That assumption deserves to be explicit, because it drives the controls you will need later. Building autonomous AI agents is not a different technology from building a scripted one; it is the same stack with the human moved from inside the loop to beside it.
Our guide to levels of agent autonomy maps these levels against deployment practice, including how to move an agent up a level without moving your risk up two.
Here is the sentence that reorganizes the whole diagram: an agent architecture becomes an access architecture the moment the agent can call a tool. Everything above the tool layer is prediction. Everything at and below it is consequence.
Tools reach an agent in three ways, in rough order of maturity. Native function calling hardcodes tool schemas into the application. A tool registry centralizes definitions so multiple agents share one catalog. A protocol standardizes the interface so any agent can talk to any tool server without bespoke glue.
The protocol that won is the Model Context Protocol. MCP is an open standard whose specification defines how an agent client connects to servers exposing tools, resources, and prompts, which is why the question of pairing agentic AI and MCP server infrastructure now comes up in nearly every architecture review. Start with the Model Context Protocol for the standard itself, then how MCP tools are defined and invoked for the schema-level detail that determines whether your agent picks the right one.
Standardizing the interface does not standardize the trust. A tool description is untrusted text that the model reads and obeys, which makes the tool catalog an injection surface: see MCP tool poisoning for how a malicious server turns a description field into instructions. OWASP ranks excessive agency, an agent holding more functionality, permissions, or autonomy than its task requires, among the top risks in large language model applications, and the tool layer is exactly where excessive agency is granted.
The architectural answer is to stop letting agents connect directly to tool servers. Put a broker in the path. An MCP gateway terminates every agent-to-tool connection in one place, which is the only position from which you can enforce a policy on a call the agent invented at runtime. MCP access control covers what that enforcement looks like per tool, per argument, and per caller.
Scan the published reference architectures for this topic and you will find the same six boxes, drawn well. You will not find the answer to the question an auditor asks first: who is this agent, on whose behalf did it act, what was it entitled to do at that moment, and what did it actually do?
That is a layer, and it wraps the other six. Four control points make it real.
1. Give the agent its own identity. Most agents in production today authenticate as a shared service account, which means the audit log records the service, not the agent, and never the person. An agent is a non-human identity and deserves the same lifecycle a human account gets: issuance, ownership, rotation, and revocation. Frontegg, the identity platform behind Agen.co, makes the same argument from the governance side: treat agents as first-class identities before you try to govern their behavior.
2. Delegate authority, do not clone it. An agent acting for a user should not hold that user's permissions. It should hold a scoped, expiring grant for the specific task. This is settled ground in identity engineering rather than a new invention: OAuth 2.0 defines scopes as the mechanism for limiting what an access token can do, and OAuth 2.0 Token Exchange defines how one party acts on behalf of another, distinguishing delegation from impersonation. An architecture that hands an agent a long-lived API key with broad scope has made a decision, whether or not anyone wrote it down.
3. Decide per action, at runtime. Static role assignment cannot govern a system that invents its next call mid-run. NIST's zero trust architecture already describes the right shape: no implicit trust, authorization evaluated per request, with a policy decision point separate from the policy enforcement point sitting in the data path. Map that onto an agent and the enforcement point is the tool boundary. AI guardrails covers the input, output, and action-level checks that run there.
4. Record it so it survives an incident review. The log has to answer four things per action: which agent, which human behind it, what was requested, and what policy decided. That is the difference between an incident review and a shrug. AI observability for agent systems covers the traces and evaluations, and auditing autonomous agents covers what auditors actually ask for. The AI agent governance guide ties the controls into a program rather than a pile of features.
None of this is exotic. It is the access control your organization already runs for humans, applied to a principal that acts thousands of times a day instead of logging in each morning. NIST's AI Risk Management Framework organizes the same work under govern, map, measure, and manage, which is a useful checklist when a security reviewer asks what your architecture does about risk.
Component lists describe the happy path. This table is the other one, and it is where AI agents best practices come from: every row is a failure a real team has had to design around.
| Layer | What breaks | The design response |
|---|---|---|
| Model | Confident wrong answers, silent quality regression on a version bump | Pin versions, run an evaluation suite in CI, keep a fallback model |
| Context and retrieval | Prompt injection through retrieved content; context bloat degrading decisions | Treat every retrieved token as untrusted input, and budget context deliberately |
| Reasoning and planning | Planning failure propagation: one bad plan corrupts every step after it | Make plans inspectable, checkpoint between phases, allow the executor to reject |
| Memory | Memory poisoning: a compromised run writes a fact that steers every later run | Scope memory per tenant and per agent, expire aggressively, validate on write |
| Tool and action | Excessive agency, tool poisoning, standing credentials with unbounded blast radius | Broker every call, scope and expire credentials, require step-up on consequence |
| Orchestration | Runaway loops, duplicate side effects on retry, cascading failure across agents | Hard step and token budgets, idempotency keys on every mutating tool, circuit breakers |
The security community has been cataloguing these systematically. OWASP's work on agentic AI threats and mitigations names tool misuse, privilege compromise, memory poisoning, and cascading failures as distinct agentic classes, which is a more precise vocabulary than "the agent did something weird". For scoring these against your own deployment, our agentic risk map turns the classes into a map you can rank.
An AI agent platform reference architecture is only useful if it survives contact with a sprint. This sequence front-loads the decisions that are expensive to reverse and defers the ones that are cheap to change.
Six layers: a model that reasons, a context and retrieval layer that supplies what it knows, a reasoning and planning layer that chooses steps, a memory layer that persists state, a tool and action layer that changes external systems, and an orchestration layer that runs the loop and decides when to stop.
An AI agent is a single system that perceives, decides, and acts toward a goal. Agentic AI is the broader category of software built around that capability, including multi-agent systems and the platforms that run them. In practice the terms overlap heavily and most sources use them interchangeably.
ReAct interleaves reasoning and acting in a single loop. The model thinks about what to do, calls a tool, observes the result, and revises its next step based on that observation. There is no separate plan, which makes it simple and adaptive but prone to drift on long-running tasks.
Start with a single agent. Multi-agent designs are worth their cost only when subtasks are genuinely parallel and distinct, or when separate actors need separate authority. Most systems described as multi-agent are one agent with good tools and an unnecessary org chart layered on top.
An MCP server exposes tools, resources, and prompts to agents through the Model Context Protocol, a standard client-server interface. It sits in the tool and action layer, replacing bespoke integrations with one contract so any compliant agent can use any compliant server without custom glue code.
Broker every call through a gateway rather than letting agents reach tool servers directly. Give the agent its own identity, issue scoped and expiring credentials instead of standing keys, evaluate each call against policy at runtime, require human approval on consequential actions, and log every decision.
The tool layer. Runaway loops and duplicate side effects on retry are the common operational failures, and excessive agency is the common security failure: an agent holding broader permissions than its task needs, using a shared credential nobody can trace to a person.
The six-layer stack is well understood, and the patterns above will get an agent working. What separates a demo from a system you can run in front of an auditor is the seventh consideration: an agent with its own identity, authority delegated per action instead of cloned wholesale, a human in the loop where consequence demands one, and a record with a name on it.
Agen.co exists for that layer. The MCP gateway puts an enforcement point between your agents and their tools, so policy runs per action at runtime rather than living in a prompt. If you are designing this now, the AI agent governance guide is the next thing to read.
Keep reading
Agentic AI plans, decides, and acts on goals autonomously. Learn how it works, how it differs from generative AI, real examples, and how to govern it safely.
Written by
Agen.co
AI agent workforce management is how enterprises onboard, govern, secure, and oversee a fleet of autonomous AI agents. Learn the lifecycle and control plane.