Papa Programmer
Lesson 03 of 20

Workflows or agents?

7 min read

Optional

Who chooses the next step?

Both designs use a language model, and both can use tools. The difference is who decides what happens next.

In an Agentic workflowA fixed sequence of steps in which your code decides the order and a language model does the work inside each step. It is cheaper and easier to test than an agent, which chooses its own steps., your code decides. The order of the steps is fixed, and the model does one job in each step, such as summarising a page or labelling an email.

In an agent, the model decides. It reads the situation after each action and picks the next one, so the order can change from one run to the next.

A recipe is a workflow. A cook who tastes the soup and decides whether it needs salt is closer to an agent.

WorkflowAgent
Who picks the next stepYour codeThe model
The order of stepsFixedCan change on every run
PredictableHighLower
Handles surprisesOnly the ones you codedMany, by choosing a different step
Cost and speedLow and steadyHigher, and it varies
A workflow and an agent side by side

A workflow in plain Python

Take a support inbox. Every email gets labelled, and the label decides what happens next. The model never chooses the order.

python
def label(email):
	return "refund" if "refund" in email.lower() else "other"

def draft_reply(email):
	return "We have started your refund."

def send_to_human(email):
	return "Passed to a person."

def handle(email):
	if label(email) == "refund":
		return draft_reply(email)
	return send_to_human(email)

print(handle("I want a refund for order 1042"))
print(handle("Do you sell gift cards?"))

In a real system label and draft_reply would call a model. The path is still fixed: label first, then branch. That gives you three benefits. You can predict the cost of a run. You can test each step on its own. And when something breaks, you know which step to look at.

When a workflow is not enough

A workflow breaks down when you cannot list the steps ahead of time. A request such as "find out why our signups dropped last week" has no fixed path. The first query depends on what you expect, the second depends on what the first returned, and so on. Only something that reads the results can choose the next move.

That is where an agent earns its extra cost. Use this short test.

  • Known steps, known order. Build a workflow.
  • Known steps, order depends on the input. Build a workflow with branches, as in the sketch above.
  • Unknown steps, the path depends on what you find. Build an agent.

The trade you make with an agent

An agent gives you flexibility and charges you for it. It uses more calls, so it costs more and runs slower. It can take a wrong turn that your code would never take. It is also harder to test, because two runs of the same task can follow different paths.

So the order of attempts should be: one prompt, then a workflow, then an agent. Many products stop at the second step. Reaching for an agent first is the most common way to build something that is expensive, slow and hard to debug.

Workflow: code picks the stepsThe path is fixed, so it is cheaper, faster and easier to test.
Agent: the model picks the stepsUse it only when the path depends on what the agent finds along the way.
Try the simpler design firstOne prompt, then a workflow, then an agent. Each step up costs more.

Your reading position is saved

0%

0 of 20 complete

Contents

Learning tools