Defending AI Agents
עברית Join waitlist
Menu

E3 · Lesson 01

Who decides the next step? Workflows and agents

Module 1's agent read a report and e-mailed a summary. A twelve-line script could do the same: read the file, ask the model for three bullets, send them. The script and the agent use the same model and the same tools. They differ in one thing: who chooses what happens next.

Two kinds of program

A workflow is a program you wrote. The model fills slots in it (summarise this, classify that), and your code decides the order of steps. An agent is a loop in which the model chooses the next step, and your code only carries it out.

Workflow Agent
next step chosen by your code the model
number of model calls fixed, known in advance decided at run time
cost and latency predictable a distribution with a long tail
testable by ordinary unit tests measuring success rates over many runs
handles the cases you foresaw some cases you did not

The statistical twin is the difference between a fixed design and a sequential one. A workflow is a pipeline of estimators applied in a fixed order. An agent is a sequential decision-maker, and the standard model of one is a Markov decision process (MDP), which has four parts:

MDP part Meaning In an agent
state s_t what the decision-maker knows at step t the history h_t: the task, and every call and result so far
action a_t what it chooses a tool call, or an answer
transition function P(s_{t+1} \mid s_t, a_t) how the world answers an action what the tool returns, which then joins the history
reward what counts as success the grader's verdict at the end of the run

A policy \pi(a_t \mid s_t) chooses the actions. Here it is the language model, sampling at temperature 0.7, and the horizon is the number of steps your loop allows. "Markov" means that the next state depends only on the current state and action. An agent satisfies that by construction, because its state is the whole history.

flowchart LR
  T[task] --> H[history]
  H --> M{model samples<br/>the next step}
  M -->|tool calls| X[your code runs them]
  X -->|results| H
  M -->|no tool call| A[answer]
  B[budget] -. checked before<br/>every call .-> M

The simplest thing that works

The advice from teams that ship agents is to start with the simplest program that does the job and to add agency only where it pays (Anthropic, 2024). The best-known measurement is Agentless (Xia et al., 2024). On SWE-bench Lite's 300 issues, a fixed three-phase pipeline (localise the bug, write a patch, validate it), in which the model never chooses the next action, solved 32.0% of issues at $0.70 each. That was the highest score of any open-source system then, and every one of them was a full agent. Kapoor et al. (2024) found the same pattern across benchmarks: when cost is reported alongside accuracy, simple baselines often match elaborate agents at a fraction of the price.

That does not make agents a mistake. A workflow fails on every case its author did not foresee. An agent can recover from a missing file by listing the directory, and from a wrong customer ID by searching. Use a workflow when the steps are known, and an agent when the steps depend on what the tools return. Many production systems are workflows with one agentic step inside.

What this module builds

You will turn Module 1's loop into one that can run unattended. Each lesson adds one piece, and the build measures what they buy together on twenty lab tasks:

Lesson Adds Module 1's loop instead
2 arguments parsed and checked, errors returned to the model crashes on malformed JSON; passes wrong arguments to the tool
3 adapters to other wire formats speaks one format
4 parallel reads, ordered writes runs every call in sequence
5 retries for the server's failures dies on the first 503
6 four budgets and a stop reason stops at ten steps, says nothing else
7 answers checked against a schema returns whatever text came back
8 streaming waits for the whole reply

E7 returns to workflows and agents at the scale of several agents, with the same question: who decides the next step, and what does each choice cost?

Check yourself

  1. A support bot must, for every ticket, look up the customer, check the refund policy and draft a reply. Workflow or agent, and why?
  2. Agentless solved 32.0% of SWE-bench Lite. What would you need to know before concluding that a pipeline beats an agent on your own tasks?
  3. In the MDP view, what plays the role of the transition function, and why can't you write it down?
Answers
  1. A workflow. The three steps and their order are known in advance, so a fixed program does them for a predictable cost and can be unit-tested. Add an agentic step only if some tickets need steps nobody can list in advance.
  2. Whether your tasks look like SWE-bench Lite's (repository bug fixes with tests), what each system costs per task on yours, and the interval on both success rates measured on your task distribution. Agentless's result is one benchmark, a population of 300 issues, at one point in time.
  3. The tools and the world behind them: the lab's files, the inbox and the CRM decide what each call returns. You cannot write it down because it is the environment itself. That is why agents are evaluated by running them, not by analysing them.