Agents and tools
Agent planning
Write a plan first when you need approval or a large decomposition. Interleave the next action when the environment keeps surprising you.
An agent that only picks the next tool can lose the global goal. An agent that writes a ten-step plan and never revises it will execute a plan the world already invalidated. Planning is the choice between those two, and the scratchpad that keeps the goal visible.
Concept
Before you start: the ReAct loop chooses one action from the latest observation. A plan is an explicit list of upcoming steps the runtime (and often a human) can see.
The big idea
Plan-then-execute. The model writes a multi-step plan first, then executes it. Good when the task is large and decomposable (research report, migration checklist). Weak when early observations invalidate the plan. You must allow re-planning.
Interleaved (ReAct-style). Plan only the next action given the latest observation. More adaptive. Easier to lose the global goal in a long trajectory.
Todo lists and scratchpads. Persist an explicit checklist in state, or expose a tool such as update_todo. Coding agents do this so the model can mark steps done without relying on attention over a 100k-token transcript. Compact the scratchpad when it grows. See context engineering.
A kitchen recipe is plan-then-execute. Cooking from whatever is in the fridge is interleaved. Real cooking does both: you sketch the meal, then adjust when the onions are already burnt.
Trade-off
Plan-then-execute is easier to show a user ("here is what I will do") and to insert approval gates between plan and action. Interleaved planning is better for uncertain environments. Many systems do both: propose a plan for approval, then ReAct inside each approved step.
Walking through state the prompt should not own
Long agents accumulate junk. Keep canonical state in a structure the runtime owns:
goal: "Debug flaky checkout test"
todos: [reproduce, find culprit, patch, run tests]
artifacts: [log_url, branch_name]
budget: {steps: 12 used 4, usd: 0.20 used 0.07}
last_error: nullExpose update_todo and attach_artifact as tools so the model writes here instead of hoping attention remembers. When you compact the transcript, reload goal, todos and recent errors so the agent does not forget the mission.
Common mistakes
- A rigid plan with no re-plan path. The first failed tool call makes the rest of the list fiction.
- No visible goal after compaction. The agent starts busy-work.
- A ten-step plan for "fix the typo in utils.ts." Match process weight to blast radius.
Check yourself
- You need a human to approve work before any write tool runs. Which style? Plan-then-execute, so the plan is the approval artifact.
- Why keep todos outside the transcript? Compaction and long context drop details. A structured checklist survives.
Key takeaways
- Plan first when you need approval or a large decomposition.
- Interleave when early observations will change the path.
- Many systems propose a plan, then ReAct inside each approved step.
- Keep goal, todos and artifacts in runtime state, not only in the prompt.
Further learning
How much autonomy to grant, and when a human must sit on the loop, is agent autonomy.
Related
Agents and agent architectures
Workflows vs agents, the core patterns, ReAct loops, planning and knowing when to stop.
The ReAct loop
Reason, act, observe, repeat, with hard stop conditions so the loop cannot run forever.
Context engineering
Deciding what goes into the context window: ordering, compaction, memory and long context vs retrieval.