Checking and Refining the Agent's Reasoning › Practical Applications

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 › Practical Applications
Reading section 8 of 14 · Practical Applications · 2 minSection 8 of 14 · 2 min

Book contents

Section 8 of 14 · 2 min read

Checking and Refining the Agent's Reasoning › Practical ApplicationsOne section · Sections in this chapter8 / 14 ↓

Let's apply these verification techniques to our personal assistant.

Scenario: Planning a Budget

Your assistant helps you plan monthly expenses. You want it to check its own calculations.

Example (GPT-5)

In[8]:
Code
from openai import OpenAI

client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

budget_problem = """I earn \$4,000 per month after taxes. I want to:
- Save 20% for retirement
- Spend no more than 30% on rent
- Allocate \$400 for groceries
- Set aside \$200 for entertainment
- Keep \$150 for utilities

How much will I have left for other expenses? Create a budget breakdown."""

## Initial budget calculation
response = client.chat.completions.create(
    model="gpt-5",
    messages=[{"role": "user", "content": budget_problem}],
)

initial_budget = response.choices[0].message.content
print("Initial budget:\n", initial_budget)

## Verification with specific checks
verification = client.chat.completions.create(
    model="gpt-5",
    messages=[
        {"role": "user", "content": budget_problem},
        {"role": "assistant", "content": initial_budget},
        {
            "role": "user",
            "content": """Please verify your budget by:

1. Adding up all expenses to confirm they don't exceed \$4,000
2. Checking that percentages are calculated correctly
3. Confirming the remaining amount is accurate
4. Noting if any category seems unrealistic

Show your verification calculations.""",
        },
    ],
)

print("\nVerification:\n", verification.choices[0].message.content)
Out[8]:
Console
Initial budget:
 Here’s a simple monthly budget based on $4,000 take-home pay:

- Retirement savings (20%): $800
- Rent (up to 30%): $1,200
- Groceries: $400
- Entertainment: $200
- Utilities: $150

Total allocated (assuming rent at the 30% cap): $2,750
Left for other expenses: $1,250

Notes:
- This leaves 31.25% of your income for other expenses (transportation, insurance, debt payments, phone/internet, healthcare, clothing, misc, or extra savings).
- If your rent is less than $1,200, the leftover amount will be higher by the difference.

Verification:
 Verification of the proposed budget (assuming rent at the 30% cap):

1) Add up all allocations
- Retirement: $800
- Rent: $1,200
- Groceries: $400
- Entertainment: $200
- Utilities: $150
Total allocated = 800 + 1,200 + 400 + 200 + 150 = $2,750
Check against income: $2,750 ≤ $4,000 (OK)

2) Check percentage calculations
- Retirement: 20% of $4,000 = 0.20 × 4,000 = $800 (matches)
- Rent: 30% of $4,000 = 0.30 × 4,000 = $1,200 (matches)
- Groceries as %: 400 / 4,000 = 10.0%
- Entertainment as %: 200 / 4,000 = 5.0%
- Utilities as %: 150 / 4,000 = 3.75%
- Total % allocated = 20% + 30% + 10% + 5% + 3.75% = 68.75%
- Remaining % = 100% − 68.75% = 31.25%

3) Confirm remaining amount
- Remaining dollars = $4,000 − $2,750 = $1,250
- Cross-check via %: 31.25% × $4,000 = 0.3125 × 4,000 = $1,250 (matches)

4) Notes on realism
- Rent at $1,200 (30%) may be challenging in high-cost areas but is a solid target if feasible.
- Utilities at $150 could be low if it needs to include electric, gas, water, trash, internet, and phone; you may want to budget internet/phone separately in “other expenses.”
- Groceries at $400 is reasonable for one person; for multiple people it may be tight.
- Retirement at 20% of take-home is ambitious and excellent if cash flow allows; ensure you still cover essentials, insurance, and any debt.

Result: Left for other expenses = $1,250. If your actual rent is below $1,200, the remaining amount increases dollar-for-dollar.

The verification might reveal:

Let me verify the budget:

Income: \$4,000

Expenses:
- Retirement (20%): \$4,000 $\times$ 0.20 = \$800 ✓
- Rent (30%): \$4,000 $\times$ 0.30 = \$1,200 ✓
- Groceries: \$400 ✓
- Entertainment: \$200 ✓
- Utilities: \$150 ✓

Total expenses: \$800 + \$1,200 + \$400 + \$200 + \$150 = \$2,750

Remaining: \$4,000 - \$2,750 = \$1,250 ✓

Verification complete. The budget is mathematically correct, and you'll have \$1,250 
remaining for other expenses. All calculations check out.

This systematic verification ensures the budget is accurate before you rely on it.