ReAct Pattern: Interleaving Reasoning and Action for LLM Agents › Worked Example: Multi-Hop Question Answering
Language AI HandbookAll chapters ReAct Pattern: Interleaving Reasoning and Action for LLM Agents › Worked Example: Multi-Hop Question AnsweringOne section · Sections in this chapter5 / 14 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Let's trace through a concrete ReAct execution for the query: "What is the population of the city where the author of 'The Old Man and the Sea' was born?"
This question requires three distinct information retrieval steps: finding the author, then their birthplace, then the population of that city. Each step depends on the result of the previous one, which makes this a canonical multi-hop reasoning problem. A model without tool access would need to rely entirely on its parametric memory for all three facts, which introduces significant hallucination risk, especially for the specific population figure.
The dependency structure is:
You cannot resolve the left side without resolving the right side first, which makes this unsolvable with a single tool call. The agent must execute the chain from right to left, resolving each dependency before proceeding.
Step 1: Initial Thought and Action
The model receives the question and generates an initial plan:
Thought: I need to identify the author of 'The Old Man and the Sea' first.
I believe this is Ernest Hemingway, but I should verify with a search.
Action: search[author of The Old Man and the Sea]
Notice how the thought explicitly states the immediate goal. The model acknowledges it already has a hypothesis (Hemingway) but chooses to verify rather than assume. This metacognitive pattern, being aware that parametric knowledge can be wrong and deferring to retrieval, is exactly what we want.
Step 2: Observation and Reformulation
The environment returns factual data:
Observation: Ernest Hemingway wrote The Old Man and the Sea in 1952.
The model now incorporates this observation and updates its plan:
Thought: The author is Ernest Hemingway. Now I need to find where he was born.
Action: search[Ernest Hemingway birthplace]
The thought explicitly names the newly confirmed fact ("The author is Ernest Hemingway") and then states the next open question. This structure, state what you now know and then state what you still need, is a reliable template for well-structured thoughts.
Step 3: Second Information Retrieval
The environment provides the next fact:
Observation: Ernest Hemingway was born in Oak Park, Illinois.
The model updates its understanding and identifies the final missing piece:
Thought: Hemingway was born in Oak Park, Illinois. Now I need the population of Oak Park.
Action: search[population of Oak Park Illinois]
Step 4: Final Retrieval and Termination
The observation provides the final required fact:
Observation: Oak Park, Illinois has a population of 54,583 as of the 2020 census.
The final thought demonstrates task completion recognition:
Thought: I now have all the information needed. Oak Park, Illinois is where Hemingway was born,
and its population is 54,583.
Action: finish[54,583]
Notice how each thought explicitly references the previous observation, creating a coherent chain of evidence that can be audited. The trajectory is a complete written record of how the agent reasoned from question to answer, which makes it possible to diagnose exactly where things went wrong when they do.
If the second search had returned "Ernest Hemingway was born in Key West, Florida" (which is wrong but plausible), the agent would have searched for Key West's population and returned an incorrect answer. This illustrates the retrieval quality dependence that we will discuss in the limitations section.