Generative AI and Agentic AILangChain 1.4 · LangGraph 1.2 · Python 3.12 or 3.13
Dashboard
0%

ReAct agents

A ReAct agent is an agent that repeats three steps, reasoning about what to do, acting by calling a tool, and observing the result, until it can answer.

Last updated: 08 Oct, 2026 · LangChain 1.4

An agent that calls one tool and stops can only answer questions with one lookup in them. Many questions need a second step that depends on the first: find a price, then multiply it. ReAct is the pattern that handles this, and create_agent from AI agents is built on it.

The video reaches the pattern from a mistake. Its chatbot graph is asked for the recent AI news and then to multiply 5 by 10. The model calls the search tool, the tool's output goes straight to the end of the graph, and only the first half of the question is answered. The clip shows why, and what changes.

Reason, act and observe

Why the tool result goes back to the model · from the Complete Agentic AI Course video · 3:53:10 to 3:58:42

The name ReAct comes from a 2022 paper, ReAct: Synergizing Reasoning and Acting in Language Models. The clip lists the three terms as act, observe and reason. In the loop they run in this order:

  • Reason. The model reads everything so far and decides what to do next: call a tool, or answer.
  • Act. The model asks for a tool call and the tool runs.
  • Observe. The tool result comes back and joins the messages. The model reads it and goes back to reasoning.
The ReAct loop: the model reasons and decides it needs a tool, acts by calling the tool, observes the tool result, and goes back to reasoning; when nothing is left it gives the final answer.

The loop ends when the model answers without a tool call. In the clip's example the model finds the news, then multiplies, then writes one answer that covers both parts. What stops the first graph from doing that is a single edge: the tool's output must return to the model, not to the end.

Building a ReAct agent with create_agent

The video builds the loop by hand in a graph, by changing one edge. The code here uses create_agent, which builds the same loop without writing the graph; the edge version is in LangGraph essentials. Older tutorials use create_react_agent from langgraph.prebuilt. That function is deprecated, and create_agent from langchain.agents replaces it.

Two tools where the second depends on the first

A shop catalogue gives get_price and a calculator gives multiply. The question "How much do 7 notebooks cost?" needs both, in order: the price first, then the product.

python
from langchain.tools import tool

PRICES = {"notebook": 45.0, "pen": 12.5, "bag": 650.0}

@tool
def get_price(item: str) -> float:
    """Get the price in rupees of one item from the shop catalogue: notebook, pen or bag."""
    return PRICES[item]

@tool
def multiply(a: float, b: float) -> float:
    """Multiply two numbers."""
    return a * b

The agent

The system prompt tells the model which tool to use for which job. Nothing forces a model to call a tool, and a short instruction makes it more likely.

python
from langchain.agents import create_agent

agent = create_agent(
    model="groq:openai/gpt-oss-120b",
    tools=[get_price, multiply],
    system_prompt="Use get_price for prices and multiply for every multiplication.",
)

Watching the loop run

Printing every message shows each pass: what the model asked for, and what came back.

ExampleAPI keyRun on Groq
question = "How much do 7 notebooks cost?"
result = agent.invoke({"messages": [{"role": "user", "content": question}]})

for message in result["messages"]:
    calls = [(c["name"], c["args"]) for c in message.tool_calls] if message.type == "ai" else []
    print(message.type, "|", calls or message.content)
  • Reason, then act. The first model message has no text, only a call to get_price with {'item': 'notebook'}.
  • Observe. The tool message holds 45.0, the catalogue price.
  • Reason and act again. With the price in the messages, the model asks for multiply with 7 and 45. This second call depends on the first result, so the model could not have made it before the first tool ran.
  • Observe, then answer. The tool returns 315.0 and the model writes the final message from it. The loop stopped because that last message holds no tool call.

Capping the loop with recursion_limit

Each pass through the model node and each pass through the tools node counts as one step. recursion_limit in the run's config sets the most steps one run may take, so an agent that keeps asking for tools cannot loop for ever. When the limit is reached before the agent finishes, LangGraph raises GraphRecursionError. A limit of 3 is too small for the two-tool question above:

ExampleAPI keyRun on Groq
from langgraph.errors import GraphRecursionError

try:
    agent.invoke({"messages": [{"role": "user", "content": question}]}, config={"recursion_limit": 3})
except GraphRecursionError as error:
    print(type(error).__name__)
    print(str(error).splitlines()[0])

The run took a model step, a tools step and a second model step, then reached the limit before the second tool call could run. The error names the config key to raise. Choose a limit that fits the longest honest run of the task; a small multiple of the expected number of steps is a sensible safety net.

One tool call vs the ReAct loop

Tool result goes to the endTool result goes back to the model
StepsModel, tool, stopModel, tool, model, and again as needed
Two-step questionOnly the first step is doneEach step is done in turn
Final messageThe tool's outputThe model's answer
CostFewer model callsOne model call per pass

LangGraph essentials builds both versions by hand, with one changed edge between them, and runs them side by side.

Where you use ReAct agents

  • Chained lookups. Find a customer, then their latest order, then the refund rule for that order.
  • Lookup then calculation. A price, a rate or a balance followed by arithmetic on it.
  • Questions with an unknown number of steps. Research tasks where each result decides what to ask next.
Watch out. Nothing makes the model use a tool. A model may answer from memory and skip a lookup, or do arithmetic in its head and get it wrong. Say in the system prompt which tool handles which job, set a recursion_limit, and read the message list when an answer looks off.
Try it yourself
  • Ask "What do 3 pens and 2 bags cost together?" and count the tool calls. On Groq, gpt-oss asks for one tool per reply, so more steps mean more rounds.
  • Raise recursion_limit to 6 for the capped example and run it again. The run finishes.
  • Remove the system prompt and ask the same question. Check whether the agent still calls multiply.
PreviousTool calling

Slow is fine. Stopping is the only problem.