mantus.ai

THE BEST INVESTMENT IS ALWAYS YOUR BRAIN

How do I build ReAct workflows that take actions?

Create AI agents that can search, calculate, and interact with external tools by combining reasoning with action-taking capabilities.

You've been building AI systems that think. Now it's time to make them act. ReAct workflows combine reasoning with action-taking, creating AI agents that can search information, calculate results, and interact with external tools to solve problems you couldn't handle with prompts alone.

ReAct stands for "reason and act." The approach mimics how humans solve complex problems. You think about what you need to know, take an action to get that information, observe the results, then reason about what to do next. Your AI does the same thing, but it can call APIs, run calculations, and search databases while explaining its thinking at every step.

Understanding the ReAct pattern

Traditional prompts give you one shot at the right answer. ReAct workflows create a loop: the AI reasons about the problem, decides what action to take, executes that action, observes the result, then reasons again based on what it learned. This continues until it reaches a solution.

The pattern follows a simple structure:

Thought: The AI explains what it's thinking and what it needs to find out next.
Action: The AI calls a specific tool or function.
Observation: The AI receives the result from that action.

This cycle repeats until the AI determines it has enough information to provide a final answer.

ReAct is a control pattern, not a framework feature. You don't need LangChain or any specific library to build one. You need a model that can follow instructions, a clear definition of what tools exist, and a prompt that enforces the loop. The rest is plumbing.

When ReAct earns its complexity

ReAct is overkill for most questions. A single well-crafted prompt handles the majority of real work. Use ReAct when the problem genuinely requires multiple pieces of information that can't be retrieved in one step, or when each step in a calculation depends on the result of the last one.

Good fits: research tasks that need current information, multi-step data analysis, anything where you can't know in advance exactly what to look up. Poor fits: summarization, classification, generation tasks, anything where the model already has what it needs.

If you're unsure, start with a static prompt. Only reach for ReAct when the static approach demonstrably fails.

Designing the agent

When you write a ReAct prompt, you're specifying four things: what the agent may do, what it may never do without confirmation, how many steps it has, and what it must return.

What tools the agent may use. List each tool by name with a plain description of what it does and when to use it. Be specific. A search tool described as "finds information" will get called for everything. A search tool described as "retrieves current web results for questions the model can't answer from training data, not for calculations or lookups of known records" gets called appropriately.

Common tools and their intended scope:

  • Search: current information the model wouldn't have in training data
  • Calculator: arithmetic and unit conversions, not logic or reasoning
  • Code runner: structured data processing or anything where precision matters
  • Database query: retrieving specific records by known identifiers
  • API: accessing live external services for defined data types

What the agent may never do without confirmation. Write, delete, send, publish, or modify anything without a human in the loop. State this explicitly in the prompt. The agent should flag intended writes and stop, not proceed and report.

How many steps it may take. Set a hard cap. Eight is a reasonable starting point. Raise it only when you have a specific reason. Without a cap, agents loop. They find something, decide they need a bit more context, search again, and never commit. A step limit forces prioritization.

What log it must return. Require the agent to return its full reasoning chain alongside its answer: every thought, every action taken, every observation received. This is not optional overhead. It's how you verify the answer is actually grounded in what the agent found, not in what it expected to find.

A prompt structure that works:

Answer the following question using the tools available. For each step, state your reasoning, choose one action if needed, and record what you actually learned from the result before continuing. Stop as soon as you have enough for a complete, accurate answer. You have a maximum of [N] steps. Return your full thought-action-observation log with your final answer.

How ReAct agents fail

Most people who build ReAct agents discover the same failure modes. Knowing them before you build saves significant pain.

Loops. Without a clear stopping condition, an agent will keep searching, recalculating, and re-checking indefinitely. The step limit prevents this. If you still see loops, add explicit instruction to avoid repeating an action that already returned a result.

Tool misuse. The agent picks a tool based on your description. Vague descriptions produce wrong choices. If your agent keeps calling the wrong tool, rewrite the description before assuming the model is the problem.

Runaway costs. Each thought, action, and observation costs tokens. A poorly constrained agent can take fifty steps and still not finish. Set the cap before you deploy anything.

Confident wrong answers. The agent reasons its way to a conclusion that sounds coherent but is built on a bad early action. Because the reasoning chain looks logical, it's harder to spot than a straightforward hallucination. Requiring the agent to state what it actually learned, not what it expected to learn, surfaces this early.

Reviewing the result

The log the agent returns is not just for debugging. It's how you evaluate whether the answer is trustworthy. Check three things:

  1. Did the agent use the tools it was supposed to use, and only those?
  2. Does each observation actually support the reasoning that follows it?
  3. Did the agent stop because it had enough, or because it hit the step limit?

A result built on a bad observation early in the chain is unreliable even if the final reasoning looks sound. The log shows you where the chain broke, if it broke. Read it before you act on the answer.

Controlling costs and temperature

Use a temperature around 0.1 for ReAct workflows. You want consistent, predictable reasoning, not creative leaps. Higher temperatures cause agents to make unusual tool choices and explore tangents that waste steps.

Monitor behavior during development. Once you trust how the agent handles simple, well-defined problems, increase complexity gradually. The verbose output from the log makes debugging faster than it sounds.