Single agent with tools: one model in a loop
One model, one loop, and a small set of tools, with a step budget around it. Start here for most agent work, and add more structure only when this one clearly falls short.
Single agent in 60 seconds
- What: one model that loops, choosing a tool or a final answer at each step, with one shared history.
- Why it is the default: it is the simplest design that can use tools, and it is easy to build, test, and debug.
- Best for: tasks with a handful of tools and a short path, such as support lookups or data questions.
- Weak spots: many tools confuse the model, long tasks overflow the context, and one prompt must serve every skill.
- Origin: ReAct (Yao et al., 2022) interleaves reasoning with actions so the model can update its plan from tool results.
Where this type fits
In the orchestration hub, patterns are grouped by who decides the path: your code, a model, a reviewer, or a person. The single agent is in the family where a model decides. It is the base case. Supervisor and handoff designs are what you get when you split this one agent into several, so it is worth mastering first.
The problem it solves
A plain model call can only write text from what it already knows. It cannot check today's order status, look up a customer, or send a message. Without tools you must either put everything in the prompt, which is often impossible, or write fixed code that decides every step in advance.
Fixed code breaks when requests vary. A customer asks, 'Where is my order, and can you change the address?' One request needs a lookup, a rule check, and an update, in an order that depends on what the lookup returns. Code that handles every such path becomes a thicket of branches.
A single agent lets the model pick the path. It sees the tools, reads the request, and chooses the next step. After each tool result it chooses again. This is the pattern ReAct describes: reasoning and acting in turns, so each new fact can change the plan. The cost is that the path is no longer fixed, so you must add limits and checks around the loop to keep it safe and affordable.
How it works
- Set up: write a system prompt with the role, rules, and when to ask for help. Describe each tool with a name, a purpose, and typed arguments.
- Receive the request: the user's message becomes the first entry in the history.
- Model step: the model reads the history and replies with either a tool call or a final answer.
- Run the tool: your code checks the arguments, applies permissions, runs the tool, and appends the result to the history. Tools that change things can ask for confirmation first.
- Repeat: the model sees the result and decides again. A counter tracks steps.
- Stop: the loop ends on a final answer, on the step limit, or on an error that should go to a person.
The picture is deliberately plain. There is one decision maker and one history. All the control lives in the code around the loop: the step budget, the argument checks, and the confirmation step for the email tool. The model chooses, but the harness decides what is allowed.
Because there is a single history, every tool result is visible to every later step. That is a strength, since nothing gets lost in a hand-off. It is also the limit. The history grows with every step, so long tasks eventually crowd the context window.
A worked example
Acme Outfitters runs a support agent with three tools: search_help(query), get_order(order_id), and send_email(to, subject, body), the last needing confirmation. The step budget is 8.
Customer message: 'My jacket order A-7731 has not arrived. Can you email me the tracking link?'
- Step 1. The model thinks it needs the order. It calls
get_order('A-7731'). Result:{status: 'shipped', carrier: 'FastPost', tracking: 'FP-90412', customer_email: 'sam@example.com', shipped: '2026-03-02'}. - Step 2. The model checks the policy on late parcels. It calls
search_help('late parcel policy'). Result: a passage saying parcels are late after 7 working days and are re-sent after 10. - Step 3. Seven working days have not passed, so the parcel is not late. The model decides to send the tracking link. It calls
send_emailwith the customer's address and a short note. - Confirmation. The harness sees that
send_emailneeds confirmation and shows the draft to the customer. The customer approves. - Step 4. The tool returns
sent. The model replies: 'Your jacket shipped on 2 March with FastPost. I have emailed the tracking link FP-90412. It is not yet late, but tell me if it has not arrived by the 12th.'
Four model calls, three tools, one confirmation, and the history held every result for the next decision.
Building it
The sketch below is the whole pattern. llm.generate, tools, and confirm are placeholders for your own parts. Notice the step limit, the argument check, the output cap, and the fact that errors become observations the model can react to.
MAX_STEPS = 8 # hard stop on loops
MAX_TOOL_OUTPUT = 2000 # characters kept from any tool result
NEEDS_CONFIRM = {'send_email'}
# Placeholders: llm, tools, and confirm stand in for your own components.
def run_agent(user_message, llm, tools, confirm):
history = [{'role': 'user', 'content': user_message}]
for step in range(MAX_STEPS):
reply = llm.generate(
system='You are a support agent. Use tools only when needed.',
messages=history,
tools=[t.spec for t in tools.values()],
)
if reply['type'] == 'answer':
return {'status': 'done', 'answer': reply['text'], 'steps': step + 1}
name, args = reply['tool'], reply['args']
history.append({'role': 'assistant', 'tool_call': reply})
# Why: the model can ask for a tool that does not exist or pass bad data.
if name not in tools or not tools[name].valid(args):
history.append({'role': 'tool', 'content': 'error: bad tool call'})
continue
if name in NEEDS_CONFIRM and not confirm(name, args):
history.append({'role': 'tool', 'content': 'user declined this action'})
continue
try:
result = str(tools[name].run(args))[:MAX_TOOL_OUTPUT]
except Exception as err:
# Errors go back as text, so the model can try something else.
result = 'error: ' + str(err)[:200]
history.append({'role': 'tool', 'content': result})
# Out of budget: hand over instead of looping on.
return {'status': 'step_limit', 'answer': 'I could not finish. Passing to a person.'}Design decisions
- Number of tools: keep it to about five to ten, with clear, distinct names. Beyond that the model picks wrongly more often. If you need more, route to a smaller toolset first. See the router page.
- Tool design: make tools narrow and typed, with plain error messages. A tool named
get_orderbeats a generalquery_database. Narrow tools are safer and easier to test. - Permissions: run tools with the end user's rights, not a broad service account. Default to read-only tools, and add write tools one at a time with confirmation.
- Step and cost budgets: cap steps, tokens, and seconds. Eight to fifteen steps is a sensible start, and stop when a budget ends.
- Context growth: trim or summarise old tool results, and cap each result's length. Large raw outputs are the usual reason a loop degrades.
- Failure handling: return tool errors as text for the model, retry only safe operations, and use idempotency keys on writes. Add a circuit breaker around flaky tools.
- Model choice: use a stronger model for the loop, and smaller ones inside tools that summarise or classify. Keep one model version pinned and test before upgrading.
Measuring it
- Task success rate: the share of test requests that end in a correct result, judged by a script or a reviewer against a fixed set of cases.
- Tool selection accuracy: for test requests where the right tool is known, the share of first calls that pick it, with valid arguments.
- Steps per task: the mean and the 95th percentile. A rising tail means loops or confusion.
- Budget hit rate: the share of runs that stop on the step limit. This should be small, and each case is worth reading.
- Cost and latency per task: tokens times price, and total seconds, split by model call and tool call.
- Unsafe action rate: the share of runs where a write tool was called wrongly or without confirmation. The target is zero.
When to use it, and when not to
| Situation | Use this type? | Why |
|---|---|---|
| A support bot with order lookup and a help search | Yes | Few tools and a short path suit one loop. |
| A first version of any new agent feature | Yes | It is the quickest to build and the easiest to debug, so you learn what is really needed. |
| Steps are always the same, in the same order | No | Use a pipeline. Fixed code is cheaper and more predictable. |
| Thirty or more tools across different domains | No | The model will choose badly. Use a router or specialist agents. |
| Work needing different skills and long contexts | Not alone | A supervisor with workers keeps each context small. |
| Irreversible actions with no review | No | Add confirmation or a human checkpoint first. |
Trade-offs
| Dimension | Effect | What to do about it |
|---|---|---|
| Quality | Handles varied requests, but quality drops as tools and context grow. | Keep the toolset small, test on a fixed set, and trim history. |
| Latency | Each step is a model call, so latency grows with steps. | Set step limits, run independent lookups together, and use faster models where possible. |
| Cost | Every step re-reads the growing history. | Cap output sizes, summarise old results, and set a spend limit per task. |
| Complexity | Lowest of the model-driven patterns. | Resist adding structure until a measured problem demands it. |
| Failure modes | Loops, wrong tool choice, bad arguments, and unsafe writes. | Use step budgets, validation, confirmation, and clear error text. |
Compared with related types
A sequential pipeline fixes the order of steps in code, so it is cheaper and more predictable, but it cannot adapt. A single agent adapts but costs more and is harder to predict. Many good systems use a pipeline for the known parts and a single agent for the open-ended part.
A supervisor with workers splits one agent into a planner and several specialists. Reach for it when one agent has too many tools or its context overflows, not before. For the reasoning pattern inside the loop, see the ReAct agent.
What this means for your role
Common mistakes
Further reading
- Orchestration patterns: the hub that compares all orchestration patterns.
- ReAct (Yao et al., 2022): interleaves reasoning traces with actions such as tool calls, so the model can update its plan from what the tools return.
- Tool calling and MCP: how tools are described and called.
- Circuit breaker: protecting the loop from failing tools.
Start with one agent, a small set of narrow tools, and firm limits. Add structure only when your measurements show where this design stops being enough.