Course contentsShow
← AI Engineering
Lesson 183 of 1,8865. Advanced Prompting TechniquesFree lesson

Few-Shot ReAct Examples

Using few-shot examples that demonstrate complete Thought-Action-Observation sequences.

Few-Shot ReAct Examples

What you'll learn: How to use example Thought-Action-Observation sequences to teach an LLM the ReAct pattern.

The Core Idea

Just like you learned with few-shot learning earlier, showing the model complete examples of the Thought-Action-Observation loop dramatically improves its ability to follow the ReAct pattern. Instead of just describing what you want, you demonstrate 1-3 full cycles where the model thinks, takes an action, and receives an observation—then draws a conclusion.

Think of it like teaching someone to cook by showing them complete recipe walkthroughs, not just listing the tools. They see how thinking ("I need more flavor") leads to action ("add salt") leads to observation ("tastes better") leads to the next thought.

What Goes in a Few-Shot ReAct Example

Each example should show a complete mini-episode:

Question: What's the population of France's capital?

Thought: I need to identify France's capital first.
Action: search["capital of France"]
Observation: Paris is the capital of France.

Thought: Now I need the population of Paris.
Action: search["population of Paris"]
Observation: Paris has approximately 2.1 million residents.

Thought: I have the answer.
Answer: Approximately 2.1 million people.

Why This Works

By providing 1-2 examples like this before your actual question, you're showing the model:

  • The exact format for thoughts and actions
  • How to chain reasoning across observations
  • When to stop and provide a final answer
  • How to parse action syntax you expect

The model learns the pattern through imitation, much more reliably than from instructions alone.

Key Takeaway: Few-shot ReAct examples demonstrate complete Thought-Action-Observation-Answer sequences, teaching the model your exact format and reasoning pattern through concrete demonstrations rather than abstract instructions.