ReAct Pattern: Interleaving Reasoning and Action for LLM Agents › ReAct Prompting Strategies
Language AI HandbookAll chapters ReAct Pattern: Interleaving Reasoning and Action for LLM Agents › ReAct Prompting StrategiesOne section · Sections in this chapter4 / 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
Effective ReAct implementation requires careful prompt engineering that teaches the model the available tools and the pattern of reasoning that connects thoughts to actions and incorporates observations into an evolving understanding. The prompt is more than instructions: it is a behavioral specification that shapes every aspect of how the agent reasons.
Few-Shot Prompting
The standard approach provides two to three examples of successful ReAct trajectories before presenting the actual task. Each example should demonstrate multiple things:
- How to format thoughts (free-form but task-focused reasoning, neither too brief nor too verbose)
- How to format actions (strict syntax for reliable parsing)
- How to incorporate observations into subsequent reasoning steps
- How to recognize when you have enough information to call
finish - Ideally, at least one example where an initial approach fails and the agent recovers
Example 1:
Question: What is the elevation of the mountain range where Mount Everest is located?
Thought: I need to find which mountain range Mount Everest belongs to, then find the elevation of that range.
Action: search[Mount Everest mountain range]
Observation: Mount Everest is in the Himalayas.
Thought: Now I need to find the elevation of the Himalayas.
Action: search[elevation of Himalayas]
Observation: The Himalayas have an average elevation of 20,000 feet (6,100 meters).
Thought: I have found the answer.
Action: finish[20,000 feet (6,100 meters)]
Example 2:
[...]
These examples serve as behavioral templates, showing the model how to decompose complex queries into manageable steps, how to recover from unexpected observations, and how to know when sufficient information has been gathered to provide a final answer. The quality of these examples has a large effect on agent performance. Poorly constructed examples that skip reasoning steps or use inconsistent formatting produce agents that make the same mistakes.
Choosing the Right Number of Examples
More examples are not always better. For highly capable models like GPT-4 or Claude 3, two or three carefully chosen examples often suffice. For smaller or older models, four or five examples may be needed to establish the pattern reliably. Beyond about six examples, the law of diminishing returns sets in, and the additional tokens are better spent on a longer system prompt with clearer tool descriptions.
The diversity of examples matters as much as their number. If all your examples show simple two-step retrievals, the agent will struggle with tasks requiring computation, backtracking, or multi-step dependency chains. Include at least one example that involves a calculation, one that requires multiple searches on different topics, and one where a search returns partial or ambiguous information.
Zero-Shot ReAct
While few-shot prompting works well for highly capable models, some situations call for zero-shot prompting: explicit instruction templates that describe the pattern without examples. This approach is useful when the action space is novel (and therefore no prior examples exist), when context window limits prevent including examples, or when the model is large enough to generalize from instructions alone.
You are an AI assistant that helps users by thinking step-by-step and using tools when necessary.
For each step, you must provide:
1. Thought: Your reasoning about what to do next
2. Action: One of [search[query], calculate[expr], finish[answer]]
3. Observation: (provided by system after Action)
Current Task: {task}
Thought:
The zero-shot approach relies on the model's pre-trained understanding of task decomposition and tool use patterns, which makes it more flexible but potentially less reliable than few-shot examples for complex reasoning chains. In practice, the gap between few-shot and zero-shot narrows as model capability increases: a sufficiently large and capable model can infer the pattern from the instruction alone.
System Prompt Design
Beyond the examples themselves, the system prompt must convey several things clearly:
- The available tools and exactly what each one does
- The expected output format for each action
- Any constraints (for example, maximum number of iterations, policies on when to use which tool)
- The stopping condition (when should the agent call
finish)
The tool descriptions deserve special attention. A vague tool description like "search: searches for things" is far less effective than "search[query]: Performs a keyword search and returns the top 3 most relevant results. Use this for factual questions, current events, or when you need information not in your training data." Detailed descriptions reduce the rate at which models misuse tools or fail to use them when appropriate.