“Agent” is the default word for anything built with a language model right now. Ask for an AI feature and the first design on the whiteboard is a model with a bag of tools, running in a loop until it is done. Sometimes that is the right design. Often the feature is three known steps in a row, and a loop is the most expensive way to run them. The video above is the one minute version. This note is the rest.
Two definitions
The clearest line I know comes from Anthropic’s write-up Building effective agents, and it is about who owns the control flow:
- Workflow. Your code decides the steps and their order. The model does the work inside each step: classify this, extract that, write the answer.
- Agent. The model decides the steps. It gets a goal and a set of tools, and at every turn it chooses what to do next, until it decides it is finished.
Both use the same model and can use the same tools. The difference is where the if lives: in your code, or in the model’s output.
What a workflow looks like
A support assistant that answers questions about orders is a good example. The steps are known before the request arrives.
In code, it is a function you can read top to bottom:
async function answer(request: string) {
const intent = await classify(request); // one model call, fixed set of labels
if (intent === 'other') return handOffToHuman(request);
const order = await orders.findFor(request); // plain code, no model
return writeAnswer(request, order); // one model call
}
Two model calls, every time. The same input takes the same path. When the answer is wrong, you know which step to look at, and you can test each step on its own with a fixed set of examples.
What an agent looks like
Now take “fix the failing test”. You cannot write the steps down in advance. The model has to read the error, open a file, maybe search the code, change something, run the tests and look again. What it does next depends on what it just found.
async function runAgent(goal: string, tools: Tool[]) {
const history: Message[] = [{ role: 'user', content: goal }];
for (let step = 1; step <= MAX_STEPS; step++) {
const reply = await model(history, tools); // the model picks the next action
if (reply.done) return reply.answer;
const result = await runTool(reply.toolCall); // act
history.push(reply.message, result); // observe
}
throw new Error('Gave up after MAX_STEPS');
}
Think, act, check the result, repeat. This is what the loop is good at: problems where the path depends on what you find along the way.
What the loop costs
The flexibility is real, and so is the bill.
- More model calls. A workflow makes a known number of calls. An agent makes as many as it decides to, and each turn sends the growing history back to the model.
- Costs you cannot predict. The same request can take four steps today and eleven tomorrow. Budgets and latency targets get harder to promise.
- Mistakes compound. Every step can go a little wrong, and the next step builds on it. As an illustration: if each step were right 95% of the time and the steps were independent, ten of them in a row would all be right only about 60% of the time (0.95 to the power of 10).
- Harder to test. There is no single path to assert on. You end up evaluating outcomes over many runs instead of checking each step.
None of this makes agents bad. It makes them a tool you choose on purpose, not the default.
How I decide
I ask a few questions, in this order:
- Can I write the steps down today? If yes, it is a workflow. Branches are fine: routing a request to one of three fixed paths is still a workflow.
- Does the next step depend on what the last one found? Research, debugging and open ended coding are the classic cases. That is where an agent earns its cost.
- What happens when it is wrong? The more a mistake costs, the more I want a fixed path, a human approval, or both.
- Do I have a way to measure it? If I cannot evaluate the agent on real tasks, I am not ready to ship one.
The hybrid I end up building
In practice, most of my systems are workflows with one agentic step inside them. The intake, the validation and the final formatting stay in code. Only the part that really needs judgment runs as a loop, for example “investigate why this payment failed”, and it hands a structured result back to the workflow.
When I do put a loop in, it gets the same treatment as any other part of a production system:
- A step limit and a budget. The loop stops, and says it stopped, instead of running until someone notices the invoice.
- The smallest set of tools. Every tool is something the model can do on its own. Read-only first, writes only when they are worth the risk.
- Traces. Every turn is logged: what the model saw, what it called, what came back. Without that, a bad run cannot be debugged.
- Evals on real tasks. A fixed set of cases, run on every change, scored on outcome.
The same idea shows up in my other notes. In MCP in 60 seconds, the client is the boundary where you put confirmations and limits on what the model calls. In RAG vs CAG, the trade-off is how much to put in the context. Here, it is how much of the control flow to hand over.
This is a short guide, not a full framework. Latency targets, failure handling and how you evaluate the output all matter in a real design. But the default holds up well: keep the path in code, and give the model the decisions only where the path cannot be known in advance.