Agents & Reasoning

ReAct, chain-of-thought, planning, tool use, function calling

Advanced35 min

Prerequisites

  • prompt-engineering

ChatGPT can answer questions. But can it book you a flight? Check your calendar, find available dates, search for cheap flights, and email you the confirmation? That requires more than language understanding — it requires planning, reasoning, and the ability to use tools. That's what AI agents do.

A regular chatbot is stateless. You ask, it answers, done. An agent is different. It observes the world, thinks about what to do next, takes an action, sees the result, thinks again, and keeps going until the task is done. It can call APIs, query databases, search the web, run code, write files — anything you can express as a function. The key innovation is the loop: LLMs stop after generating one response, but agents keep going.

This shift from passive question-answering to active goal-driven behavior is one of the most important developments in AI. An LLM with a ReAct loop and a few tools can do things that feel almost autonomous: debugging code by running tests and fixing errors iteratively, researching a topic by searching, reading, and synthesizing sources, or booking travel by checking constraints, comparing options, and making decisions. Agents are not magic — they are LLMs in a loop with tool access. But the combination unlocks capabilities that pure language modeling cannot provide.

From chatbot to agent

A chatbot is a one-shot system. You send a prompt, the model generates a response, and the interaction ends. An agent is a loop. It observes the current state, decides what to do, takes an action, observes the result, and repeats until it reaches a goal or decides it cannot proceed. This simple shift — from one-shot generation to iterative action — is what transforms a language model into something that can autonomously accomplish tasks.

The agent loop has a few key components. First, you need a way for the model to take actions beyond generating text. This is where tool use (also called function calling) comes in. You define a set of functions the model can call: get_weather, search_web, run_python_code, send_email, whatever is relevant to your use case. The model learns to output structured calls to these functions instead of (or in addition to) natural language.

The Agent Loop

Task
User gives a goal
Think
Reason about what to do
Act
Call a tool or function
Observe
Get result from tool
Done?
Goal achieved or stuck?
Final Answer
Return result to user

The second component is reasoning. The model needs to think out loud about what it has learned, what it still needs to know, and what action to take next. This is where techniques like chain-of-thought and ReAct (Reasoning + Acting) come in. By prompting the model to alternate between thought and action, you get a transparent, debuggable loop where each step builds on the last.

The third component is planning. For complex tasks that require multiple steps, the agent needs to break the problem down into sub-goals, track progress, and adjust the plan when things go wrong. Advanced agents use tree-of-thought (exploring multiple reasoning paths in parallel) or hierarchical planning (breaking tasks into subtasks recursively). The goal is to avoid getting stuck in unproductive loops or giving up too early.

How agents think and act

The magic of agents is in the interplay between four core techniques: ReAct (reasoning and acting interleaved), chain-of-thought (step-by-step reasoning), tool use (calling external functions), and planning (multi-step goal decomposition). These are not separate systems — they work together to turn an LLM into something that can autonomously pursue goals.

ReAct — Reasoning + Acting Interleaved

ReAct is the core pattern that makes agents work. Instead of prompting the model to just generate an answer, you prompt it to alternate between Thought (internal reasoning) and Action (calling a tool or function). After each action, the environment provides an Observation (the result of that action). The model then thinks again, decides the next action, and the loop continues until it outputs a final answer.

Thought: I need to check the weather in Paris
Action: get_weather(city="Paris")
Observation: Temperature: 15°C, Rain: 80%
Thought: 80% rain probability is high, umbrella needed
Final Answer: Yes, bring an umbrella. It's 15°C with 80% chance of rain in Paris.

The ReAct paper (Yao et al., 2022) showed that this interleaved format dramatically improves task success rates on question-answering and interactive environments compared to either pure reasoning or pure action. By making the agent's thoughts explicit, you also get interpretability for free: you can see exactly why the agent took each action. This is critical for debugging and building trust.

Step 1 of 4

Watch a ReAct agent in action

This interactive visualizer shows a ReAct agent loop solving different tasks. Pick a scenario, then step through the loop one action at a time (or click Auto to watch it play out). Notice how the agent alternates between Thought (reasoning), Action (calling a tool), and Observation (getting results) until it reaches a Final Answer. This is the core pattern behind every agent system.

Select a task scenario:
Task:
What's the weather in Paris and should I bring an umbrella?
Click Step or Auto
💭
Thought
I need to check the weather in Paris first
Breaking down the task: get weather data, then make a recommendation based on that data
ReAct Loop Components:
💭
Thought
Action
👁️
Observation
Final Answer

Key Takeaways

  • An agent is an LLM in a loop: observe → think → act → observe → repeat. This simple pattern transforms a passive chatbot into an active system that can pursue goals autonomously.
  • ReAct (Reasoning + Acting) is the core technique. The model alternates between Thought (internal reasoning), Action (calling a tool), and Observation (seeing the result). This interleaving dramatically improves task success and provides transparency into the agent's decision-making.
  • Chain-of-thought prompting ("Let's think step by step") is critical for multi-step reasoning. By breaking problems into intermediate steps, agents can solve tasks that would fail with one-shot prompting.
  • Tool use (function calling) is what turns a language model into an agent. By defining functions the model can call — search, calculator, code execution, APIs — you give the agent the ability to interact with the world beyond text generation.
  • Planning is the hardest part. Simple ReAct loops work for 2-5 step tasks, but complex goals require hierarchical planning (breaking tasks into subtasks) or tree-of-thought (exploring multiple reasoning paths). Current research focuses on hybrid approaches combining LLMs with classical planning algorithms.

Common Misconceptions

  • "Agents are magic and can do anything." -- They are not. Agents are LLMs in a loop with tool access. They inherit all the limitations of LLMs (hallucination, lack of true reasoning, no world model) plus new failure modes (infinite loops, tool misuse, poor planning). Agents work well for tasks with clear sub-goals and reliable tools, but they struggle with long-horizon planning, ambiguous objectives, and environments where tools frequently fail.

Quick check

What makes a ReAct agent different from a regular chatbot?