Planning, Reflection and Long Tasks
Techniques that help agents tackle multi-step tasks: explicit plans, to-do lists, self-checking and verification against the real world.
Advanced · about 5 hours · difficulty 4/5
Learn first: The Agent Loop, Reasoning Models and Thinking Budgets
Reasoning models already plan internally, but long tasks still benefit from explicit structure that survives many steps and context resets.
Useful patterns
- Plan then act: ask the agent to write a short plan or checklist first, then execute it step by step and update it as it learns. A visible plan also helps humans supervise.
- ReAct style interleaving: think, act with a tool, observe the result, think again. Most modern tool loops already work this way.
- Verification: the strongest signal is external. Run the tests, query the database, render the page, check the file exists. Prefer "prove it worked" over "does this look right?".
- Reflection and critique: a second pass (same or different model) reviews the output against the goal and lists problems. Useful for writing and code, but it costs tokens and can rationalize mistakes.
- Decomposition: break a big goal into sub-tasks, possibly handled by sub-agents with fresh context.
Long-running tasks
When a task exceeds one context window, the agent needs durable progress: a notes file, a task list, git commits, or a database row per step. Compaction (summarizing old history) keeps the loop going but loses detail, so write important facts to storage deliberately.
Good enough to move on
You can make an agent produce a plan, execute it with verification after each step, and resume from saved progress after being stopped halfway.
Key concepts
- Plan-then-execute
- ReAct interleaving
- External verification
- Self-critique and reflection
- Task decomposition
- Context compaction
- Durable progress files
Mini project
Give an agent a coding task in a small repo with a test suite. Require it to write a plan, run tests after every change, and keep a progress.md file so a fresh run can resume the task.
Check yourself
Why is running the test suite a better check than asking the model whether its code is correct?
Free resources
- ReAct: Synergizing Reasoning and Acting (arXiv)
- Anthropic: Building effective agents (Anthropic)