AlgoViz

When to choose an agent

medium 7 min

An agent is a control decision about who chooses the next operation.

Video lesson · Chapter 1 of 4

One parcel, one lookup

0:00 / 3:22

Theory

Read or listen first. About 3 min.

What it is

An agent is a control decision about who chooses the next operation. A model call, deterministic workflow and model-directed loop offer different levels of flexibility. Retrieval is an evidence mechanism that can be used in any of them.

Why it exists

Start with one real task and identify what cannot be decided ahead of time. Choose autonomy where observing the environment changes the next useful action, then evaluate whether its benefit justifies the additional paths, cost and recovery burden.

Choose between a form, a lookup and an agent

Desired outcome → Control choice (identify uncertainty). Control choice → Task acceptance (test chosen control)
Desired outcome → Control choice (identify uncertainty). Control choice → Task acceptance (test chosen control)

Inside this chapter

Chapter sources
What agent engineering covers
An agentic application combines model decisions with a controlled execution environment. Start by defining what decisions may vary, what actions exist and what constitutes success. A useful first exercise compares a fixed return-policy workflow with a task whose next step depends on what the last lookup revealed.

Agent engineering is less about the model and more about the box you put it in. You decide which decisions may vary at run time, which actions exist, what each action is allowed to touch and how you will know the task succeeded. The model only fills in choices inside that box. A good first exercise is to write down a fixed workflow for the task and then mark the exact points where a fixed rule cannot pick the next step without seeing an intermediate result.

Example. Trace a read-only shipment question first. Add an ambiguous follow-up and identify which next action now depends on the previous response.

Another example. A returns bot with one policy (30 days, unused, receipt) needs no agent: it is a form plus a rule check. A warranty bot that must first find which of three product lines the serial belongs to, then pick a different evidence source for each, has a genuinely data-dependent next step.

Where the next step stops being fixed

The first lookup is fixed. What happens next depends on what the lookup returned, and that is the part worth designing carefully.
What a working agent must demonstrate
To demonstrate agent engineering, trace one request from goal to observable outcome. Name the state, allowed actions, stop rule, evidence and recovery path. Test a missing prerequisite as well as the successful case. These artifacts show whether the application can be operated and evaluated.

If you cannot point to each of these for a single failed run, the system cannot be operated. Missing state means you cannot resume, a missing stop rule means it runs until something external kills it, and missing evidence means success is whatever the model claimed. Test the unhappy path on purpose: remove a prerequisite such as the party size and check that the run asks for it rather than guessing.

Example. Take one failed booking and record the goal, allowed actions, observations, stop reason and final business state. Identify any missing artifact.

Another example. A coding agent's trace should show the issue (goal), the branch and files touched (state), the commands it may run, the stop rule (tests green or 20 steps), the test output (evidence) and how a half-applied change is reverted.

Six artifacts for one traced booking

  • Goal

    Book a table for 4 at 19:00 on Friday

  • State

    Restaurant ID, party size, holds made so far

  • Allowed actions

    search, hold, confirm, ask user

  • Stop rule

    Confirmed booking, user handoff or budget spent

  • Evidence

    Booking reference returned by the venue system

  • Recovery path

    Release the hold if confirmation fails

The Evolution of AI Systems
A single model call transforms input to output. A workflow connects predetermined transformations. An agent delegates some choice of next operation to a model. Moving along this spectrum introduces more possible trajectories, so the application needs stronger observability, bounded resources and clear ownership of side effects.

Moving down this spectrum is a trade, not an upgrade. Each extra model-directed decision multiplies the number of possible runs, so a fixed two-step lookup has one path while a loop that may clarify, look up again or hand off has many. That is why agents need budgets, traces and a clear owner for every write: the application must stay safe on paths nobody drew in advance.

Example. Compare a fixed two-step lookup with a loop that can ask for clarification. Count the additional transitions the second design must test.

Who picks the next operation

DesignNext step chosen byPaths to testWhat you must add
Single model callnobody, one step1input and output checks
Fixed workflowcode, written in advancea few, all knownper-step tests
Workflow with a clarify branchcode plus one model decisionknown paths x clarify outcomesbranch tests, turn limits
Agent loopthe model, inside allowed actionsgrows with every steptracing, budgets, side-effect ownership
Each row delegates more choice to the model, so the set of possible trajectories grows and so does the testing and observability burden.
What Is an "Agent"?
An agent observes state, selects an allowed action and uses the resulting observation to continue or stop. The host grants capabilities and checks them independently. A parcel assistant may choose which order to inspect, while the host restricts access to orders belonging to the authenticated customer.

The defining property is the feedback edge: the result of one action changes what the model chooses next. The permission check sits in the host, not in the prompt, because a model can be talked into proposing anything. In practice you notice a weak boundary when the only thing stopping a cross-customer lookup is an instruction in the system prompt.

Example. A tool returns two possible orders. The agent can ask which one the user means; it cannot grant itself access to a different customer.

Another example. A calendar assistant may decide which free slot to propose, but the calendar API only accepts writes to calendars the signed-in user owns, whatever the model asks for.

Observe, choose, check, observe again
  1. 1Observe stategoal plus the last tool result
  2. 2Choose an actione.g. look up order 42
  3. 3Host checks capabilityis order 42 this customer's?
  4. 4Record observationtwo orders match the name
  5. 5Continue or stopask which order, or answer
Repeat: back to Observe state

The model chooses; the host grants. A choice the host refuses never runs.

Agent vs RAG vs Workflow Automation
RAG describes how a system obtains evidence. A workflow describes who controls the order of steps. An agent describes a system with some model-directed decisions. These properties can coexist. A fixed retrieval pipeline can answer a policy question without delegating routing to a model.

These three words answer different questions, which is why they are not alternatives. RAG says where evidence comes from, workflow says who fixes the order of steps, and agent says that some choice of next step belongs to the model. A system can be a fixed workflow that uses RAG, or an agent that never retrieves anything. Name each property separately in a design review so nobody argues past each other.

Example. Build a fixed retrieval-and-answer route, then add conditional routing only for ambiguous cases. Both versions still use RAG.

Retrieval inside a fixed route and a routed one

Both branches use RAG. Only the lower branch delegates a routing choice to the model.
When NOT to Use Agents
When the required inputs, route and acceptance rule are known in advance, deterministic orchestration is easier to test and cost. Escalate to model-directed control when variability has measurable value. For an address change, a validated form plus an authorized update may satisfy the entire task.

Deterministic orchestration wins whenever you can write the inputs, the order and the success check down before the request arrives. It is cheaper, faster, easier to cost and every path can be unit tested. Reach for model-directed control only where you can show a measurable gain on real tasks, such as fewer handoffs on genuinely ambiguous requests.

Example. Changing a mailing address needs validated fields and authorization. Determine whether any next-step decision actually requires a model.

Another example. Resetting a password, updating a phone number and downloading an invoice are all form-shaped. Diagnosing why a webhook stopped firing, where the next check depends on the last log line, is not.

Is a model decision actually needed?

For an address change every answer is yes, so the deterministic route is cheaper to test and run.

How it works

Step through the idea, or press Play.

Step 1 of 3

Desired outcome. “Where is order 42?”

Understand it

Worked example

Choose between a form, a lookup and an agent

  1. 1

    “Where is order 42?”

    The request has a known input, a single authorized lookup and a verifiable result. Identify where, if anywhere, decisions must adapt.

  2. 2

    Use the fixed lookup

    A deterministic route is sufficient for the stated task. A follow-up with missing identity or several conflicting orders may need clarification.

  3. 3

    Correct order and owner

    Compare approaches by success, latency and unnecessary actions on the same tasks. Variation in prose alone is weak evidence for adding autonomy.

Follow the handoffs

Start with one real task and identify what cannot be decided ahead of time. Choose autonomy where observing the environment changes the next useful action, then evaluate whether its benefit justifies the additional paths, cost and recovery burden.

Which design each request variant needs

Most traffic takes the fixed path. Only the clarification branch has a next step that depends on an intermediate observation.

Compare designs on the same task set

DesignCorrect order and ownerLatencyUnnecessary actions
Formonly if the user types the IDlowestnone
Fixed lookupyes on labelled lookupslownone
Agent loopyes, plus clarifies conflictshigherpossible repeat lookups
Qualitative comparison. Measure all three on the same requests before adding autonomy; nicer prose alone is weak evidence.

Summary

The whole topic in one minute.

A model-directed decision should solve an observed source of variability and improve outcomes enough to justify its extra operational complexity.

Start with one real task and identify what cannot be decided ahead of time. Choose autonomy where observing the environment changes the next useful action, then evaluate whether its benefit justifies the additional paths, cost and recovery burden.

Sources