An office sets up a meeting room. It needs chairs, a screen, coffee, name cards and more.
The first try is an agent loop. The model picks one move, reads the result and picks again. Each turn sends the whole history once more.
Split the work between a planner and an executor.
- The planner is one model call. It writes the full list of steps.
- Code checks that every step exists before any step runs.
- The executor is plain code. It runs the steps in order.
- The planner is asked again only when a step fails.
For example, the projector is broken. The planner is told and picks another screen.
sequenceDiagram
participant Office as Your code
participant Model
Office->>Model: write all the steps
Model-->>Office: plan
alt a step does not exist
Office->>Model: fix the plan
else a step fails while running
Office->>Model: plan the rest
else all steps work
Office->>Office: room is ready
end
- The planner writes the steps.
- The executor runs them.
- An agent loop picks one move at a time.
uv run lab plan-executor naive
uv run lab plan-executorAdd --case 2 or --case 3 to try the other cases.
There are three rooms with one broken screen each. Code counts input tokens. An unmet need adds a large charge.
| Version | Tokens read |
|---|---|
| Agent loop | 50,026 |
| Plan, then execute | 3,565 |
Now break it. Open the pattern file and find unknown_steps. Make it return an empty list. Then
run the test:
uv run pytest tests/promises/test_plan_executor.pyThe test fails, because a plan with a step that does not exist is now run.
- A "no key found" message means the key file is missing. Copy the example file and paste your key.
- If you see "so nothing was run", the plan named actions that do not exist.
A fixed plan cannot react to surprises until a step fails. Use an agent loop when each move depends on what you saw last.
Our rooms are a stand in. Your savings depend on how long the loop would run.
Go to Reason with observations. It reads each result before the next move.