Planning and the ReAct loop
Already running Thought, Action, Observation loops? Skip to the next lesson.
Everything so far needed one tool call. Real questions often need several, in an order nobody decided in advance. This lesson is where your agent starts working things out.
The idea
ReAct stands for Reasoning and Acting. It is a pattern, not a library, and it is three things in a cycle:
- Thought. The model says what it plans to do next, in ordinary words.
- Action. It asks for a tool.
- Observation. You run the tool and hand back what happened.
Then it thinks again, now knowing something it did not know before.
Here is the good news: your loop from Module 2 already does this. You do not need new machinery. What changes is the system prompt, the instructions at the top of the conversation. Ask the model to work step by step and explain its reasoning, and the same loop starts solving problems that need several moves.
This question needs two: a multiplication, then an addition. One tool call cannot get there.
What to write
Write the system prompt that asks for step-by-step work. Keep the loop exactly as it was: call, tool, append, repeat.
The point
Planning is a prompt plus the loop you already built. There is no separate planning engine.
Break it on purpose
Stop after the first tool result. The check fails with single_step, because
answering after one move on a two-move question means guessing the rest.
Check yourself
Answer out loud first. Reading the answer without trying is where the learning leaks out.
1. Where does Thought live in the event stream versus Action?
2. What is an Observation in your messages list?
3. Why does the same while-loop support one step and many?