Lesson 2 / 25
ReAct: Reason, Act, Observe
Follow the ReAct pattern where the model alternates short reasoning with tool actions.
Think, then do, then look
ReAct (Reasoning + Acting) interleaves a short thought, an action (a tool call) and an observation (the tool result), then repeats. Thinking about the observation before the next action helps the model correct course. Modern tool-calling APIs give you this loop structurally; the model can also reason before calling a tool.
A ReAct transcript
Older text-only agents asked the model to print these lines and parsed them. The parsing line below ran as shown: it pulls the tool name and JSON arguments out of the text.
text = ("Thought: I need the balance.\n"
"Action: get_balance\n"
"Action Input: {\"account_id\": 7}")
fields = dict(l.split(": ", 1) for l in text.splitlines())
print(fields["Action"], json.loads(fields["Action Input"]))
Output:
get_balance {'account_id': 7}Prefer structured tool calls
Parsing free text breaks when the model changes wording. Native tool calling returns a validated name and JSON arguments, which is far more reliable than regular expressions on prose.
Quick check: What happens after an action in ReAct?
- The model sees an observation and reasons about the next step
- The run ends
- The tools are deleted
- The user must restart
Answer
The model sees an observation and reasons about the next step — The observation feeds the next round of reasoning, which closes the loop.