Introduction to Reasoning › Teaching Reasoning Through Examples
Michael BrenndoerferJune 21, 20252 min read
AI Agent HandbookAll chapters Part 4 of 15Reasoning - Teaching the Agent to Think
Introduction to Reasoning › Teaching Reasoning Through ExamplesOne section · Sections in this chapter5 / 14 ↓
Sections in this chapter14
Just like with other prompting strategies, you can teach reasoning by showing examples. This is especially useful when you want the agent to follow a specific reasoning format or approach.
Few-Shot Reasoning
Here's how you might use examples to teach a reasoning pattern:
Question: If 5 apples cost \$3, how much do 8 apples cost?
Reasoning:
- First, find the cost per apple: \$3 $\div$ 5 apples = \$0.60 per apple
- Then multiply by 8 apples: \$0.60 $\times$ 8 = \$4.80
Answer: \$4.80
Question: If 3 books weigh 6 pounds, how much do 7 books weigh?
Reasoning:
- First, find the weight per book: 6 pounds $\div$ 3 books = 2 pounds per book
- Then multiply by 7 books: 2 pounds $\times$ 7 = 14 pounds
Answer: 14 pounds
Question: If 4 tickets cost \$50, how much do 9 tickets cost?By showing the pattern in the first two examples, you're teaching the agent how to structure its reasoning for the third question. The model will recognize the pattern: find the unit rate, then scale up.
Example (GPT-5)
Here's how this looks in code:
In[2]:
Codefrom openai import OpenAI
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
prompt = """Solve these word problems by showing your reasoning step by step.
Question: If 5 apples cost \$3, how much do 8 apples cost?
Reasoning:
- First, find the cost per apple: \$3 $\div$ 5 apples = \$0.60 per apple
- Then multiply by 8 apples: \$0.60 $\times$ 8 = \$4.80
Answer: \$4.80
Question: If 3 books weigh 6 pounds, how much do 7 books weigh?
Reasoning:
- First, find the weight per book: 6 pounds $\div$ 3 books = 2 pounds per book
- Then multiply by 7 books: 2 pounds $\times$ 7 = 14 pounds
Answer: 14 pounds
Question: If 4 tickets cost \$50, how much do 9 tickets cost?
Reasoning:"""
response = client.chat.completions.create(
model="gpt-5", messages=[{"role": "user", "content": prompt}]
)
print(response.choices[0].message.content)The agent will follow the pattern you've established, breaking down the problem into unit cost and then scaling up.