Yashotantra Academy logo
level 1
Curious · 0 XP
streak
0d
perfect
0
badges
0

100 XP to Apprentice

Patterns · easy

2. ReAct: reason, act, observe

The classic prompting pattern that made tool-using agents reliable.

1 min read2 questionsup to 50 XPtopic 2/14

Read in another language

AI translates the explanation and quiz text while preserving code and answer scoring.

ReAct interleaves *thought*, *action*, and *observation*. Modern models do this natively through tool calling, but the pattern still explains why agents work: making the reasoning explicit before an action reduces impulsive, wrong tool calls.

- Thought: what do I know, what is missing? - Action: one tool call with concrete arguments. - Observation: the tool's real output, never invented.

text
Thought: I need the current ETH gas price before estimating the fee.
Action: http_get({"url": "https://api.example.com/gas"})
Observation: {"baseFeeGwei": 12.4}
Thought: Fee = 21000 * 12.4 gwei = 0.00026 ETH. I can answer now.
Answer: About 0.00026 ETH at the current base fee.

With native tool calling, keep a short `"Think about what is missing before each call"` line in the system prompt: it is the cheapest accuracy improvement available.

Gotcha: never let the model write the observation itself. If your loop appends model-generated text as a tool result, the agent will happily hallucinate API responses.

Exercise: run the same question twice — once with a ReAct hint in the system prompt, once without — and count tool calls and wrong answers over ten runs.

How to study this topic

  1. 1. Read the explanation once end to end, skipping the code.
  2. 2. Re-read the code snippets and say out loud what each line does.
  3. 3. Answer the quiz without scrolling back — that is the real check.
  4. 4. Read every explanation, even for the answers you got right.

Scoring

  • · Up to 30 XP from quiz accuracy.
  • · +15 XP for a perfect first attempt.
  • · +5 XP while a 3-day streak is running.
  • · 75% or higher marks the topic complete.

Check your understanding

  1. 1. What does the 'observation' step in ReAct contain?

  2. 2. Why does explicit reasoning before a tool call help?

Badges

First light
Pass your first topic
Sharp shooter
3 perfect first-try quizzes
On a roll
Study 3 days in a row
Week warrior
Study 7 days in a row
Grinder
Earn 500 XP
Deep diver
Earn 1500 XP