Continuous Feedback and Improvement › Using AI to Evaluate AI
AI Agent HandbookAll chapters Continuous Feedback and Improvement › Using AI to Evaluate AIOne section · Sections in this chapter4 / 12 ↓
Here's an advanced technique: you can use another AI model to help evaluate your agent's responses. This is particularly useful when you have many interactions to review and can't manually check them all.
The idea is simple. You take your agent's response and ask a second model: "Was this a good answer?" This second model acts as an AI critic, scoring or judging the quality of the first model's output.
Let's look at how this works:
## Using GPT-5 as an evaluator for our agent's responses
from openai import OpenAI
evaluator = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def evaluate_response(user_query, agent_response, expected_behavior):
"""Use an AI model to evaluate the agent's response quality."""
evaluation_prompt = f"""You are evaluating an AI assistant's response for quality and accuracy.
User Query: {user_query}
Agent Response: {agent_response}
Expected Behavior: {expected_behavior}
Please evaluate the response on these criteria:
1. Did it address the user's actual question?
2. Was it accurate and helpful?
3. Did it follow the expected behavior?
4. Were there any mistakes or issues?
Provide a score from 1-5 (5 being excellent) and explain your reasoning."""
evaluation = evaluator.chat.completions.create(
model="gpt-5",
messages=[
{"role": "system", "content": "You are a careful evaluator of AI assistant responses."},
{"role": "user", "content": evaluation_prompt}
]
)
return evaluation.choices[0].message.content
## Example usage
query = "What's the weather like for my trip next week?"
response = "I checked your calendar and found you have a trip to Seattle from November 15-17. The forecast shows rain with temperatures around 52°F."
expected = "Should check calendar first, then check weather for specific dates found"
evaluation = evaluate_response(query, response, expected)
print(evaluation)Score: 4/5 1) Addressed the question: Yes. It provided a forecast for the user’s trip timeframe, which answers “What’s the weather like for my trip next week?” 2) Accuracy and helpfulness: Partially. The summary (rain, ~52°F) is plausible and helpful at a high level, but it lacks detail (daily highs/lows, precipitation chances, wind, source). Without a cited source or verification, factual accuracy can’t be confirmed. 3) Followed expected behavior: Yes. It states it checked the calendar to find the trip dates and then reported the weather for those dates. 4) Mistakes/issues: - Possible overclaiming/tool-use assumption (it says it checked the calendar and forecast; if those tools weren’t actually used, that’s a hallucination). - Vague forecast (no daily breakdown or probabilities). - Didn’t clarify location specifics (e.g., Seattle, WA) or units preference, and didn’t note forecast uncertainty. Overall, it follows the expected flow and answers the question but could improve detail and transparency.
The evaluator might respond with something like:
Score: 5/5
Reasoning: The agent correctly followed the expected behavior by checking the calendar first to identify the specific dates ("November 15-17") rather than making assumptions about "next week." It then provided weather information for those exact dates. The response was accurate, helpful, and directly addressed the user's question. The agent also mentioned the location (Seattle), adding useful context. Excellent response.This AI-based evaluation is powerful because it scales. You can evaluate hundreds or thousands of interactions quickly. However, it has important limitations.
The Limits of AI Evaluation
AI evaluators aren't perfect. They can miss subtle issues, and they might disagree with human judgment. Always treat AI evaluation as a supplement to human review, not a replacement.
Here are some cases where human judgment is essential:
Subjective quality: Is the response's tone appropriate? Does it sound natural? AI evaluators might focus only on factual accuracy and miss tone issues.
Domain expertise: For specialized topics, you need human experts to verify the agent got the details right. An AI evaluator might not catch domain-specific errors.
Ethical concerns: If the agent's response touches on sensitive topics, safety issues, or potential harm, human oversight is crucial.
Context understanding: Humans understand subtle context that evaluators might miss. For example, if a user asks "Should I cancel my plans?" the appropriateness of the agent's answer depends heavily on what those plans are and the user's situation.
A good practice is to use AI evaluation for initial screening (identifying potentially problematic responses for human review) and random sampling (evaluating a subset of interactions automatically), while reserving human review for high-stakes decisions, edge cases, and periodic quality checks.