ReAct: Reasoning and Acting with Tools
Learn the ReAct pattern, where the model interleaves reasoning steps with tool actions to solve tasks it cannot answer from memory alone.
ReAct: Reasoning and Acting with Tools is a free Prompt Engineering & LLM Optimization for Developers lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Prompt Engineering & LLM Optimization for Developers learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
When Thinking Is Not Enough
Chain-of-thought helps a model reason, but reasoning alone cannot fetch live data or run code. The ReAct pattern combines Reasoning with Acting so the model can use tools mid-task.
The ReAct Loop
ReAct alternates three roles in a loop:
- Thought: reason about what to do next.
- Action: call a tool with an input.
- Observation: read the tool's result.
Repeat until the answer is ready.
A ReAct Trace
A typical trace looks like this. The model emits a thought, an action, then waits for an observation injected back into the prompt.
Thought: I need today's weather in Paris.
Action: get_weather("Paris")
Observation: 18C, light rain
Thought: I can now answer.
Answer: It is 18C with light rain in Paris.Defining the Tools
You describe the available tools in the prompt: their names, what they do, and the input format. The model picks among them.
Tools:
- search(query): web search
- calc(expr): evaluate math
- get_weather(city): current weatherStopping at the Action
In practice your code stops generation when it sees an Action, executes the real tool, then appends the Observation and resumes the model. The model never invents tool results itself.
Why It Reduces Hallucination
Because the model grounds each step in real observations, ReAct cuts hallucination on factual or computational tasks. The reasoning explains why each tool was called, aiding debugging.
Multi-Step Problems
ReAct shines on tasks needing several lookups: find a company, then its founder, then that person's birth year. Each step's observation feeds the next thought.
Limiting the Loop
Always cap the number of iterations. Without a limit, a confused model can loop forever calling tools. Add a max-step budget and a fallback answer.
for step in range(MAX_STEPS):
out = model(prompt)
if is_answer(out): break
obs = run_tool(parse_action(out))
prompt += observation(obs)Handling Tool Errors
Tools fail: timeouts, bad inputs, empty results. Feed the error back as an observation so the model can retry differently rather than crashing the loop.
Observation: ERROR: city not found.
Thought: I should try the full country name.ReAct vs Plain Chain-of-Thought
- CoT: reasons internally, no external data.
- ReAct: reasons AND acts on the world via tools.
Use ReAct whenever the answer depends on information the model cannot already know.
Foundation for Agents
ReAct is the backbone of modern LLM agents. Frameworks like LangChain implement this thought-action-observation loop under the hood to build autonomous tool-using assistants.
Quick Check
Test your understanding of ReAct.
Recap
ReAct interleaves Thought, Action, and Observation so the model reasons and uses real tools. It grounds answers, reduces hallucination, needs a step limit and error handling, and underpins modern LLM agents.
Frequently asked questions
Is the “ReAct: Reasoning and Acting with Tools” lesson free?
Yes — the full text of “ReAct: Reasoning and Acting with Tools” is free to read here on the web, and the Prompt Engineering & LLM Optimization for Developers course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Prompt Engineering & LLM Optimization for Developers course, upgrade to CoddyKit PRO.
What will I learn in “ReAct: Reasoning and Acting with Tools”?
Learn the ReAct pattern, where the model interleaves reasoning steps with tool actions to solve tasks it cannot answer from memory alone. You practise Prompt Engineering & LLM Optimization for Developers with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Prompt Engineering & LLM Optimization for Developers?
No prior experience is required. Prompt Engineering & LLM Optimization for Developers on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “ReAct: Reasoning and Acting with Tools” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Prompt Engineering & LLM Optimization for Developers lesson?
Yes. Every Prompt Engineering & LLM Optimization for Developers lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Chain-of-Thought Prompting
- Self-Consistency & Generated Knowledge
- Tree-of-Thought & Graph Prompts
- ReAct: Reasoning and Acting with Tools