
Dan Patiño
AI Strategy & Innovation at Coderhouse
Artificial Intelligence
The ReAct pattern (short for Reasoning + Acting) is a way of building AI agents in which a large language model alternates between thinking about a problem and taking actions with tools. Instead of answering in one shot, the model writes a short reasoning step, calls a tool (a search API, a database query, a calculator, an internal service), reads the result, and repeats the loop until it has enough information to give a final answer.
It matters because most useful business tasks cannot be solved from the model's training data alone. Checking an order status, reconciling numbers across two systems or answering a question about this week's tickets all require fresh data. ReAct is the simplest, most widely used loop for letting an LLM gather that data step by step, and it is the mental model behind many of the agent frameworks AI engineers use in production today.
Where the ReAct pattern comes from
The pattern was introduced in the research paper ReAct: Synergizing Reasoning and Acting in Language Models (Yao et al.), by researchers from Princeton University and Google. The authors showed that interleaving reasoning traces with actions helped models on question-answering and fact-checking tasks by letting them look up information instead of relying on memory, which reduced made-up facts. Google Research summarized the idea in a blog post on ReAct.
The key insight: reasoning alone (like chain-of-thought prompting) can drift into confident but wrong conclusions, and acting alone (calling tools without a plan) wastes steps. Combining both lets the model plan, check reality and adjust.
How the ReAct loop works
A ReAct agent repeats three steps:
Thought: the model reasons about what it knows and what it still needs. Example: "I need the customer's last invoice before I can explain the charge."
Action: the model chooses a tool and its inputs, such as
get_invoices(customer_id=4821, limit=1).Observation: the application runs the tool and feeds the result back into the model's context.
The loop ends when the model decides it can answer, or when the application stops it (for example, after a maximum number of steps). In the original paper these steps were written as plain text in the prompt. In modern LLM APIs the "Action" step is usually implemented with native function calling, so the model returns a structured tool call instead of free text that your code has to parse.
A simple example
A support agent receives: "Why was I charged twice this month?"
Thought: I should look up this customer's recent charges.
Action:
list_charges(customer_id, last_days=30)Observation: two charges: one for the monthly plan, one for an add-on purchased on the 12th.
Thought: These are two different products, not a duplicate. I should confirm the add-on details.
Action:
get_order(order_id)Observation: add-on "extra seats", purchased by a team admin.
Final answer: explains both charges and who bought the add-on.
Each observation changes what the model does next. That adaptive behavior is what separates an agent from a fixed script.
ReAct vs other agent designs
ReAct is not the only option, and in production it is often not the first one AI engineers reach for. Anthropic's guide to building effective agents distinguishes between workflows, where LLM calls and tools are orchestrated through predefined code paths, and agents, where the model dynamically directs its own process and tool use. It recommends starting with the simplest solution and adding autonomy only when the task needs it.
Single LLM call: best when the answer only needs the prompt and retrieved context, as in many RAG use cases.
Fixed workflow (prompt chaining, routing): best when the steps are known in advance, such as "classify the ticket, then draft a reply, then check the tone".
ReAct loop: best when the number and order of steps depend on what the agent discovers along the way.
Plan-and-execute: the model first writes a full plan, then executes it, re-planning only on failure. Useful for long tasks where you want to review the plan.
Multi-agent systems: several specialized agents coordinate; more powerful, but harder to debug and more expensive.
What AI engineers add to make ReAct production-ready
A ReAct demo takes a few lines of code. A ReAct agent that a business can trust takes engineering. This is the daily work of a forward deployed AI engineer: taking the pattern into a real customer environment with real systems and real risk.
1. Well-designed tools
The model can only be as good as the tools it can call. Give each tool a clear name, a precise description, typed parameters and useful error messages. Return compact, relevant data instead of full API dumps that flood the context window.
2. Step limits and stop conditions
Set a maximum number of iterations, a timeout and a cost budget per request. Detect loops, such as the agent calling the same tool with the same arguments repeatedly, and stop or escalate.
3. Guardrails on actions
Separate read tools from write tools. Reading an order is low risk; issuing a refund is not. Require human approval or strict validation for actions that change data, move money or contact customers. See our explainer on AI guardrails.
4. Tracing and evaluation
Log every thought, tool call, input and observation so you can see why the agent did what it did. Build test sets of realistic tasks and measure success rate, number of steps and cost per task before and after each change.
5. State and memory
For multi-turn conversations, decide what the agent should remember between requests and what should be fetched again fresh. Our guide to agent memory and state covers the main options.
Common mistakes with ReAct agents
Too many tools: dozens of overlapping tools confuse the model. Start with a few and merge similar ones.
Vague tool descriptions: the model chooses tools from their descriptions; ambiguity leads to wrong calls.
No error handling: when a tool fails, return an informative message the model can act on, not a stack trace.
Using an agent where a workflow would do: if the steps are always the same, a fixed pipeline is cheaper, faster and easier to test.
Trusting observations blindly: tool outputs can contain untrusted text, including prompt injection. Treat them as data, not instructions.
FAQ
Is ReAct the same as function calling?
No. Function calling is the API feature that lets a model return a structured tool call. ReAct is the loop design that uses those calls repeatedly, alternating reasoning and actions until the task is solved.
Do I need a framework to build a ReAct agent?
No. A ReAct loop is a while-loop around an LLM call that executes tool calls and appends results. Frameworks such as LangChain offer ready-made agents, but many teams write the loop themselves to keep full control.
Does the model have to show its reasoning?
Not to the end user. Many systems keep reasoning internal and only show the final answer, while still logging tool calls for debugging and audits.
When should I avoid ReAct?
When the task is predictable, latency-sensitive or high risk. In those cases a fixed workflow with explicit steps is usually the better choice.
Keep learning with Coderhouse
Knowing when to use a ReAct loop, and how to make it safe, is a core skill for engineers who deploy AI inside real companies. Explore the path that fits your goals:
Forward Deployed AI Engineering Course — learn to design, build and deploy AI agents and LLM systems that solve real business problems.
Data Analytics Course — learn SQL, Python and dashboards to work with the data your agents depend on.
GTM Engineer Course (waitlist) — join the waitlist for early access to the program focused on AI-powered go-to-market systems.
I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.