Agent as Judge with Teams
Evaluating team outputs with Agent as Judge
This example demonstrates evaluating team outputs using Agent as Judge evaluation.
Add the following code to your Python file
1from typing import Optional23from kern.agent import Agent4from kern.db.sqlite import SqliteDb5from kern.eval.agent_as_judge import AgentAsJudgeEval, AgentAsJudgeResult6from kern.models.openai import OpenAIResponses7from kern.team.team import Team89# Setup database to persist eval results10db = SqliteDb(db_file="tmp/agent_as_judge_team.db")1112# Setup a team with researcher and writer13researcher = Agent(14 name="Researcher",15 role="Research and gather information",16 model=OpenAIResponses(id="gpt-5.2"),17)1819writer = Agent(20 name="Writer",21 role="Write clear and concise summaries",22 model=OpenAIResponses(id="gpt-5.2"),23)2425research_team = Team(26 name="Research Team",27 model=OpenAIResponses(id="gpt-5.2"),28 members=[researcher, writer],29 instructions=["First research the topic thoroughly, then write a clear summary."],30 db=db,31)3233response = research_team.run("Explain quantum computing")3435evaluation = AgentAsJudgeEval(36 name="Team Response Quality",37 model=OpenAIResponses(id="gpt-5.2"),38 criteria="Response should be well-researched, clear, and comprehensive with good flow",39 scoring_strategy="binary",40 db=db,41)4243result: Optional[AgentAsJudgeResult] = evaluation.run(44 input="Explain quantum computing",45 output=str(response.content),46 print_results=True,47 print_summary=True,48)4950# Query database for stored results51print("Database Results:")52eval_runs = db.get_eval_runs()53print(f"Total evaluations stored: {len(eval_runs)}")54if eval_runs:55 latest = eval_runs[-1]56 print(f"Eval ID: {latest.run_id}")57 print(f"Team: {research_team.name}")Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall dependencies
1uv pip install -U kern-ai openaiExport your OpenAI API key
1export OPENAI_API_KEY="your_openai_api_key_here"1$Env:OPENAI_API_KEY="your_openai_api_key_here"Run the example
1python agent_as_judge_team.py