Σ 0:00▸ 0:00

Module 4 · Planning, Context & Multi-agent Systems · scripted

Agent Planning: The Language of Planning

25 minoutcomes: agent-architectures, context-engineering

Overview

An agent's conversation is a trajectory — and back in Module 1 we met chain of thought: make the model write correct reasoning first, and the right answer becomes the probable continuation. Planning is chain of thought for action. Have the agent write its plan into the conversation before its first action, and every action after it is predicted following a document that already contains the path. The tool list gave the agent its language of action; this lesson begins a language of planning — words like write_plan and think that put reflection itself into the conversation, the way science builds thinking into research by demanding a hypothesis before the experiment. In this lesson: why planning first works, why the plan should be written through a tool, and how to design the planning vocabulary.

Think first: the plan is chain of thought for action

Remember the ferry problem. Forced to jump straight to the answer, the model slipped; asked to think step by step, it wrote a correct chain of reasoning — and the right answer became nothing more than the continuation of a correct document. Planning is the same move, one level up:

Chain of thought, one level up

For answers:write the REASONING first —
the right answer becomes the probable next words.
For actions:write the PLAN first —
the right action becomes the probable next step.

Same mechanism. The conversation is a trajectory, and a plan seeds it with the path.

Watch it work. The task: a small data-analysis package has a failing test suite. The tools are the file system and the test runner — and the only thing that will change between the two runs is one sentence.

One more tool rides along in both runs, and it looks like it does nothing: think( thought ). Call it, and the computer just replies "OK." It exists because the conversation alternates — after the agent speaks, the computer must answer before the agent may speak again — so an agent cannot follow a paragraph of reasoning with a tool call in the same breath. When it wants to reason between actions, it calls think, and the OK keeps the conversation taking turns. File that odd little tool away: the next lesson is entirely about it.

Example 1 · No plan — the agent wanders
user

You have the following tools available for use:


  1. list_files( dir )
  2. read_file( path )
  3. edit_file( path, old, new )
  4. run_tests( )
  5. think( thought )

Task: The test suite for our field-data package is failing. Find the problem and fix it.

assistant
list_files(dir = ".")
user
analysis.py · io_utils.py · test_analysis.py
assistant
read_file(path = "analysis.py")
user
[def mean_salinity(readings): returns sum(readings)/len(readings),
rounded to 1 decimal …]
assistant
think(thought = "The rounding to one decimal looks suspicious — a
precision mismatch would fail an equality assertion. I'll return
the unrounded mean.")
user
OK.
assistant
edit_file(path = "analysis.py", old = "round(m, 1)", new = "m")
user
OK.
assistant
run_tests()
user
2 failed: test_mean_skips_missing — mean_salinity([31.2, -999.0,
30.8]) expected 31.0, got -312.6…
assistant
think(thought = "The failure was never about rounding — it's about
missing readings coded as -999. I fixed a problem I imagined
instead of the one that exists. Reverting my edit, then reading
the failing test.")
user
OK.
✎ noteEvery choice was locally reasonable given the conversation at that moment. But the trajectory never contained the path — so the agent guessed one, paid for a wrong edit, a revert, and an extra pass through the file. Nothing malfunctioned except the order of events.

Now the same task — plus one new tool, and one added line. The tool is write_plan( plan ): the way the agent plans is by calling a tool that writes the plan down.

Example 2 · Plan first — the actions follow the plan
user

The same tools and task — with one new tool:

  1. write_plan( plan )

…and one addition to the task:

Before your first action, call write_plan with your complete plan as numbered steps.

assistant
write_plan(plan = "
1. run_tests — observe what actually fails before touching
   anything.
2. read_file the failing test — the test states the expected
   behavior; that is the specification.
3. Form a hypothesis, and read only the file it implicates.
4. Make the smallest edit that fits the hypothesis.
5. run_tests again — the experiment that confirms or refutes it.
")
user
Plan saved to plan.md.
assistant
run_tests()
user
2 failed: test_mean_skips_missing — mean_salinity([31.2, -999.0,
30.8]) expected 31.0, got -312.6…
assistant
read_file(path = "test_analysis.py")
user
[test_mean_skips_missing: readings of -999.0 mark a missing sensor
value and must be excluded from the mean]
assistant
think(thought = "Step 3 — hypothesis: mean_salinity averages every
reading, but -999.0 is a missing-value code and must be skipped.
The fix belongs in analysis.py.")
user
OK.
assistant
read_file(path = "analysis.py")
user
[def mean_salinity(readings): returns sum(readings)/len(readings)…]
assistant
edit_file(path = "analysis.py",
  old = "sum(readings)/len(readings)",
  new = "mean of [r for r in readings if r != -999.0]")
user
OK.
assistant
run_tests()
user
All tests pass.
✎ noteSame model, same failing suite. The plan is not held in the agent's mind — an LLM has no mind to hold it in. The write_plan call is words in the conversation, re-read on every turn like everything else — and that is exactly why it works: each next action is the probable continuation of a document that already contains the path. Notice, too, what the plan is: observe first, read the specification, hypothesize, make the smallest change, test. The agent wrote itself a little scientific method.

And because the plan is just words, it is revisable the moment the world disagrees. If step 5 had come back still failing, the right continuation is not stubbornness — it is another write_plan call, replacing the hypothesis that just failed. A plan is a hypothesis about the future; every result that comes back is evidence about whether to keep it.

Hypothesis, evidence, revision

The note under Example 2 said the agent "wrote itself a little scientific method." Take that seriously, because it names what planning actually is. Science is not a collection of unusually smart people — it is a format for thought, built into a community's conversation. A paper must state its hypothesis before its results. A method must be written down where others can check it. Being wrong has a prescribed answer: revise, in writing. The format does the disciplining, and ordinary minds working inside it do extraordinary work.

That is exactly the move we just made on the agent's conversation. We did not make the model more intelligent. We gave its conversation words for reflection, and demanded they be used:

The language of planning

write_planstates the hypothesis: where the task is going, and why this path should get there
each resultreturns as evidence — it confirms the step it answers, or contradicts it
write_plan againis the revision: the method's required answer to being wrong

The tool list taught the agent what it may DO. The planning vocabulary teaches its conversation how to THINK OUT LOUD.

Why a tool, and not just a message?

The agent could have simply said its plan — the trajectory effect would be identical, since either way the plan is words the model re-reads. So why route it through a tool? Because a message only puts the plan in the conversation, and the conversation is rented space with a hard limit. A tool call does something a message cannot: if it writes it, it saves it. The plan now also lives in plan.md — outside the conversation, in the durable world.

What write_plan buys

in the conversationthe plan conditions every next action — the trajectory effect, same as saying it
outside itthe plan is SAVED — a file in the world, not a passage in a transcript
if context runs outthe conversation can be trimmed or compacted, and the plan survives it — one read_file brings it back whole
if the run stopscrash, interruption, end of session — the plan is still there, for the agent that resumes tomorrow or the human who wants to see what the agent intended

You have met this move before: the journal between conversations, the handoff you write to your future self. The plan is the first thing worth writing down, because it is the one document that says where the whole task is going — and the conversation, with its edges and its meter, is the wrong place for anything you cannot afford to lose.

The plan is a first-class artifact

Once the plan exists outside the conversation, something bigger than durability opens up. A conversation is one big prompt — so a plan that lives in a file can be injected into any prompt we like. It stops being a passage in one transcript and becomes a first-class artifact: a document that can move between conversations, between models, and between readers.

What a first-class plan can do

travel between conversationsstart a completely fresh conversation, inject the plan, and the work continues — the trajectory travels with the document, not the transcript
travel between modelslet an expensive, careful model write the plan, then start the execution conversation on a cheaper, faster model — same plan, lower bill; the judgment was already spent and saved
carry the whythe plan records the decision-making — compact, and separate from the blow-by-blow of the actions taken. For traceability, that separation is the point: anyone can read the plan at a glance and know why things were done, without replaying a transcript

Each row is the same move: the plan seeds a new trajectory with an old one's judgment. The reasoning was paid for once — by a person, by an expensive model, by a long exploration — and the artifact carries it wherever a conversation needs it next.

What should the tool be named?

We called it write_plan — but that was a design choice, and you know from the tool design case studies what's at stake in it: the name is the policy, and the tool set is a language. There are several ways to speak "planning," each with its own consequences:

Three designs for the same act

write_planone call writes the whole plan. The simplest design: one word for one act, saved and done
planning modeenter_planning_mode() swaps the tool set — inside it, only planning tools exist, so the agent can do nothing but think ahead; when the plan is written, exit_planning_mode() returns the action tools
a to-do listadd_todo(item), update_todo(item, status), list_todos() — the plan becomes a living checklist, and the agent marks each item pending, in progress, or done as it works

The planning-mode design has a quiet superpower: the agent loop can see which mode the conversation is in, and route it to different models. Planning is where the judgment concentrates — so spend a more intelligent, more expensive model on writing the plan, and let a cheaper, faster model execute the steps. The mode boundary in the tool set becomes a cost boundary in the loop.

The to-do design adds something else: status. The agent doesn't just have a plan — it records where it is in the plan, updating each item as it perceives progress. Now the saved artifact tells anyone who reads it — the agent that resumes after a crash, the human peering in mid-run — not only where the task is going, but exactly where it stands. A set of tools for planning and for tracking the plan is one of the most useful vocabularies you can hand an agent.

The grammar can demand thought

There is one more place to put planning words, and it may be the most powerful: inside the tools themselves. Parameters are the grammar of the language of action — and we write that grammar, so we can write contracts into it. A tool can require a rationale parameter: now the tool cannot be called without a stated reason. And we can go further — require the same thinking parameters on every tool:

A contract on every tool

Every tool in this set takes two required parameters, before its own:

prior_learningwhat I learned from the last result — one or two sentences
hypothesismy current hypothesis, and why I am calling this tool now

The agent cannot act without answering both. It is what parents tell children — think before you act — written into the grammar.

Example 3 · The grammar forces the dialogue
user

The same failing-test task — but now every tool requires prior_learning and hypothesis before its own parameters.

assistant
run_tests(
  prior_learning = "Nothing observed yet — the task says the
    suite fails, but not where.",
  hypothesis = "Running the tests first will name the failure
    and point at the file that matters.")
user
2 failed: test_mean_skips_missing — mean_salinity([31.2, -999.0,
30.8]) expected 31.0, got -312.6…
assistant
read_file(
  prior_learning = "The failing test is about missing values;
    -999.0 readings are being averaged instead of skipped.",
  hypothesis = "The test file states the expected behavior —
    reading it will tell me the exact rule before I touch code.",
  path = "test_analysis.py")
user
[readings of -999.0 must be excluded from the mean]
assistant
edit_file(
  prior_learning = "The rule is confirmed: -999.0 marks a
    missing reading and must not enter the mean.",
  hypothesis = "Filtering -999.0 inside mean_salinity is the
    smallest change that satisfies the test.",
  path = "analysis.py",
  old = "sum(readings)/len(readings)",
  new = "mean of [r for r in readings if r != -999.0]")
user
OK.
✎ noteLook at what the conversation has become. Every action arrives wearing its reasoning — what was learned, what is being tested, why this word is being spoken now. No system-prompt plea produced this; the protocol did. A call without the thinking is not lazy, it is unspeakable — malformed, like a calendar entry without a date. The style of dialogue is enforced by the grammar.

Engineering a style of thinking

Step back and look at the design space this opens. Tool design and loop design together are a mechanism for forcing the conversation to think in a particular style — reflection made structural, not requested:

Ways to build thinking into the machinery

a rationale parameterone tool demands a stated reason — no reason, no call
thinking parameters everywhereprior_learning and hypothesis on every tool — each act must say what was learned and what is being tested
plan before anythingthe loop offers only write_plan until a plan exists; the action tools appear after
a thought before dangercertain tools can only be called if a think came immediately before — detected by the loop, enforced every time
reflection on a cadenceevery N iterations, the loop requires an explicit reflection on the plan — is this still the right plan, given everything since?

And this is just scratching the surface — because the language of planning can itself be planned. Nothing says the contract must be fixed: the loop can detect things about the task, or hand it to another agent to read first, and choose the thinking style the task deserves. A routine task gets a light grammar and no mandatory reflection; a destructive or ambiguous one gets hypothesis parameters, a required plan, and reflection every third loop. The parameters, the cadence, the required words — all of it can adapt, per task, chosen by judgment. There is an infinite number of ways to design the language of planning, and to design it dynamically — what you have seen here is the start of a design space, not the end of one.

Two threads now lead onward. The think tool that kept appearing between actions is the next lesson's whole subject: where thought lives inside the loop, and how the loop can control it. And the lesson after asks what happens when a plan becomes so fully specified that it stops needing the conversation at all — and leaves it, as code.

Read the plan back
  • In Example 2, point to the exact words that made "read the test before touching analysis.py" the probable next action.
  • The wandering agent's every choice was locally reasonable. What exactly did the plan change — the model's intelligence, or the document it was continuing? What does that distinction tell you about where to invest your design effort?
  • Which of the three planning vocabularies would your research domain need — one write_plan, a planning mode, or a to-do list — and what status labels would its items carry?
Your turn

Take a task from your research that an agent could drive with a handful of tools. (1) Write the plan-first prompt: the tool list including write_plan and think, the task, and the one instruction that asks for the plan. (2) Before running anything, write the plan YOU would want it to produce — your hypothesis about its hypothesis. (3) Run it if you can, and compare. (4) Choose the vocabulary — write_plan, a planning mode, or a to-do list — and defend the choice in two sentences.