Part 3 of 7 in the Enterprise AI Agent Engineering guide
Why this matters now
Imagine an invoice-exception agent in a finance shared-services team. It is asked to resolve a mismatch between an invoice and a purchase order. The vendor system returns incomplete data, so the agent rephrases its query and tries again. And again. Nothing tells it that it is stuck, so it keeps going overnight until a budget alert fires in the morning. The mismatch is still unresolved, and the compute bill is not small. (This is an illustrative scenario, not a customer case.)
The agent did what a loop does: observe, decide, act, repeat. The failure was that nobody designed how the loop should end.
Enterprises feel this because work arrives in volume and runs unattended. An agent that loops without limits turns a small defect into a large bill, a blocked queue or a pile of half-finished records. Organisations also run work across several teams, so a single task may pass between systems and, increasingly, between several agents. Every handoff is another place where progress can stall or context can be lost.
This is loop engineering: deciding how an agent repeats, when it stops and when it asks for help. It sits third in our series because it builds on context engineering and memory architecture and tool design and harness engineering. The loop is where context and tools come together.
The core concept
A loop is the repeating cycle in which an agent observes its context, decides its next step and acts, usually by calling a tool. Loop engineering sets the rules for that cycle: how many times it may run, what counts as progress, what counts as done and what forces a stop or a handoff to a person.
Orchestration is the coordination of several steps, loops or agents to complete a larger task. It answers different questions: which step runs first, who passes what to whom, what runs in parallel and who decides the task is complete.
The two depend on each other. Orchestration composes loops, so a poorly bounded loop inside a well-orchestrated system still fails. And a well-bounded loop cannot rescue an orchestration design that loses context at every handoff.
It helps to separate a workflow from a loop. A workflow follows steps you wrote in advance. A loop lets the model choose the next step. Anthropic's 2024 guide "Building effective agents" draws this same distinction and advises starting with the simplest approach that works, adding autonomy only when needed. We agree, and most enterprise tasks contain a mix: a fixed workflow for the predictable parts and a small, bounded loop for the uncertain part.
The shape of a well-engineered loop:
Observe (context assembled by the harness)
|
v
Decide next step --> Act (tool call through the harness)
^ |
| v
+---- continue <---- Check stop conditions
- goal met?
- step or cost budget spent?
- repeating the same action?
- needs a human? -> escalate
How it works in real systems
Scenario 1: Invoice exceptions. Instead of one open-ended agent, the design uses a fixed workflow for extraction and matching, which are predictable. Only the mismatch-resolution step is a loop, and it is bounded: a maximum number of steps, a rule that stops after the same query repeats, and an automatic handoff to a finance analyst with a summary of what was tried. The overnight run never happens, because the loop ends within minutes and passes the case to a person.
What the limits look like in practice. Limits belong in the harness, not in the prompt, so the agent cannot talk its way past them. An illustrative configuration for the invoice-exception loop:
loop_limits:
max_steps: 12
max_seconds: 180
max_cost: set per workflow
repeat_stop_after: 3 # same tool call, same arguments
on_limit: handoff_to_analyst
handoff_summary: [goal, steps_tried, current_state, evidence]
completion_check: totals_match_ledger # not "the agent says it is done"
The values are starting points to calibrate, not recommendations for your workload. The structure is what matters: three limits, a repeat check, a defined handoff and a completion check that does not depend on the agent's own claim. This is an example, not a customer configuration.
Scenario 2: Contract review. A review involves extracting clauses, checking them against policy and summarising risk. A team might use a supervisor agent that delegates to specialist agents for each part. This helps when the parts need different tools, permissions or context, since each specialist sees only what it needs. It also adds cost: every handoff carries a summary, and anything left out of that summary is lost to the next agent.
Impact. Bounded loops improve reliability and cap cost. Fewer unnecessary steps reduce latency. Clear stop and escalation rules lower risk, because uncertain cases reach people sooner. Simpler patterns are easier to test and explain, which supports adoption.
Design decisions and trade-offs
| Decision | Option A | Option B | Choose A when | Choose B when |
|---|---|---|---|---|
| Control | Fixed workflow | Model-directed loop | Steps are known and stable | The path depends on what the agent finds |
| Agents | Single agent | Several specialist agents | One context and tool set suffices | Parts need different tools, permissions or context |
| Execution | Sequential | Parallel | Steps depend on earlier results | Steps are independent and speed matters |
| Stopping | Agent decides when done | Harness enforces limits | Never as the only control | Always, in addition to the agent's own judgement |
| Planning | Decide step by step | Plan first, then execute | The task is short or exploratory | The task is long and needs review of the plan |
When not to use multiple agents: if one agent with a clear tool set can do the task, adding more agents adds handoffs, cost and new failure points without a clear gain. Add a second agent only when you can name the problem it solves, such as separated permissions or a context that grows too large.
What breaks in production
| Failure mode | Symptom | Root cause | Mitigation |
|---|---|---|---|
| Runaway loop | Run continues long after it should have ended, cost spikes | No step, time or cost limit | Hard limits enforced by the harness, plus alerts |
| Thrashing | Agent repeats the same or near-identical action | No repeat detection, error messages give no direction | Detect repeated calls, stop and escalate after a set number |
| Goal drift | Agent works on a related but wrong task | Goal restated loosely over many steps | Keep the goal fixed in context, check progress against it |
| Handoff context loss | Second agent redoes work or contradicts the first | Summary at handoff omits key facts | Structured handoff records with required fields |
| False completion | Agent reports done when the task is only partly finished | Completion judged by the agent alone | Verify against a checklist or independent check before closing |
| Cascading errors | One agent's mistake spreads through the chain | Downstream agents trust upstream output | Validate outputs at each handoff, isolate failures (see evals for agents) |
Enterprise Decision Framework
Choose the simplest pattern that fits, and move to the next row only when a measured failure justifies it. All limits are recommended starting points; calibrate to your environment.
| If the task... | Choose | Minimum controls |
|---|---|---|
| Has known steps and little variation | Fixed workflow | Step validation, trace |
| Has known steps plus one uncertain step | Workflow with one bounded loop | Step limit, repeat detection, human handoff |
| Depends on what the agent discovers | Single-agent loop | Step, time and cost limits, repeat detection, human handoff |
| Is long and benefits from a reviewed plan | Planner and executor | Plan approval, progress checks against the plan |
| Needs different tools, permissions or context per part | Supervisor with specialist agents | Structured handoffs, per-agent limits, output validation |
Required for every loop, whichever row applies:
- A maximum number of steps, a time limit and a cost limit, all enforced by the harness.
- Detection of repeated actions, with a stop after two or three repeats as a starting point.
- A defined handoff to a person when limits are reached or confidence is low (see human-in-the-loop design).
- A completion check that does not rely only on the agent saying it is done.
If you cannot name the stop condition, do not release the loop.
Worked example. Suppose a team has to choose a pattern for three tasks. This is an illustrative review, not a customer result.
| Task | Pattern | Why | Minimum controls |
|---|---|---|---|
| Password reset requests | Fixed workflow | Steps are known and rarely vary | Step validation, trace |
| Invoice mismatch resolution | Workflow with one bounded loop | Extraction and matching are predictable; only the mismatch step is uncertain | Step limit, repeat detection, handoff to an analyst |
| Contract review across clause, policy and risk checks | Start with a single agent; move to specialists only after a measured failure | One context may be enough. Add specialists only if parts need different tools, permissions or context | Structured handoffs, per-agent limits, output validation if specialists are added |
The rule behind the table is to choose the simplest pattern that fits, and to move down a row only when a measured failure justifies it. In every row the harness still enforces step, time and cost limits.
What to do in the next 30 days
- Map every agent task to a pattern. Owner: AI architect. Outcome: a one-page table placing each task in a row of the decision framework, completed in week one.
- Add harness-enforced limits. Owner: platform engineer. Outcome: step, time and cost limits active on every loop by week two.
- Implement repeat detection and escalation. Owner: engineering lead. Outcome: a test where a deliberately stuck agent stops and hands off with a summary, passing by week three.
- Define completion checks. Owner: product owner for the workflow. Outcome: a written, verifiable completion rule for each task, agreed by operations.
- Review multi-agent designs. Owner: head of AI. Outcome: each multi-agent design is either justified in writing or simplified by day 30.
Closing thoughts
Reliable agents are bounded agents. Our practitioner's view is that most enterprise tasks need less autonomy than a first design assumes, and that the discipline of stop conditions and handoffs matters more than the number of agents involved. The next post looks at guardrails and permissions, which limit what an agent is allowed to do inside the loop. If useful, download the checklist below, or talk to our architects about a loop and orchestration review for your agent.
Free checklist: Loop and Orchestration Design Review
Download the Loop and Orchestration Design Review checklist
A one-page, 14-point checklist your architects and risk team can use in the next design review.
Quick self-check
Tick the statements that are true for your agent today. The same checklist is available as a PDF above.
Pattern selection
Limits
Stop and handoff
Completion and handoffs
Frequently asked questions
What is an agent loop?
An agent loop is the repeating cycle in which an agent reads its context, decides its next step and acts, often by calling a tool, until a stop condition is met. Loop engineering defines how many times it can repeat, what counts as progress and when it must stop or ask a person for help.
When should I use multiple agents instead of one?
Use multiple agents when parts of a task need different tools, permissions or context, and a single agent cannot hold them safely. If one agent with a clear tool set can do the job, stay with one. Extra agents add handoffs, cost and new places for errors.
How do you stop an AI agent from looping forever?
Enforce limits in the harness, not only in the prompt: maximum steps, time and cost per run. Add repeat detection so the agent stops after the same action recurs, and define a handoff to a person. Also verify completion independently rather than trusting the agent's own claim.
What is the difference between a workflow and an agent?
A workflow follows steps written in advance, so the path is fixed. An agent chooses its next step based on what it finds, so the path varies. Many enterprise tasks combine both: a workflow for predictable steps and a bounded agent loop for the uncertain one.
What should an agent handoff contain?
A handoff should carry the goal, what has been done, what remains, the evidence gathered and the reason for the handoff. Anything left out of the summary is lost to the next agent or person, so write the summary format as a fixed structure rather than free text.
What limits should an AI agent loop have?
At least three, enforced by the harness: a maximum number of steps, a time limit and a cost limit. Add detection of repeated actions, and a defined handoff to a person when a limit is reached. The numbers are starting points; calibrate them against your own workflow and review them as the agent changes.
Should I start with a multi-agent system?
No. Start with the simplest pattern that fits, which is often a fixed workflow with one bounded loop. Add a second agent only when you can name the problem it solves, such as separated permissions or a context that grows too large, because every handoff adds cost and a new failure point.
Scenarios and examples in this guide are illustrative, not customer cases. Thresholds and intervals are recommended starting points; calibrate to your environment. Last reviewed: October 2026.
Put this into practice
Tell us about the workflow you want an agent to own. We map the controls, the failure modes and the measurement before any build starts.