Area 03 · AI Agents · Concept 03 of 20

ReAct Pattern

Reasoning steps and actions take turns. The classic agent prompt pattern.

01–10 · The basePhase 3 · Weeks 11–14≈ 45 min

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.

Why it matters

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

  1. Paste the prompt below into a chat app.
  2. When it writes an Action, reply with a made-up Observation.
  3. Continue until it gives a Final Answer.
Answer the question using this format, one step at a time, and wait for me after each Action: Thought: ... Action: search[...] Observation: (I will provide) ... Final Answer: ... Question: Which is older, the Eiffel Tower or the Statue of Liberty?

Use it in code

Ask for a rationale before each tool call and log it.

python
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 call
PRACTICE · TICK IT AFTER THIS

Add 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.

Go deeper