ReAct picks one step at a time, like driving while looking only five metres ahead. Planning adds a short plan that the agent follows over many steps.
Comparison
| ReAct: decide as you go | Plan, then act |
|---|---|
| Reacts to every result | First writes a short plan, then follows it |
| Can wander or repeat itself | Keeps the steps in order |
| Good when little is known in advance | Good when the steps are clear |
Example plan for the shopping task: search, check fit, compare totals, check out.
In practice
- agents mix the two ideas
- keep a short to-do list
- follow it step by step
- rewrite it when a result is surprising
Remembering tip
Plan the route, but keep your eyes on the road. Follow the plan, and replan when the road changes.
Code
A plan as a to-do list that the loop updates:
plan = ["search", "check fit", "compare totals", "check out"]
def next_step(plan, last_result):
"""Follow the plan, and rewrite it when a result is surprising."""
if last_result == "no results":
return ["rephrase search"] + plan # replan: add a step in front
return plan
while plan:
step = plan.pop(0) # take the next step of the plan
result = do(step) # do() runs the matching tool call
plan = next_step(plan, result)Notes:
dostands for the code that turns a plan step into a tool call- this is a sketch of the idea, and real frameworks store the plan in the memory of the agent
A plan can still fail, so after a failed attempt the agent can learn a lesson, see Reflexion.