Free sample lesson · Building Reliable AI Agents
Choose the Path Before the Model
A damaged mug, two orders: who chooses the next step?
Lesson 1 of the Wondering course Building Reliable AI Agents
Two Orders, One Decision
Maya’s mug arrives damaged, but she has two orders: O17, a blue mug, and O18, a white plate.
Who chooses the next step: code or the model? Code means logic written in advance, so it does the same thing every time. The model means a large language model (LLM), the AI system interpreting messages and proposing replies or actions while the conversation is happening.
Some steps are already known. The store’s invented policy requires damage evidence and staff approval before a refund runs. Those checks are the refund’s gates, steps that must pass before the next one starts. They happen the same way every time, so they are predictable.
Other things are not known yet. If Maya doesn’t say which order holds the mug, the system is missing information. That missing information is the uncertainty, and it decides who should choose the next step.
Code should control predictable refund gates. A model may choose how to gather missing information, such as which order Maya means.
- Code
- Model
Choose the smallest design that can do the job. Extra autonomy adds decisions without improving a known path.
Fixed Paths Can Use Models
Does one LLM call make a workflow an agent? No.
In a fixed workflow, code selects the path, even when a step calls a model. Workflows follow predefined routes.[[1]](https://www.anthropic.com/research/building-effective-agents)
In prompt chaining, code sends one model call’s result into the next call. In our fictional refund example, the first call summarizes Maya’s damage report. Code passes that summary to a second call that drafts the refund proposal. The model writes each result; code fixes which call runs next.
Code can also check for recorded staff approval before allowing the payment step. If approval is missing, that step does not run.
For the fictional refund, a model may draft the proposal, but code still waits for recorded staff approval before the payment step. The model call has not gained control over that route.

Anthropic’s prompt-chain diagram includes a gate between model calls. · Anthropic, Building effective agents (2024).
For Maya, code can check evidence, prepare the refund proposal, request staff approval, execute, and verify in sequence.
Let Uncertainty Choose
Maya only says, “The mug broke.” Which order should the system inspect?
An agent lets the model dynamically direct its own process and tool use.[[1]](https://www.anthropic.com/research/building-effective-agents) Here, within the application’s boundaries, it can look up orders or ask Maya to clarify.
After a lookup, it reads the result. If O17 appears, control returns to the fixed refund gates.
- Routes and dispatchers
A model-selected route does not authorize bypassing staff approval.
Autonomy Is Not Permission
Suppose the model confidently says, “Refund approved.” Did approval happen?
The fictional policy requires damage evidence and staff approval before execution. Those gates remain in code, regardless of the model’s wording.
Autonomy is not permission. An eloquent answer is not evidence that a tool ran or a refund completed.
In this refund design, the model may suggest a next step. Staff approval must still be recorded before code can issue payment. Choosing a helpful action and having permission to carry it out are separate questions.
Feedback Needs an Exit
What should happen when a complete order lookup finds nothing?
An agent loop chooses an action, reads actual feedback, then continues, asks for help, or stops within explicit bounds.[[1]](https://www.anthropic.com/research/building-effective-agents)
Anthropic describes those controls: agents gain ground truth from the environment at each step, can pause for human feedback at checkpoints, and often include stopping conditions.[[1]](https://www.anthropic.com/research/building-effective-agents)

Anthropic, Building effective agents (2024).
Here, a complete search with no matching order triggers a request for the order reference and pauses refund execution.
A partial search is different: some results remain unseen. The matches you have not seen might include O17, so “not shown” does not mean “not found.”
You have two ways to see more:
- Narrow the query: search again with a more specific filter, such as the item “blue mug,” so fewer matches come back.
- Continue: ask the tool for the next page of results.
The search budget, like other iteration limits, is a product choice, not a universal default.
So if the tool says more results remain, narrow the query or continue to the next page within that budget. If the budget runs out, ask for help without claiming the order is absent. Repeating lookup forever is not recovery.
Sketch the Allowed Path
Sketch the allowed path before writing prompts.
Known item: code checks evidence, prepares a proposal, gets staff approval, executes, then verifies.
Missing order: the model chooses lookup or clarification. The lookup result must be visible before another action.
Incomplete search: narrow or continue within the search budget; ask for help if the budget runs out. Complete search, no match: ask for the order reference and pause. No approval: stop the refund action and notify staff; never execute.
- Order known?: Is the damaged item's order identified?
- Model: lookup or clarify: The lookup result must be visible before another action.
- Search complete?: Has the tool returned all relevant results, rather than a partial slice?
- Narrow, continue, or ask: Inspect remaining results within the search budget; otherwise ask for help without claiming absence.
- Match found?
- Ask reference, pause: Ask for the order reference and stop.
- Code: evidence, proposal: Code checks evidence and prepares a proposal.
- Staff approved?
- Stop and notify staff: Do not issue payment without recorded staff approval.
- Execute, then verify
- Read result
This design reads actual results and stops when information or permission is missing. If a proposed loop repeats lookup until success, add the missing no-match feedback branch and stopping condition.
Check yourself
A workflow with one LLM call is _____.
- a fixed workflow when code selects the path
- automatically an agent because it calls an LLM
Answer: a fixed workflow when code selects the path
An LLM call does not make a system an agent. If code selects the route and the model operates within that predefined route, it remains a fixed workflow.
Maya has identified the order containing her damaged mug. Which design is the smallest adequate workflow for processing the refund?
- Let the model decide every refund step from the customer’s message
- Use code for evidence, proposal, approval, execution, and verification
- Ask the model to announce approval, then execute the refund automatically
- Repeat model calls until one confidently recommends a refund
Answer: Use code for evidence, proposal, approval, execution, and verification
Code should handle the predictable sequence: check evidence, prepare the proposal, obtain staff approval, execute, and verify. Model autonomy is unnecessary when the path is already known.
A search returns no matching mug and says no further results remain. Maya has not supplied an order reference. What should happen next?
- Try the identical lookup again until it returns a matching record.
- Ask Maya for the order reference and pause the refund action.
- Search progressively older records without setting an end condition.
- Choose the nearest item description and send that refund for approval.
Answer: Ask Maya for the order reference and pause the refund action.
This search is complete, so repeating the same lookup adds no new evidence. Ask for information that could identify the order. An unlimited broader search lacks a stopping condition; a near match is not evidence that the damaged item belongs to that order.
Keep going
This is lesson 1 of 8 in Building Reliable AI Agents. Next up:
- Make Tools Hard to Misuse
- Connect Tools Without Granting Trust
- Give Each Decision the Right Context
- Check Authority Before Money Moves
- Retry Without Refunding Twice
Wondering turns any topic into short lessons you can read, watch, or listen to, with practice questions and an AI tutor.