ReAct prompting teaches a model to alternate between two modes: thinking out loud and taking actions in the outside world. The reasoning steers what to do next; the actions feed real information back into the reasoning. It is the prompting pattern that turns a chatty model into something that can actually get work done.
Chain-of-Thought made AI better at reasoning by itself. But pure reasoning has a hard limit — the model can only work with what is already in its training data or its current context. The moment a task requires looking up a fact, running a query, hitting an API, or checking the state of a system, raw CoT runs out of room. ReAct, introduced in a 2022 paper by Yao et al., solves exactly that gap.
The idea is deceptively simple. The model is allowed to produce three kinds of output in any order: a Thought (its internal reasoning), an Action (a tool call it would like to make), and an Observation (the result fed back by the environment after the action runs). Together these form a loop that resembles how a careful human researcher actually works — hypothesise, look something up, update their thinking, decide the next move.
This tutorial covers the ReAct pattern from prompt design through to a worked agent loop you can build with any model that supports function calls or simple stop tokens.
A ReAct prompt instructs the model to follow a strict cycle. After receiving the user's goal, it must first produce a Thought that explains what it intends to do and why. Then it produces an Action — a specific call to one of the tools you have given it (search, calculator, database query, web fetch, internal API). Your runtime executes the action and feeds the result back as an Observation. The model then either continues with a new Thought, takes another Action, or commits to a Final Answer.
Think of ReAct as the difference between a student writing an exam from memory and a researcher who can leave their desk to fetch a reference book. The researcher's thinking is interleaved with real lookups. They write a paragraph, get up, check a source, come back, refine their argument. ReAct gives the same affordance to the model.
Suppose you ask a model to research a small company and summarise its product. Without ReAct, the model has two unattractive options: hallucinate plausible-sounding facts, or refuse and apologise. Neither is useful.
Pure-reasoning attempt
You are a research analyst. Give me a 200-word
brief on the company "Lumen Cargo Systems",
including its main product, target market, and
two competitors.
If the model has never seen this company, it will either confidently invent details or hedge so much that the brief is useless. The model has no way to look anything up — it can only generate text from its prior weights.
Now give the same task with a ReAct scaffold and a small set of tools:
ReAct scaffold
You are a research analyst with access to tools.
Available actions:
- search(query: string) — returns the top 3 web results
- fetch(url: string) — returns the visible text of a page
- finish(answer: string) — submits the final brief and ends the loop
Follow this exact format on every step:
Thought: <your reasoning about what to do next>
Action: <one of search / fetch / finish>
Action Input: <the input for that action>
After each Action, you will receive:
Observation: <the tool result>
Continue the Thought / Action / Observation loop until you
have enough information, then call finish() with a 200-word
brief covering main product, target market, and two competitors.
Task: Research the company "Lumen Cargo Systems".
Your runtime parses each Action, executes the corresponding tool, and appends an Observation back into the model's context. The model now reasons over real evidence instead of guessing.
Thought:, Action:, Action Input:. This makes parsing reliable. Models are remarkably good at sticking to these labels when the system prompt is explicit.finish(answer). Your runtime detects that action and exits the loop with the answer as the final result.Tip: Modern function-calling APIs (OpenAI, Anthropic, Gemini) effectively give you ReAct out of the box — the SDK handles the Thought/Action parsing internally and you simply implement the tools. Even when using these APIs, knowing the underlying ReAct pattern helps you write better tool descriptions and debug strange loops.
Build a minimal ReAct loop in any language with two tools: search(query) and calculate(expression). Test it with the question
What is the population of Auckland, divided by the population of Wellington?
Watch how the model decides which tool to use first.
Take a ReAct prompt that works and deliberately break it — remove the format instructions, or rename Action to Step. Observe how the model's output degrades. This shows you which parts of the scaffold are load-bearing.
Add a deliberately broken tool that returns errors 30% of the time. Run a ReAct task ten times and count how often the model recovers (retries with a different approach) versus gives up. This stress-tests the robustness of your scaffold.
Sign in to join the discussion and post comments.
Sign inPrompt Engineering Projects & Real-World Applications
Twelve hands-on projects that turn prompt engineering theory into a portfolio. Build chatbots, content generators, RAG systems, and more.
Prompt Engineering for Content & Copywriting
Write blogs, ads, emails, and social media content ten times faster with AI. 13 practical tutorials on prompt engineering for content creators and copywriters.
Foundations of Prompt Engineering
The must-know basics of prompt engineering. Learn what prompts are, how AI models read them, and how to write clear instructions that get great results.
Prompt Engineering for Education & Learning
Use AI as your personal tutor. Learn how to study faster, create lesson plans, generate practice questions, master languages, and prepare for competitive exams with smart prompts.
Prompt Engineering for Developers
Use AI as your coding co-pilot. 18 tutorials on writing prompts to generate clean code, debug faster, write tests, build APIs, and ship better software.
Prompt Engineering for Image Generation
Turn words into stunning visuals. Master AI image generation tools like Midjourney, DALL·E 3, and Stable Diffusion with 18 focused tutorials — from first prompt to full brand identity.