ReAct interleaves reasoning with actions — the model thinks, calls a tool, reads the result, and thinks again. It is the prompting pattern behind agents that search, calculate, and use APIs.
Why: ReAct (Reason + Act) lets a model use tools instead of guessing facts — it reasons, takes an action, observes the result, and repeats. When: use it whenever the model needs fresh data, calculations, or anything outside its own memory. How: define the loop format explicitly.
Answer the question using this loop. Repeat until you can answer.
Thought: reason about what you need next.
Action: one of Search[query] or Calculator[expression]
Observation: (the tool's result will be filled in here)
... repeat ...
Answer: the final answer.
Question: Who directed the highest-grossing film of 1997, and
how old were they that year?Why: doing one iteration manually shows exactly what an agent framework automates. When: practice this once so you understand what is really happening before you trust a library to do it. How: you play the "tool" and paste the Observation back in.
Thought: I need the highest-grossing 1997 film.
Action: Search[highest-grossing film 1997]
Observation: Titanic, directed by James Cameron.
Thought: Now I need James Cameron's birth year.
Action: Search[James Cameron birth year]
Observation: 1954.
Thought: 1997 - 1954 = 43.
Answer: James Cameron directed Titanic; he was 43 in 1997.Why: the rigid Thought/Action/Observation labels make the output parseable — your code can read the Action line, run the real tool, and feed the Observation back. Where: this is exactly how agent libraries (LangChain, the OpenAI/Anthropic tool APIs) wire prompts to functions under the hood.
Loose prompt (hard to automate):
"Figure out the answer, search the web if you need to."
Structured ReAct (easy to automate):
Action: Search[...] <- your code regex-matches this line,
calls the API, pastes the result as
the next Observation, and re-prompts.