Batch Agent-as-Judge Evaluation

Judge three pre-supplied customer-service cases with binary scoring, persist the evaluation runs in SqliteDb, and report the result pass rate.

Demonstrates evaluating multiple cases in one run.

pass_rate uses the returned evaluations as its denominator. If two of three judge calls fail, one passing result can still report 100%. Check the returned count against the submitted cases before reporting batch success.

agent_as_judge_batch.py
"""
Batch Agent-as-Judge Evaluation
===============================

Demonstrates evaluating multiple cases in one run.
"""

from agno.db.sqlite import SqliteDb
from agno.eval.agent_as_judge import AgentAsJudgeEval

# ---------------------------------------------------------------------------
# Create Database
# ---------------------------------------------------------------------------
db = SqliteDb(db_file="tmp/agent_as_judge_batch.db")

# ---------------------------------------------------------------------------
# Create Evaluation
# ---------------------------------------------------------------------------
evaluation = AgentAsJudgeEval(
    name="Customer Service Quality",
    criteria="Response should be empathetic, professional, and helpful",
    scoring_strategy="binary",
    db=db,
)

# ---------------------------------------------------------------------------
# Run Evaluation
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    result = evaluation.run(
        cases=[
            {
                "input": "My order is delayed and I'm very upset!",
                "output": "I sincerely apologize for the delay. I understand how frustrating this must be. Let me check your order status right away and see how we can make this right for you.",
            },
            {
                "input": "Can you help me with a refund?",
                "output": "Of course! I'd be happy to help with your refund. Could you please provide your order number so I can process this quickly for you?",
            },
            {
                "input": "Your product is terrible!",
                "output": "I'm sorry to hear you're disappointed. Your feedback is valuable to us. Could you share more details about what went wrong so we can improve?",
            },
        ],
        print_results=True,
        print_summary=True,
    )

    print(f"Pass rate: {result.pass_rate:.1f}%")
    print(f"Passed: {sum(1 for r in result.results if r.passed)}/{len(result.results)}")

    print("Database Results:")
    eval_runs = db.get_eval_runs()
    print(f"Total evaluations stored: {len(eval_runs)}")
    if eval_runs:
        latest = eval_runs[0]
        print(f"Run ID: {latest.run_id}")
        print(f"Cases evaluated: {len(result.results)}")

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai sqlalchemy

Export your API keys

export OPENAI_API_KEY="your_openai_api_key_here"

Reject incomplete batches

Replace the complete if __name__ == "__main__": block with:

batch completeness check
if __name__ == "__main__":
    cases = [
        {
            "input": "My order is delayed and I'm very upset!",
            "output": "I sincerely apologize for the delay. I understand how frustrating this must be. Let me check your order status right away and see how we can make this right for you."
        },
        {
            "input": "Can you help me with a refund?",
            "output": "Of course! I'd be happy to help with your refund. Could you please provide your order number so I can process this quickly for you?"
        },
        {
            "input": "Your product is terrible!",
            "output": "I'm sorry to hear you're disappointed. Your feedback is valuable to us. Could you share more details about what went wrong so we can improve?"
        }
    ]
    result = evaluation.run(cases=cases, print_results=False, print_summary=False)
    if result is None or len(result.results) != len(cases):
        completed = len(result.results) if result is not None else 0
        raise RuntimeError(f"Incomplete evaluation: {completed}/{len(cases)} cases")
    print(f"Pass rate: {result.pass_rate:.1f}%")
    print(f"Passed: {sum(item.passed for item in result.results)}/{len(cases)}")
    eval_runs = db.get_eval_runs()
    print(f"Evaluation runs stored: {len(eval_runs)}")

Binary results use passed; their numeric score is normally None. The completeness check concerns the number of evaluated cases, not the presence of a numeric score.

Run the example

Save the code above as agent_as_judge_batch.py, then run:

python agent_as_judge_batch.py

Full source: cookbook/09_evals/agent_as_judge/agent_as_judge_batch.py