g↗genai/ learner
Tools and agents / Lesson 02

Workflows versus agents

Some AI systems follow steps that code has already fixed. Others let a model choose the next step while the system runs. Knowing which one you are building changes how you test, limit and trust it.

Concept + interactive labBeginner friendly
Two paths side by side. On the left, tickets ride a conveyor past identical stations on fixed rails. On the right, a small robot stands at a fork in a road and chooses its own way.
Fixed stations on the left. A chosen path on the right.

Who picks the next step?

This lesson uses three terms. They are defined here and used the same way throughout.

  • Workflow: the code decides which steps run and in what order, using rules written in advance. A model may run inside a step.
  • Agent loop: the model chooses the next step while the system runs. The system runs that step, the model reads the result, and it chooses again until it stops.
  • Combination: fixed steps around one or more agent loops.

In this lesson, a step is one thing the system does, such as looking up an account. A tool is a function the system runs on the model's behalf. “Run a tool” in the diagram means the system runs that function.

Key question: at run time, does the code or the model choose the next step?

Think of a recipe card. It lists the steps in order. A cook who tastes the dish and decides whether to add salt or simmer longer is making choices as they go. The comparison breaks down in one important way: a model's choice can be wrong, so an agent loop needs limits on how many steps it can take.

A workflow: the code sets the order.

Take one support ticket: “I was charged twice on my latest invoice.” A workflow handles it with three fixed steps. Every ticket runs the same steps in the same order.

  1. Classify the ticket by topic. This one is billing.
  2. Check its urgency. The system looks for words such as “urgent”, “outage” or “blocked”. This ticket has none, so its urgency is low.
  3. Route the ticket to the billing team.
A workflow diagram titled: the code sets the order. Three steps run one after another: Classify ticket, Check urgency and Route ticket, with arrows pointing down from one step to the next. Below, an example outside the ticket shows the same fixed order at a library desk.
Each step runs in order. The code decides what comes next.

The steps can be keyword rules or model calls. What makes this a workflow is that the code decides what runs next.

Outside the ticket: a library desk checks your card, then the due date, then prints the receipt. The clerk does not change that order based on which book you borrowed.

An agent loop: the model picks each step.

Now a different ticket: “My account is locked and I cannot log in.” In an agent loop, the model chooses the next step. It might choose to look up the account. The system runs that lookup and returns the result. The model reads the result and chooses again.

  1. The model picks a step, such as looking up the account.
  2. The system runs the step and returns the result.
  3. The model reads the result, then either picks another step or stops.
Two panels side by side. On the left, a workflow: Classify ticket, Check urgency and Route ticket in a fixed order. On the right, an agent loop: Model picks next step at the top, Run a tool at the right and Model reads result at the left. Arrows go clockwise around the loop, and a dashed Stop box sits below Model reads result.
The model chooses the next step after each result.

Because the model chooses, two runs on the same ticket can take different paths. A loop with no limit can keep going, so an agent loop needs a maximum number of steps and a way to stop.

Outside the ticket: you call a courier about a late parcel. You read the answer, then decide whether to check the depot or wait another day. Each answer shapes the next choice.

A coded branch is still a workflow.

A workflow can branch. In one version of the ticket system, a rule checks the classification confidence after urgency is assessed. If the confidence is below 0.70, or the category is “other”, the ticket goes to an extra review step. Otherwise it goes straight to routing.

The rule is written in code, so the code still picks the path. That keeps this a workflow. In this example, the classifier is a simple keyword scan, which keeps the rule easy to follow. The confidence is a score from 0 to 1 that the classifier reports for its own answer. Here it comes from that simple scan, so treat it as an illustration, not a measured accuracy.

Common mix-up: a model call inside a fixed step does not make the system an agent. The model writes or classifies, but the code still decides which step runs next.
Outside the ticket: a school office checks each permission form. If the parent's signature is missing, the form goes to the head teacher; otherwise it is filed. The rule is written down in advance, so the clerk does not choose the path.

Quick questions:

  • Does a branch make a system an agent? No. A branch chosen by a coded rule is still a workflow.
  • Does calling a model make a system an agent? No, not by itself. The question is whether the model chooses the next step.
  • If the model picks an action, then reads the result and picks again, is that a loop? Yes. That is an agent loop.

Many systems mix the two.

A common design keeps most steps fixed and gives one step to an agent loop. For the locked-account ticket, the system might:

  1. Intake (fixed): save the ticket and record the customer's plan.
  2. Investigate (agent loop): the model looks up login records, asks for more detail if needed, and decides when it has enough.
  3. File ticket (fixed): write the summary and route the ticket.
A hybrid flow with three steps. Intake is fixed. Investigate is a dashed agent loop, where the model looks up login records, asks for more detail if needed and decides when it has enough, with a maximum number of steps. File ticket is fixed. A side panel compares it to a restaurant kitchen: take the order and serve the dish are fixed, and adjust and taste is the agent loop.
Keep the open-ended step small, and cap how many steps it can take.

The fixed steps are easy to test and audit. The open-ended step handles cases that are hard to specify as rules in advance, and it is the hardest part to test. This is one common pattern, not a rule.

Outside the ticket: a restaurant kitchen works the same way. Taking the order and serving the dish are fixed steps. In between, the chef decides how to adjust the dish, and tastes again until it is right.

Sort five systems.

Try it in this order:

  1. Read the description and note what the system does first.
  2. Ask: does the code or the model choose the next step?
  3. Choose workflow, agent loop or combination. You can change any answer.
Workflow, agent loop or combination?PRACTICE
  1. 1. Every ticket is classified, then checked for urgency, then routed, in that order.
  2. 2. The model reads a ticket and chooses to look up the account or ask the customer a question. It reads the reply and chooses again until it is ready to route.
  3. 3. Intake and filing always run. In between, the model decides how many records to look up, and keeps looking until it judges it has enough.
  4. 4. Every ticket runs three fixed steps. One of them calls a model to write a one-sentence summary. The code always moves to the next step.
  5. 5. A trip planner uses a model that searches for flights, reads the prices, and chooses whether to search another date. It keeps going until the model judges the plan good enough, then stops.
0 of 5 correct

These are short, simplified descriptions written for this lesson. They are not descriptions of any real product. Real systems can mix these patterns in ways this lab does not show.

✎ Try it yourselfKnowledge check · Practice only

Check your understanding.

A support system runs three steps in a fixed sequence. One step calls a model to write a one-sentence summary. The model is never asked which step to run next. What is this system?
THE TAKEAWAY

Take this with you.

Ask who picks the next step. If the code does, it is a workflow, even with a branch or a model call inside a step. If the model picks the next step and the system loops, it is an agent loop. Many real systems combine fixed steps with one open-ended part, and they keep that part limited.

Back to Chapter 9: Tools and agents →