Back to Writing
• • 14 min read

Building an Agentic System, Layer by Layer

How an agentic system is put together and how to choose its parts, from the model and its tools to guardrails and upkeep, with a stack builder to try one.

Jump to Section Contents

An agent is usually described in one line, as a model that calls tools in a loop until a task is done. Building one means deciding what that line leaves out: which model does the reasoning, what it can look up and change, where it runs, who can reach it, what it may do without asking, and how anyone checks the result.

Those decisions sort into layers, grouped by what they cover. The agent is the model, the orchestration that runs its steps, its tools, and its memory and data. Deployment is the runtime it runs on and the interface people and software use to reach it. Operations and maintenance covers guardrails, evaluation and observability, and the delivery and upkeep that keep it working after launch.

Builders get the choices at each layer and an order to set them up. Leaders supporting them need to understand those choices well enough to help shape the strategy, including how much the model should decide, what should wait for a person, what it will cost and which providers it will depend on. Readers new to the vocabulary can look up words such as token, context window and harness in the Terms glossary.

The first decision, made before any layer, is whether code or the model picks each next step.

Contents

Workflows and Agents

The difference between a workflow and an agent is whether fixed code or the model picks each step. Anthropic's guide calls both designs agentic systems and separates them by that test, and OpenAI's guide draws the same line between workflows and agents. In a workflow, models and tools run through code paths someone wrote in advance. In an agent, the model directs its own process and tool use, and keeps control over how the task gets done.

A workflow is predictable and cheap to test because its paths are fixed. An agent handles tasks whose steps cannot be listed ahead of time, and it costs more to run and needs more testing before anyone relies on it. Anthropic advises starting with the simplest solution that works. Often that is a single model call with retrieval and examples in the prompt, and for well-defined tasks it is a workflow.

Workflow: code decides

Classify an incoming invoice, extract its fields, check them against the purchase order, then draft a reply. The steps and their order are the same every time.

Fits work that repeats the same steps at high volume, where a low cost per run adds up.

Agent: the model decides

Find out why a build fails, fix it, and confirm the tests pass. The number of steps and the files involved are unknown at the start.

Fits open-ended work where each step depends on what the last one found, and a person or a test can check the outcome.

Between one model call and a standing team of agents, autonomy rises in six levels. In the stack, the level is mostly a choice about Orchestration, from fixed code paths to a loop the model drives to a lead agent that hands work to others. The first four follow the order of Anthropic's guide, level five adds a lead agent directing subagents, and level six is this site's label for agents with standing roles that start work from a schedule or an event.

Levels of autonomy
Level Who picks each step What it adds What it costs
1. Single callThe person writing the promptAn answer from what the model already knowsNo lookup or memory
2. Augmented modelThe model, for one turnSearch, retrieval, tool calls and memoryTool context on every turn
3. WorkflowCodeRepeatable multi-step work with checks between stepsOnly the paths written in advance
4. Single agentThe model, in a loopTasks whose steps cannot be listed in advanceAbout 4 times the tokens of a chat
5. Multi-agentA lead agent that delegatesParallel work, with a clean context for each workerAbout 15 times the tokens of a chat
6. Standing fleetA coordinator, schedules and eventsWork that continues with nobody askingRoles and rules to maintain, and spend caps to set

Token multiples from Anthropic's account of its multi-agent research system.

OpenAI's practical guide recommends getting the most out of a single agent before adding more, because more agents bring extra complexity and overhead. Anthropic reports that multi-agent designs pay off on high-value tasks that split into parallel parts or exceed one context window, and fit poorly when every agent needs the same context.

Move up a level when the current one fails in a way you can name. A workflow that keeps meeting cases its paths do not cover is a reason for an agent. An agent that runs out of context on large jobs is a reason for subagents.

What an Agent Adds to a Software Project

Much of an agentic system is built and run like other software, with version control, staging, sign-in and a named owner. Letting a model pick its own steps adds work in six areas.

Where an agent needs more than other software
Area Same as other software What an agent adds
TestingRelease tests and stagingThe same request can take a different path on each run, so a set of test tasks is graded on the final state each run reaches
StoppingError handling and timeoutsThe model decides when the task is done, so someone has to write a cap on turns, a failure limit and a handback to a person
CostHosting and licensesCost per run grows with the steps the model takes, so every loop needs a spend cap
SecuritySign-in, roles and a secrets vaultText the agent reads, such as a web page or an email, can carry instructions it may follow, and code it writes runs with the access of its machine
ActionsAccess control by roleThe model chooses when to call each tool, so tools are rated by risk and the high-rated ones wait for a named person
ReleasesVersion control and rollbackPrompts and tool descriptions change behavior the way code does, and a new model version changes how every prompt behaves

Lay Out the Layers

With a starting level picked, list what each of the nine layers will hold. Each layer has one job, shown below, and the table lists common choices for each. Guardrails are the one layer that applies to all the others.

The layers by group

Agent

  • Model. Reads the context and picks what to do next

  • Orchestration. Runs the steps or the loop

  • Tools. What the system can look up and change

  • Memory and data. What the model is given, what is saved, and what it can look up

Deployment

  • Runtime. Where the work runs, what starts it and how long runs recover

  • Interface and front end. How people and other software reach it

Operations and maintenance

  • Guardrails. Approvals, access, checks and limits on every layer

  • Evaluation and observability. Whether it works and what it costs

  • Delivery and upkeep. How changes ship and who keeps it running

Common choices by layer
Layer Common choices
ModelA language model, a small language model, a decision model, an embedding model or reranker, a hosted API, self-hosted weights or a model on the device, a model gateway, a fallback model
OrchestrationPlain code, an agent framework, an agent app, managed agents, subagents, a planning step, structured output
ToolsFunction calling, MCP servers, business APIs, page fetching, web search, code execution, computer use, file access, payments
Memory and dataInstruction file, skills, user preferences, compaction, saved notes, documents, file storage, a database, vector store, memory service
RuntimeLocal machine, own server, sandbox, cloud computer, schedules, event triggers, durable workflows, checkpoints, error handling
Interface and front endOwn app, chat window, team chat, email, command line, API, agent endpoint, voice or phone, streaming replies
GuardrailsHuman approval, review model, permission allowlist, network policy, secrets vault, sign-in and roles, content filters, spend limit, stop switch
Evaluation and observabilityTracing, test tasks, cost tracking, audit log, alerts, user feedback
Delivery and upkeepVersion control, model pinning, release tests, staging, rollback, a runbook and owner, scheduled updates

Off-the-shelf products have the same layers with fewer controls. Turning on an agent in a workplace assistant still means deciding which connectors it can use, what it remembers and which actions wait for approval.

The Agent Stack Builder lays out a stack the same way. The card below is its Personal assistant template, with what each layer holds and the concerns the builder flags.

Template

Personal assistant

One person working hands-on, on their own machine.

1Model
Language model, Hosted API
2Orchestration
Agent app
3Tools
MCP servers, Web search, File access
4Memory and data
Skills, Instruction file, Compaction, Saved notes
5Runtime
Local machine
6Interface and front end
Chat window
7Guardrails
Human approval, Permission allowlist, Secrets vault
8Evaluation and observability
Tracing, Cost tracking
9Delivery and upkeep
Version control

Concerns come from six fixed checks, such as tools that act with no approval step or code that runs with no sandbox. Options typed in by hand are not checked.

The full builder starts from any of four templates (Personal assistant, Scheduled job, Coding agent and Multi-user service). Options turn on or off in each layer, custom labels cover anything the list lacks, and the builder shows the autonomy level of the result. Copy link gives a link that reopens the stack, and the diagram can be copied or downloaded. A review prompt copies the stack into an AI assistant to talk it through, and the builder's Definitions explain every option.

The builder can also name up to five providers and show who supplies each part. With providers named, the diagram shows how many companies the system depends on, whose terms cover the data it reads, and what a fallback model or gateway would have to replace. Someone reviewing a team's plan can open its stack from a copied link and read the Concerns and the providers before approving it.

The Agent

Model and orchestration

OpenAI's guide recommends building the first version with the most capable model on every step, then swapping in smaller models wherever the test tasks still pass, which lowers cost and latency. A fallback model or gateway keeps the system up when a provider fails, and adds one more model the test tasks have to cover.

The harness is the code that runs the loop and enforces limits. Besides a finished task, someone has to write each way the loop can stop: a cap on turns or spend, a limit on repeated failures, and a handback to a person, which OpenAI's guide ties to a failure threshold.

The team can write the harness, take one from a framework, or let a provider run it. The choice sets how much the team has to operate and how closely the system is tied to one provider.

Plain code

Every step stays visible and every limit is written by hand. Anthropic suggests starting here and understanding the code under any framework adopted later.

Agent framework

The loop comes ready-made. The team still runs the sandbox and absorbs upgrades.

Managed agents

The least to operate. The system can use only the tools and logging the provider supports.

OpenAI's guide suggests splitting work across agents when instructions fill with conditional branches or tools overlap enough to confuse the model. It describes two shapes: a manager that calls other agents as tools, which keeps one trace to read when a run goes wrong, and peers that hand a task to one another.

Tools

Every tool's description, from a plain function or an MCP server, is sent to the model on each turn. Anthropic's guidance on writing tools finds that more tools do not always help, and that one tool for a whole task, such as searching contacts, beats a set that mirrors every API endpoint. Its context engineering guide adds a test: if an engineer cannot say which tool fits a situation, the model will not do better.

Choosing a tool type
Tool type Pick it when What it costs
Function callingThe system and the agent belong to the same teamEach new agent product needs the tools wired again
MCP serverOne connector should serve several agent productsIts author picked the actions it exposes
Code or computer useNo tool or API covers the jobThe widest reach, so a sandbox in Runtime

A read tool that misfires wastes tokens. A write tool that misfires can send an email, move money or delete a record, so most of the approvals and limits in Guardrails attach to the write tools.

Memory and data

Quality drops before the context window is full, which Anthropic's context engineering guide calls context rot. The guide favors keeping light references such as file paths and loading the data when a step needs it.

Where information lives
Technique Lasts for Pick it when
Instruction fileEvery sessionA rule applies to every task, as in an AGENTS.md file
SkillsEvery session, loaded when neededA long procedure only some tasks need
Saved notesA task or projectA plan must survive a reset or pass between agents
RetrievalAs long as the source doesEach step needs a slice of a large source
Long-term memoryAcross sessionsPreferences should carry forward

Most techniques from Anthropic's context engineering guide; AGENTS.md from its project site.

Facts that change, such as prices, stay in their source system, because a remembered copy goes stale silently. Rules that must hold every time belong in permissions, since a model can overlook a remembered rule on a long run. Long-term memory needs an owner who can correct and delete it.

Deployment

The same agent can run on a laptop for one person or on a server for a team. A server adds hosting costs and someone to keep it running.

Runtime

A laptop is the cheapest start but stops when the laptop does, which rules out schedules. Anthropic's research system resumes long runs from the step where an error hit, since a restart is expensive and frustrating for users.

Interface and front end

A team chat or shared inbox lets anyone in it hand the agent a task, which calls for sign-in and roles in Guardrails. Behind an API the caller is other software, and it needs structured output it can check.

Generated code runs with the access of its machine, so code execution or computer use calls for a container, a list of permitted hosts and credentials from a vault. Security should review that setup before either tool is turned on.

Operations and Maintenance

Guardrails

The main decision is what runs with no confirmation. OpenAI's guide names high-risk actions as a trigger for human intervention and suggests rating each tool low, medium or high by whether it only reads, whether it can be reversed, which permissions it needs and what money it can move. High-rated actions then wait for approval. Each approval also needs a named person to answer it. The rated list and those names are what a sponsor signs off on before launch.

Deciding which tools wait for approval

1. Check each tool for

  • Whether it only reads
  • Whether its effect can be reversed
  • Which account permissions it needs
  • What money it can move

2. Rate it from what you find

  1. Low
  2. Medium
  3. High: pauses for a check or goes to a person

Anything the agent reads can also try to steer it. A web page, an email or a shared file can hold text written as instructions, known as prompt injection. Ordinary software keeps data and commands apart, while a model reads both as text. OpenAI's guide lists a classifier that screens inputs for prompt injection among its guardrails, and the approval step on high-rated tools limits what a steered agent can do.

Evaluation and observability

Models are probabilistic, choosing each word from a range of likely options, so the same request can send an agent down a different path on each run, and one good transcript proves little. Lowering the temperature setting reduces the variation, and Anthropic's glossary notes that identical inputs can still produce different outputs even at zero.

Anthropic's research team began with about 20 test tasks and recommends grading whether a run reached the correct final state, with a second model applying a rubric and people reading a sample. Traces show which step produced a bad result.

If the test tasks pass at level three (a workflow), moving to level four (a single agent) only adds cost. A task that fails at the workflow level in a way a model-driven loop would fix is the reason to move up.

Delivery and upkeep

A service many people rely on needs versioned prompts and tools, test tasks before each release and a quick rollback. Pin the model version. A new model changes how every prompt and tool call behaves, so it goes through the test tasks like any other release. Updates can also break runs in progress, so Anthropic's research system rolls them out gradually. Name the owner of these releases before launch, along with who answers when a run fails.

A Smaller Example: Competitor Discovery

The competitor discovery behind UX Bench, the site's Core Web Vitals benchmark, takes a domain, names its industry and picks five competitors to compare against. It is a level-three workflow: code runs the prompts and lookups in a fixed order, and the model never picks the next step. Its build is written up in Building a Competitor Discovery System.

Competitor discovery, read against the stack

  • A language model through a hosted API, with a local open model for the first large batch
    Model
  • A fixed sequence of prompts that narrows a domain down to an industry code
    Orchestration
  • Page crawling, Chrome UX Report data and a domain data API
    Tools
  • Stored classifications, plus site rankings to pick competitors of a similar size
    Memory and data
  • Cloudflare Workers, with storage and a cache
    Runtime
  • The UX Bench tool page
    Interface and front end
  • Only high-confidence classifications reach production
    Guardrails
  • Keyword matching, a single prompt and the fixed sequence reached a full industry code for 4.4%, 79% and 100% of domains
    Evaluation and observability

The system only reads, and both of its paths, one for domains already classified and one for new ones, are written in advance. That spares it most of the work an agent adds: each run ends when its last step does, there are no write tools to put behind approval, and every run follows one of two known paths, so the test tasks can cover both. Moving it up a level would take a domain neither path handles. Open this stack in the builder to see the layers it fills.

Key Takeaway

Someone building an agentic system has an order to follow, and a leader supporting the build helps set the strategy around it.

For builders

  1. Write test tasks in proportion to the project's scope, from a few for a narrow workflow to many more for a broad agent, graded on the final state.
  2. Build the first version as a workflow if the steps can be listed, on the most capable model.
  3. Code the stop conditions in the harness, with caps on turns and spend, a failure limit and a handback to a person.
  4. Rate each tool low, medium or high, and put the high ones behind approval.
  5. Add tracing, pin the model version, then swap in smaller models where the test tasks still pass.

For leaders

  • Confirm the work needs an agent at all. A single model call or a workflow often does the job, and any move up a level should have a failed test task behind it.
  • Ask for the pass rate on the test tasks before approving a launch. Models are probabilistic, so an agent can take a different path on each run, and one good demo shows little.
  • Agree whether the build is a pilot or a lasting service. A pilot can run on one laptop, while a lasting service needs a server, sign-in, a release process and a named owner.
  • Sign off on which write tools wait for approval, such as those that send, pay or delete, and on who answers each request. Set a spend cap on every loop.

Further Reading & Sources

Further Reading

Sources