ReAct is the foundational agent prompting pattern — the model interleaves Thought (reasoning), Action (tool call), and Observation (result) to solve multi-step problems.
# ReAct prompt structure
You have access to these tools:
- search(query): Search the web
- calculator(expr): Evaluate math
- python(code): Execute Python code
Always respond in this format:
Thought: [your reasoning]
Action: tool_name(arguments)
Observation: [result will be filled in]
# Example trace
Question: What is the GDP of France divided by its population?
Thought: I need France GDP and population.
Action: search("France GDP 2024")
Observation: France GDP is $3.1 trillion.
Thought: Now I need population.
Action: search("France population 2024")
Observation: France population is 68 million.
Thought: Calculate GDP per capita.
Action: calculator(3100000000000 / 68000000)
Observation: 45588.24
Final Answer: France GDP per capita is approximately $45,588.