The idea
ReAct (Reason + Act) structures each step as Thought → Action → Observation. The model writes a short thought about what it needs, chooses an action (a tool call), reads the observation (the result), and repeats until it writes a final answer.
Interleaving reasoning with actions helps the model plan the next step from real results instead of guessing everything up front, and it leaves a readable trace of why each action happened.
With native tool calling you get most of ReAct for free: models often emit a short text block before each tool call. You can still ask explicitly for a one-line rationale before each call to improve decisions and logs.
It is the mental model behind most agents and the reason traces are readable.
Words to know
- ObservationThe tool result the model reads after acting.
Try it without code
Run ReAct as plain text
- Paste the prompt below into a chat app.
- When it writes an Action, reply with a made-up Observation.
- Continue until it gives a Final Answer.
Use it in code
Ask for a rationale before each tool call and log it.
SYSTEM = """Before every tool call, write one sentence starting with 'Thought:' explaining
what you need and why this tool. After the final tool result, answer directly."""
def log_trace(msg):
for b in msg.content:
if b.type == "text":
print("THOUGHT:", b.text.strip())
elif b.type == "tool_use":
print("ACTION: ", b.name, b.input)
# call log_trace(msg) inside your agent loop after each model callAdd thought logging to your agent and read 5 traces. Write down one decision per trace that you would change.
Common mistakes
- Long rambling thoughts that cost more than they help.
- Parsing free-text "Action:" lines when native tool calling exists.