By Sagar Shankaran, Founder of CallSphere
Understand the ReAct (Reasoning + Acting) pattern that powers most modern AI agents, with a step-by-step breakdown of observation loops and a working Python implementation.
Key takeaways
ReAct stands for Reasoning + Acting. Introduced in a 2022 research paper by Yao et al., it is the foundational pattern behind nearly every modern AI agent. The core idea is simple: instead of having an LLM generate a final answer in one shot, you let it alternate between thinking (reasoning) and doing (acting), with observations from the environment feeding back into the next reasoning step.
This alternation is what gives agents their power. A single LLM call might hallucinate an answer. A ReAct loop grounds the LLM's reasoning in real data from real tools.
Each iteration of a ReAct loop has three phases:
flowchart TD
USER(["User message"])
LLM["LLM call<br/>with tools schema"]
DECIDE{"Model wants<br/>to call a tool?"}
EXEC["Execute tool<br/>sandboxed runtime"]
RESULT["Append tool_result<br/>to messages"]
GUARD{"Output passes<br/>guardrails?"}
DONE(["Final reply"])
BLOCK(["Refuse and log"])
USER --> LLM --> DECIDE
DECIDE -->|Yes| EXEC --> RESULT --> LLM
DECIDE -->|No| GUARD
GUARD -->|Yes| DONE
GUARD -->|No| BLOCK
style LLM fill:#4f46e5,stroke:#4338ca,color:#fff
style EXEC fill:#ede9fe,stroke:#7c3aed,color:#1e1b4b
style GUARD fill:#f59e0b,stroke:#d97706,color:#1f2937
style DONE fill:#059669,stroke:#047857,color:#fff
style BLOCK fill:#dc2626,stroke:#b91c1c,color:#fff
User: "What is the current stock price of AAPL and is it above its 50-day average?"
Thought 1: I need to look up the current AAPL stock price first.
Action 1: get_stock_price(symbol="AAPL")
Observation 1: {"price": 187.42, "currency": "USD", "timestamp": "2026-03-17T14:30:00Z"}
Thought 2: The current price is $187.42. Now I need the 50-day moving average.
Action 2: get_moving_average(symbol="AAPL", days=50)
Observation 2: {"average": 182.15, "period_days": 50}
Thought 3: AAPL is at $187.42, above its 50-day average of $182.15. I can answer now.
Action 3: respond("AAPL is currently at $187.42, which is above its 50-day
moving average of $182.15 by approximately $5.27 or 2.9%.")
Notice how each thought is informed by the previous observation. The agent does not guess — it retrieves real data and then reasons about it.
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
Chain-of-Thought (CoT) prompting asks the LLM to think step by step, but all reasoning happens internally without access to external information. This means CoT is limited by what the model already knows (its training data), and it can confidently produce wrong answers.
ReAct fixes this by interleaving actions between thoughts. The LLM can verify its assumptions, fetch current data, and correct course based on real observations.
| Approach | Grounded in real data? | Multi-step? | Can use tools? |
|---|---|---|---|
| Direct prompting | No | No | No |
| Chain-of-Thought | No | Yes (internal) | No |
| ReAct | Yes | Yes | Yes |
Here is a working ReAct agent using the OpenAI API with function calling:
import json
import openai
client = openai.OpenAI()
# Define the tools the agent can use
tools = [
{
"type": "function",
"function": {
"name": "search_web",
"description": "Search the web for current information",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "Search query"}
},
"required": ["query"],
},
},
},
{
"type": "function",
"function": {
"name": "calculate",
"description": "Evaluate a mathematical expression",
"parameters": {
"type": "object",
"properties": {
"expression": {"type": "string", "description": "Math expression"}
},
"required": ["expression"],
},
},
},
]
def execute_tool(name: str, arguments: dict) -> str:
"""Execute a tool and return the result as a string."""
if name == "search_web":
# In production, call a real search API
return json.dumps({"results": [f"Result for: {arguments['query']}"]})
elif name == "calculate":
try:
result = eval(arguments["expression"]) # Use a safe evaluator in production
return json.dumps({"result": result})
except Exception as e:
return json.dumps({"error": str(e)})
return json.dumps({"error": f"Unknown tool: {name}"})
def react_agent(user_input: str, max_iterations: int = 10) -> str:
messages = [
{"role": "system", "content": "You are a helpful agent. Use tools to find "
"accurate information before answering. Think step by step."},
{"role": "user", "content": user_input},
]
for i in range(max_iterations):
response = client.chat.completions.create(
model="gpt-4o",
messages=messages,
tools=tools,
)
choice = response.choices[0]
messages.append(choice.message)
# If no tool calls, the agent is done reasoning
if not choice.message.tool_calls:
return choice.message.content
# Execute each tool call (Action) and add results (Observation)
for tool_call in choice.message.tool_calls:
args = json.loads(tool_call.function.arguments)
result = execute_tool(tool_call.function.name, args)
messages.append({
"role": "tool",
"tool_call_id": tool_call.id,
"content": result, # This is the Observation
})
return "Agent reached maximum iterations without a final answer."
# Run the agent
answer = react_agent("What is 15% of the population of France?")
print(answer)
The key insight is on line where we check if not choice.message.tool_calls. When the LLM decides it has enough information, it responds with text instead of a tool call — that is how ReAct agents naturally terminate.
ReAct is powerful but not perfect. It struggles with tasks that require long-horizon planning (more than 8-10 steps), because LLMs can lose track of their overall goal as context grows. For those cases, you layer planning patterns on top of ReAct — decompose the task into subtasks first, then use ReAct for each subtask.
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
ReAct also depends entirely on tool quality. If your tools return ambiguous or inconsistent results, the agent's reasoning degrades. Investing in clear tool descriptions and reliable tool implementations is just as important as prompt engineering.
Function calling is the mechanism (how the LLM requests a tool execution). ReAct is the pattern (alternating reasoning and acting in a loop). ReAct uses function calling as its action mechanism, but adds the structured loop of thought-action-observation that continues until the task is complete.
For most tasks, 5 to 15 iterations is sufficient. Set a maximum to prevent runaway loops and cost explosions. If your agent consistently hits the limit, the task is likely too complex for a single ReAct loop — consider decomposing it into subtasks instead.
Yes. Any LLM that supports function calling or structured output can run a ReAct loop. Models like Llama 3, Mistral, and Qwen all support tool use. The quality of reasoning depends on model capability, but the pattern itself is model-agnostic.
#ReAct #AIAgents #Reasoning #ToolUse #Python #AgenticAI #LearnAI #AIEngineering

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
A founder's guide to the personal AI assistant market: best AI assistant apps, business-grade options, and how CallSphere's voice agent fits in.
A founder's guide to free AI agents, low-code AI agent builders, and how to know when you should pay for a real platform like CallSphere.
Graphiti is the open-source temporal knowledge graph for AI agents in 2026. Learn how bi-temporal memory beats vector RAG for voice agents and long-running LLMs.
Chatbot app vs ChatGPT in 2026: a founder's clear take on the difference, when to use which, and how a real AI chatbot app development works.
How we built a fault-tolerant HVAC emergency triage and tech-dispatch platform on Kubernetes — three-tier CQRS, 11 micro-agents on the OpenAI Agents SDK + LangGraph, NATS JetStream, DTMF/SMS/WebSocket acceptance, circuit breakers, and an evaluation pipeline that catches regressions before they wake a tech at 3 AM.
GPT-Realtime-2 brings GPT-5-class reasoning into voice. What that means for tool-call reliability, structured output, and production agent design.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco