Skip to content
AI Engineering
Agents

Workflows vs agents

Pick the least autonomy that solves the problem. Agents are for tasks whose steps you cannot write down in advance.

Chapter 9: AgentsLesson 1 of 10Level: StarterAbout 12 min
Words on this page (7)
agent
: A model run in a loop that chooses its own tools and steps until the task is done.
workflow
: A fixed sequence of steps written in code, with model calls at set points.
token
: A piece of text the model reads and writes, usually a word or part of a word. About 4 characters of English on average.
latency
: The time you wait for a response.
retrieval
: Finding the most relevant pieces of text for a query.
tool
: A function the model can ask your program to run, described by a name, description and argument schema.
eval
: A repeatable test of AI output quality, run before and after every change.

What it is

A runs a fixed path in your code and calls the model at set points, such as classify, then draft, then check. An lets the model decide which step comes next. The first is predictable, cheap and easy to test. The second handles open-ended work and costs more in , and debugging.

How to choose

Can you list the steps ahead of time? Use a workflow. Does the task branch in ways you cannot predict, like fixing an unknown bug in a codebase? Use an agent, and give it a way to check its work. Start with a single model call with good context. Add , then , then a loop, only when the simpler form falls short on your .

A worked example: choosing

Task: tag each incoming support email as billing, bug or other. Steps are fixed: one model call per email. Use a workflow. Task: investigate why a customer's invoice is wrong. The steps depend on what is found. Use an agent with tools for invoices and account history, with limits and a person to approve changes.

What the extra autonomy costs

Take the email tagger and give it an agent loop. Invented numbers for illustration. The email is 500 tokens. Each tool result adds 300 tokens, and every call resends everything so far.

The workflow makes one call and sends 500 tokens. The agent makes four calls and sends 500, 800, 1,100 and 1,400 tokens, which is 3,800 in total. That is 7.6 times the input for a task that needed one call.

Cost is only part of it. The agent might also take a different route on each run, so the same email can get two different tags.

What goes wrong: an agent where a workflow would do

The symptom is a system that works in the demo and disagrees with itself in testing. Run the same 20 emails twice and count how many get a different tag. A fixed workflow, with randomness turned down where the model allows it, should disagree far less. If the agent disagrees often, the freedom it has is not buying anything.

A middle path: one loop inside a workflow

You do not have to pick one side. Keep the fixed steps in code and allow a loop in only the step that needs it. For the invoice question, fetching the invoice and the account can be two fixed calls. Only the step "work out why the totals differ" needs a loop. The loop then has a small job, a short step limit and a narrow set of tools, so it is cheap to test and hard to derail.

Common mistake

Building an agent because the word is exciting.

Check yourself

You can list the three steps of a task in advance. What fits best?

What should you do before adding an agent loop?

A task branches in ways you cannot predict, such as fixing an unknown bug. What fits?

Go deeper

Spotted a mistake or something unclear? Report it on GitHub.

On this page