Checking and Refining the Agent's Reasoning › Combining Verification with Chain-of-Thought

Michael BrenndoerferJune 19, 20252 min read
AI Agent HandbookAll chapters
Part 4 of 15Reasoning - Teaching the Agent to Think
Chapter 11Checking and Refining the Agent's Reasoning › Combining Verification with Chain-of-Thought
Reading section 11 of 14 · Combining Verification with Chain-of-Thought · 2 minSection 11 of 14 · 2 min

Book contents

Section 11 of 14 · 2 min read

Checking and Refining the Agent's Reasoning › Combining Verification with Chain-of-ThoughtOne section · Sections in this chapter11 / 14 ↓

Verification works even better when combined with chain-of-thought reasoning from the previous chapter. Here's the pattern:

  1. Think step by step (chain-of-thought): Break down the problem
  2. Solve: Work through each step
  3. Verify: Check the reasoning and calculations
  4. Refine: Correct any errors found

This three-stage process (think, solve, verify) creates a robust reasoning pipeline for your agent.

Example (Claude Sonnet 4.5)

In[9]:
Code
from anthropic import Anthropic

client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))

problem = """A rectangular garden is 12 meters long and 8 meters wide. 
You want to build a path 1 meter wide around the entire garden. 
What is the area of the path?"""

## Stage 1 & 2: Chain-of-thought solving
response = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": f"""{problem}

Think through this step by step:

1. What are the dimensions of the garden?
2. What will be the dimensions including the path?
3. How can you calculate the path area?

Solve the problem showing your work.""",
        }
    ],
)

solution = response.content[0].text
print("Solution:", solution)

## Stage 3: Verification
verification = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": f"""{problem}

Your solution:
{solution}

Verify by:

1. Checking dimensions are correct
2. Confirming area calculations
3. Ensuring you calculated the path area, not the total area

If you find errors, provide a corrected solution.""",
        }
    ],
)

print("\nVerification:", verification.content[0].text)
Out[9]:
Console
Solution: # Solving the Garden Path Problem

Let me work through this step by step.

## Step 1: Dimensions of the garden

The garden is a rectangle with:
- **Length = 12 meters**
- **Width = 8 meters**
- **Area of garden = 12 × 8 = 96 m²**

## Step 2: Dimensions including the path

The path is 1 meter wide and goes around the **entire** garden, which means it adds 1 meter on **all sides**.

So we add:
- 1 meter on the left + 1 meter on the right = 2 meters to the width
- 1 meter on the top + 1 meter on the bottom = 2 meters to the length

New dimensions (garden + path):
- **Length = 12 + 2 = 14 meters**
- **Width = 8 + 2 = 10 meters**
- **Total area = 14 × 10 = 140 m²**

## Step 3: Calculate the path area

The path area is the difference between the total area and the garden area:

**Path area = Total area - Garden area**

**Path area = 140 - 96 = 44 m²**

## Answer

The area of the path is **44 square meters**.

Verification: Your solution is **completely correct**! Let me verify each step:

## Verification

### Step 1: Garden dimensions ✓
- Length = 12 meters
- Width = 8 meters
- Garden area = 12 × 8 = 96 m² ✓

### Step 2: Outer dimensions (garden + path) ✓
You correctly identified that a 1-meter path around the **entire** garden adds:
- 1 meter on each side (left AND right) = +2 meters to width
- 1 meter on each end (top AND bottom) = +2 meters to length

Outer dimensions:
- Length = 12 + 2 = 14 meters ✓
- Width = 8 + 2 = 10 meters ✓
- Total area = 14 × 10 = 140 m² ✓

### Step 3: Path area calculation ✓
Path area = Total area - Garden area
Path area = 140 - 96 = **44 m²** ✓

## Alternative verification method:

The path can be thought of as four rectangles (with overlapping corners):
- Two long sides: 2 × (12 × 1) = 24 m²
- Two short sides: 2 × (8 × 1) = 16 m²
- Four corners: 4 × (1 × 1) = 4 m²
- Total: 24 + 16 + 4 = 44 m² ✓

**Your answer of 44 square meters is correct!** 🎉

This combined approach gives you both the benefits of structured thinking and the safety of verification.