Skip to content
Guide · Foundations

Agentic workflows 101: when to let a model run the loop

An agent is a model with tools, a goal and permission to keep going. This guide explains the loop, how to design tools and stopping conditions, and when an agent genuinely beats a fixed pipeline.

Updated 6 Nov 2026 · 9 min read · By Teksmobile AI practice

Three shapes of LLM system

Most confusion about agents comes from using one word for three different things. It helps to name them.

A pipeline is a fixed sequence of steps, some of which call a model. Extract the invoice fields, validate them, post to the ledger. The code decides the order; the model fills in a step. This is how most document processing works, and it is the right shape for anything repetitive and well understood.

A workflow with LLM decisions adds branching. The model classifies a ticket, and the code routes it. The model still does not choose what happens next beyond a menu you defined.

An agent inverts control. You give the model a goal and a set of tools, and it decides which tools to call, in what order, how many times, until it judges the goal met. The code's job becomes enforcing limits rather than dictating steps.

The further right you go on that spectrum, the more the system can handle situations you did not anticipate, and the less you can predict what it will do. That trade is the whole subject of this guide.

The loop

Agent loop: from a goal the model plans, acts by calling a tool, observes the result and checks whether it is done; if not it re-plans. Guard-rails around the loop enforce budgets, permissions, approvals and tracing GUARD-RAILS: step and spend budgets · user-scoped permissions · approval for writes · full trace of every run Goal Plan Act call one tool Observe read the result Check done? limit hit? yes Result plus the trace no: re-plan with what was learnt tools: search, CRM, calendar, email draft Each pass through the loop costs tokens and time; the budget, not the model, decides when to stop.
The agent loop. Everything inside the outer box is the model's decision; the outer box itself is yours.

Every agent, whatever the framework, is this loop. The model is given the goal, the conversation so far and the list of tools. It produces either a final answer or a request to call a tool. The code executes the tool, appends the result and calls the model again. It stops when the model answers, when a step or spend budget is exhausted, or when a check fails.

The quality of an agent is decided far more by what surrounds the loop than by the model inside it: the tools, the stopping rules, the permissions and the trace.

Tool design decides everything

A tool is a function the model can call, described in words. The description is the model's only documentation, so write it for a capable new colleague: what it does, when to use it, what it returns and what it must not be used for.

  • Narrow beats general. get_order_status(order_id) is called correctly; query_database(sql) is called creatively.
  • Return only what the next step needs. Large results flood the context window and bury the useful part.
  • Make errors recoverable. "No order with that id; the customer may have used a reference number" lets the model try again sensibly.
  • Separate reads from writes. Reads can be free; writes need permission, confirmation or both.
  • Standardise the plumbing. If more than one assistant needs the same tools, serve them through MCP, as described in MCP explained.

A useful test: could a careful human do the task with only these tools and these descriptions? If not, the agent cannot either. More on this in tool use.

Stopping conditions and budgets

The model should never be the only thing deciding when to stop. Set three limits in code: a maximum number of steps per run, a maximum token or spend budget per run, and a daily cap per user or tenant. Add a wall-clock timeout. When any limit trips, the agent returns what it has, with a clear statement that it stopped early, and the run is flagged for review.

Also define what "done" means before you start. "Reply to the customer" is not a stopping condition; "a draft reply exists, cites the relevant policy and has been queued for approval" is. Vague goals are the single biggest cause of agents that wander.

Where the human sits

Autonomy is a dial, not a switch. The patterns below are listed in order of increasing independence; most production agents live in the middle.

PatternWho actsUse when
SuggestAgent drafts, human does everythingConsequential or customer-facing output; early in a rollout
ApproveAgent acts after a human approves each writeWrites to systems of record, payments, external communication
NotifyAgent acts, human is informed and can reverseReversible actions with a clear audit trail
Autonomous within boundsAgent acts; only exceptions reach a humanLow-risk, high-volume, well-measured tasks

Move one step along the dial only when the evaluation numbers say the previous step is reliable. This is the approach behind our customer support AI and sales copilot solutions, which both start at "suggest".

When an agent beats a pipeline

Agents are worth their unpredictability when the path to the goal genuinely varies case by case and the tools to discover it exist. They are not worth it when the path is known.

SituationPipelineAgent
Same steps every time (invoice extraction, nightly report)YesOverkill and less predictable
Steps depend on what is found (investigate a failed payment)Branches explodeYes
Needs to combine several systems ad hoc (prepare for a client meeting)RigidYes, with read-only tools
High-stakes, irreversible action (send payment)Yes, with model-assisted stepsOnly with approval pattern
Strict latency or cost per requestYesLoops are slow and variable

A useful compromise is a pipeline whose steps are small agents: a fixed outer structure, bounded autonomy inside each step. It gives you predictability where you need it and flexibility where it pays.

Failure modes to design out

How agents go wrong in production

Runaway loops. The model keeps calling the same tool with slightly different inputs. Fix: step budgets and a check for repeated calls.

Cost blow-ups. Each step carries the whole history; long runs get expensive fast. Fix: spend budgets, summarising context, smaller models for routine steps.

Wrong tool, confidently. Overlapping or vaguely described tools. Fix: fewer, narrower tools with precise descriptions.

Instructions in the data. A fetched web page or email tells the agent to do something else. This is prompt injection; fix with treating tool results as data, least privilege and approvals.

Silent partial success. Three of five updates applied, then a limit hit, and nobody told. Fix: transactional patterns or explicit reporting of what was and was not done.

Every one of these should be a test case. Our AI red teaming service builds adversarial suites for exactly these behaviours.

Evaluating an agent

You cannot evaluate an agent by reading a few transcripts. Build a set of tasks with known good outcomes, run the agent against them repeatedly, and measure task success, steps taken, cost per run and the rate of unsafe actions attempted. Record the full trace of every run in production and sample them for review. Treat a drop in task success or a rise in steps as a regression, exactly as you would a failing unit test. The method is laid out in evaluating LLM outputs; the guardrails entry covers the runtime side.

A sensible first agent

Pick an internal, read-mostly task that people find tedious and that touches two or three systems: preparing a customer summary before a call, triaging an inbox, investigating a failed job. Give it three or four narrow tools, a step budget of a dozen, and the "suggest" pattern. Run it on a hundred real cases, review the traces, fix the tools. Only then consider a write tool with approval. This is the path our AI agents and automation engagements follow, and it rarely takes more than a few weeks to reach something people use daily.

Key takeaways

  • Pipeline, workflow and agent are different shapes; choose by how much the path varies.
  • The loop is simple; tools, stopping rules, permissions and traces decide the outcome.
  • Write narrow tools with descriptions a new colleague could follow.
  • Enforce step, spend and time budgets in code, never in the prompt.
  • Start at "suggest" and move along the autonomy dial only when the numbers justify it.
  • Treat tool results as untrusted; a web page can instruct your agent.
  • Evaluate on repeated task runs and keep every trace.
FAQ

Frequently asked questions

What is the difference between an agent and a chatbot?

A chatbot answers. An agent acts: it decides which tools to call, calls them, reads the results and keeps going until the goal is met or a limit is hit. A support chatbot that can also issue a refund through a tool, with approval, is an agent for that part of the conversation.

Are agents reliable enough for production?

For bounded tasks with good tools, clear stopping conditions and a human approval step on consequential actions, yes. For open-ended tasks with vague goals and unlimited autonomy, not yet. The design choices in this guide are what separate the two.

Do we need a framework to build an agent?

No. The loop is a few dozen lines of code around a model API. Frameworks help with tracing, retries and tool plumbing, and can get in the way when you need to understand why a run went wrong. We often start without one and add tooling once the shape of the agent is settled.

How do we stop an agent running up a huge bill?

Budgets at three levels: maximum steps per run, maximum tokens or spend per run, and a daily cap per user or tenant. Enforce them in code, not in the prompt, and alert when runs approach the limit.

Ready to make AI work in production?

Tell us about your systems, your data and your constraints. We reply within one business day with a straight answer and a suggested next step.