Read our operating thesis — Machines work better in tandem
JOURNALARCHITECTURE · JULY 2026

The AI agent tech stack: seven layers

Most stack diagrams stop at the control loop. The two layers after it — governance and evidence — are what separate an agent you demo from an agent you deploy, and they are architecture, not process.

WRITTEN BYTandem Machines
Coordinated Intelligence
PUBLISHED
READING TIME17 minutes
SHARE
LinkedInX
KEY TAKEAWAYS
  • 01Seven layers: model, context, tools, control loop, memory, governance, evidence.
  • 02Frameworks and tutorials cover layers one to five. Deployments fail at six and seven.
  • 03Build the tool layer first — it determines what governance and evidence you need.
  • 04Each layer should be replaceable without touching the others. If swapping the model means rewriting your tools, the boundary is in the wrong place.
  • 05Governance and evidence are architecture, not process. You cannot add them to a finished agent as a review step.

The seven layers

An agent stack has seven layers: a model layer that abstracts the provider, a context layer that decides what enters the window, a tool layer that defines the action surface, a control loop that bounds iteration, a memory layer for state that outlives a run, a governance layer that decides what may happen without a human, and an evidence layer that records what did happen.

Most published stack diagrams stop at four. That is not an oversight — the first four layers are genuinely all you need to produce something that works, and they are what every framework competes on. The last three, and particularly the last two, are what you discover you need at the exact moment an agent touches something real.

#LayerResponsibilityFailure if missing
01ModelProvider abstraction, routing, fallbackLocked to one vendor's pricing, limits and outages
02ContextWhat enters the window, and what it costsCost explosion; the agent forgets what matters
03ToolsThe action surface — schemas, execution, idempotencyDuplicate side effects; unbounded capability
04Control loopStep budget, stop conditions, retry, escalationRunaway loops; errors that compound silently
05MemorySession state, durable memory, reusable proceduresRe-derives the same knowledge every single run
06GovernanceAuthority boundaries, approval gates, policy in codeNothing stops a redirected or mistaken agent
07EvidenceTracing, evals, audit trailYou cannot prove, reconstruct, or improve what happened
LAYERS 6 AND 7 ARE WHERE PILOTS DIE — AND THE ONE FRAMEWORKS DON'T PROVIDE

The organising principle is replaceability. Each layer should be swappable without touching the others, and the test is concrete: if changing your model provider means rewriting tool definitions, or adding an approval gate means editing the control loop, the boundaries are in the wrong place.

1. Model

The model layer treats the LLM as a configured dependency rather than a hard-coded assumption. It owns provider selection, per-task model choice, fallback when a request is refused or a provider degrades, and the parameters — effort, thinking, token ceilings — that trade cost against capability.

The mistake here is not choosing the wrong model; it is choosing anything at all in a way that cannot be revisited. Model releases currently outpace deployment cycles, so a system that names a model in forty places has already lost a decision it will need to make again within months.

Per-task, not per-system

A single model everywhere is almost always wrong in one direction or the other. Planning, ambiguity resolution and anything with a wide solution space want capability. Mechanical extraction, classification and routine tool selection do not. The practical shape is a capable model on the main thread and cheaper models for delegated work that is well-specified — see the Agent SDK guide for how per-subagent model selection works in a real harness.

One constraint worth knowing before you design around model switching: prompt caches are model-scoped. Changing model mid-conversation invalidates the cache, so the cheap pattern is a stable main thread with variety pushed into subagents rather than a router that swaps models turn by turn.

2. Context

The context layer decides what occupies the window on each request: system instructions, conversation history, retrieved documents, tool schemas, and memory. It is the layer that most directly controls cost, and the one where cost problems are almost always actually relevance problems.

Four things compete for the window, and they have very different value density. Instructions are small and load-bearing. Tool schemas are moderate and mostly static. History grows without bound. Retrieved content is the largest and the most variable in usefulness.

THE FOUR CONTEXT CONSUMERS, BY MANAGEMENT STRATEGY
01InstructionsSmall, stable — keep first in the prefix so it caches
02Tool schemasStatic; defer loading when the library is large
03HistoryGrows unbounded — compact or clear stale tool results
04Retrieved contentLargest and least predictable; filter before it enters
ORDER OF ATTENTION SHOULD FOLLOW COST × VARIABILITY, NOT SIZE ALONE

Caching is a prefix match, and that dictates layout

Prompt caching keys on the exact bytes of the prompt up to a breakpoint, which means one changing byte early invalidates everything after it. That single fact determines the whole layer’s design: stable content first, volatile content last, and nothing dynamic interpolated into the system prompt.

The classic self-inflicted wound is a timestamp or a session ID in the system prompt. It sits at position zero, changes every request, and quietly makes the entire conversation uncacheable. If your cache-hit rate is zero across identical-looking requests, look for something like that before looking anywhere else.

3. Tools

The tool layer is the agent’s action surface: what it can do, with what arguments, and with what guarantees. Build this layer first — the set of available actions determines what governance you need, what evidence you must capture, and how much context is required to use them correctly.

Two design decisions in this layer matter more than the rest of the stack combined.

Granularity: bash versus dedicated tools

A shell tool gives an agent enormous reach and gives your harness nothing: every action arrives as an opaque command string with the same shape. Promoting an action to a dedicated tool with a typed schema gives you something you can gate, render, log, rate-limit and parallelise.

Start with breadth and promote what you need to control. The signal that an action should be promoted is that you want to do anything to it other than run it.

Guarantees: exactly-once is not free

Every tool that changes state needs an explicit answer to “what happens if this runs twice?”. Agents retry on their own initiative and often cannot tell whether a previous attempt succeeded, so this is not a theoretical concern — it is the most common source of real damage in agent deployments. The mechanism differs from the HTTP pattern because an agent’s retry is not a byte-identical request; see idempotency for agent actions for how to key on intent instead.

The tool-layer rule
A tool description should state when to call it, not only what it does — that phrasing measurably changes how often the model reaches for it. And every mutating tool should ship with a matching read, so the agent can check rather than guess.

4. Control loop

The control loop decides when the agent acts again and when it stops. It owns the step budget, the cost ceiling, retry behaviour, and the conditions that end a run — completion, exhaustion, or escalation. An unbounded loop is an open-ended bill and an unbounded blast radius.

This is the layer people write themselves and shouldn’t. The loop is not where differentiation lives, it is well-solved by several harnesses, and hand-rolling it means owning a class of bug — malformed tool-result ordering, dropped parallel calls, mishandled pause states — that has nothing to do with your product.

What the loop layer must expose
// Bounds — every one of these should be configurable per run.
maxTurns:      40,        // agentic iterations before a hard stop
maxBudgetUsd:  5,         // spend ceiling, enforced
taskBudget:    { total: 64_000 },  // budget the model is AWARE of, so it paces itself
timeoutMs:     15 * 60_000,

// Stop conditions — distinct outcomes, not one boolean.
//   completed  → objective met
//   exhausted  → hit a budget; partial work may be salvageable
//   escalated  → hit an authority boundary; waiting on a human
//   failed     → unrecoverable
TASK BUDGET AND MAX TOKENS ARE DIFFERENT THINGS — ONE PACES THE MODEL, THE OTHER CUTS IT OFF

The distinction in that caption is worth internalising. A hard output ceiling truncates the model mid-thought with no warning. A budget the model can see lets it prioritise and finish gracefully. Production loops want both: the budget for behaviour, the ceiling as a backstop.

Loops compound errors

A single wrong tool call is bounded. A loop is not: the agent acts on a mistaken belief, observes a world that now reflects its mistake, concludes something further, and acts again. By step six the original error is buried under five steps that each followed logically from it, and the transcript reads as reasonable the whole way down. That is why the stop conditions above need to be four distinct outcomes rather than success or failure — escalated in particular is not a failure, and treating it as one is how agents get retried into damage.

5. Memory

The memory layer holds state that outlives a single request or run: conversation state within a session, durable facts across sessions, and reusable procedures the agent has worked out before. Without it, an agent re-derives the same knowledge every run and pays for it in tokens, latency and variance.

Three distinct things get called memory, and conflating them is why the layer is usually built badly.

KindLifetimeWhat it holds
Session stateOne runHistory, intermediate results, current plan
Durable memoryAcross runsFacts, preferences, decisions worth persisting
Procedure libraryAcross runs and agentsReusable workflows the agent worked out once

The third is the highest-leverage and the least commonly built. An agent that solves a multi-step problem, writes down the procedure, and reuses it next time is strictly cheaper and more consistent than one that re-reasons from scratch. It is also the design decision behind the fastest-growing open agent runtimes, which is a reasonable signal that it works.

Memory is an injection surface

Anything the agent writes and later reads as instruction is a persistence channel for a prompt injection. Content absorbed from an attacker-controlled source in one session and written to memory affects every later session that loads it — a compromise that outlives the run that caused it. Treat memory writes as untrusted on read, and never store credentials there: memories are replayed verbatim into future contexts.

6. Governance

The governance layer decides what the agent may do without a human. It owns authority boundaries, approval gates on consequential actions, least-privilege credentials per task, and policy enforced in code rather than stated in a prompt. This is the first layer that most stacks omit and the first one a deployment needs.

“If a rule matters, it must be enforced in code that runs regardless of what the model decided. Anything expressed only as instruction is subject to negotiation.”

That is the whole layer in one sentence. A constraint written into the system prompt is a preference; the attacker, or simply an unusual situation, gets to make the closing argument. A constraint enforced at the tool-call boundary is a rule.

The four controls

CONTROLS THAT HOLD WHEN THE MODEL IS WRONG
01Least privilegeCredentials scoped per task, not inherited from a service account
02Approval gatesOn irreversibility, value and low confidence — not on everything
03Policy in codeChecks on the tool call, not sentences in the prompt
04Egress controlEnumerate every outbound channel, including images and shared writes
EACH ONE ASSUMES THE MODEL WILL BE MISTAKEN OR FOOLED — WHICH IT WILL

Two of those have a failure mode worth naming. Least privilege is usually skipped because permissions are inherited rather than designed — the agent gets wired to an integration user that already had broad access and nobody narrowed it, because the demo runs either way. And a gate that fires constantly gets clicked through, which converts a control into a formality that produces a record implying review that did not happen.

Deciding where the boundary sits is its own problem, and it is more a question about the organisation than about the software — when should an agent ask covers the three signals worth gating on. For the adversarial view of the same layer, see the agent threat model.

7. Evidence

The evidence layer records what the agent did and why, in enough detail to reconstruct a decision after the fact. It covers tracing of every tool call with its inputs and reasoning, an audit trail durable enough to show a third party, and evaluations that measure whether behaviour is getting better or worse across releases.

This layer is usually confused with logging, and the difference is the audience. Logs are for you, during debugging, and can be lossy. Evidence is for someone who was not there — a reviewer, an auditor, a customer asking why — and it has to be complete enough to answer a question nobody anticipated.

What a trace needs to contain

Enough to answer “why did it do that?” without re-running anything: the objective, each action with its arguments, the result returned, the reasoning that selected it, which authority rule allowed it, and who approved anything gated. The last two are what makes it an audit trail rather than a transcript.

Evaluation is a trajectory problem

Reviewing outputs is sufficient for a system that only produces text. For an agent it is not: the same final answer can be reached through an acceptable path or an alarming one, and only one of those should pass. You are evaluating the sequence of decisions, not the answer — which means your eval harness needs traces, which means this layer is a prerequisite for improving anything above it.

That dependency is the strongest practical argument for building the evidence layer early rather than last. Without traces you cannot build evals; without evals every change to the layers above is a guess.

What to build first

Build the tool layer first, then the loop, then evidence, then governance — and take a harness rather than writing layers one, two, four and five yourself. The tool surface determines everything downstream, and evidence before governance because you cannot tune a boundary you cannot observe.
OrderBuildBecause it unblocks
1Tool surface (layer 3)Everything — governance, evidence and context all follow from what the agent can do
2Bounds on the loop (layer 4)Safe iteration; you can now run it repeatedly without an open-ended bill
3Evidence (layer 7)Evals, and any ability to tell whether a change helped
4Governance (layer 6)Production. This is the gate between a pilot and a customer
5Context and memory (layers 2, 5)Cost and consistency, once the shape is stable enough to optimise
THE ORDER IS DRIVEN BY WHAT EACH STEP UNBLOCKS, NOT BY THE LAYER NUMBERS

Layer one barely appears in that list, which is deliberate. Model choice feels like the first decision and is nearly the last one that matters — as long as you have kept it swappable, which costs almost nothing at the start and a rewrite later.

The through-line: the first five layers make an agent that works, and they are the ones with the most tooling, the most tutorials and the most vendor attention. The last two make an agent you can put in front of someone, and you will mostly have to build them yourself. That asymmetry is not a gap in the ecosystem — it is where the actual work is.

If you are deciding what to build on rather than what to build, the Agent SDK guide covers one harness in production detail, and the definitions piece is worth reading first if it is not yet settled whether you need an agent at all.

Frequently asked questions

What is in an AI agent tech stack?

Seven layers: a model layer that abstracts the provider, a context layer that decides what enters the window, a tool layer that defines the action surface, a control loop that bounds iteration, a memory layer for state that outlives a run, a governance layer that decides what may happen without a human, and an evidence layer that records what did happen.

How do I build an AI agent?

Pick a harness rather than writing the loop, define the narrowest tool surface the task needs, bound the loop with a step and cost ceiling, then add governance and evidence before it touches anything real. Building the first four layers gives you a working agent; the last two are what make it deployable.

Which layer should I build first?

The tool layer, because it determines everything downstream. The set of actions an agent can take decides what governance you need, what evidence you must capture, and how much context it takes to use them correctly. Teams that start with the model or the framework usually rebuild once the tool surface settles.

Do I need a framework to build an agent?

No, but you need a harness. The choice is whether to write the agent loop yourself or take one — the loop itself is not the hard part and not where the differentiation is. Frameworks help most in layers one through five and offer almost nothing for governance and evidence, which is where deployments actually fail.

What is the difference between the control loop and the governance layer?

The control loop decides when the agent stops — step budgets, cost ceilings, stop conditions. The governance layer decides what the agent is permitted to do at all, and which actions require a human first. One bounds how long it runs; the other bounds what it can change.

Why do agent projects fail at the last two layers?

Because layers one through five are what frameworks, tutorials and demos cover, and they are enough to produce something that works. Governance and evidence only become necessary when an action has consequences outside the model, which is exactly the point at which a pilot meets a real customer and gets paused.

Sources

  1. 01Building effective agents Anthropic, 2024
  2. 02Agent SDK overview Anthropic, 2026
  3. 03Model Context Protocol specification Anthropic, 2026
  4. 04OWASP Top 10 for Large Language Model Applications OWASP, 2025
Tandem Machines
Notes on coordinated intelligence — one essay a month
Subscribe
PREVIOUS

Agent observability: Langfuse vs Arize Phoenix vs Braintrust