Accuracy with Teams
Example showing how to evaluate the accuracy of an Kern Team.
Create a Python file
1from typing import Optional23from kern.agent import Agent4from kern.eval.accuracy import AccuracyEval, AccuracyResult5from kern.models.openai import OpenAIResponses6from kern.team import Team78# Setup a team with two members9english_agent = Agent(10 name="English Agent",11 role="You only answer in English",12 model=OpenAIResponses(id="gpt-5.2"),13)14spanish_agent = Agent(15 name="Spanish Agent",16 role="You can only answer in Spanish",17 model=OpenAIResponses(id="gpt-5.2"),18)1920multi_language_team = Team(21 name="Multi Language Team",22 model=OpenAIResponses(id="gpt-5.2"),23 members=[english_agent, spanish_agent],24 respond_directly=True,25 markdown=True,26 instructions=[27 "You are a language router that directs questions to the appropriate language agent.",28 "If the user asks in a language whose agent is not a team member, respond in English with:",29 "'I can only answer in the following languages: English and Spanish.",30 "Always check the language of the user's input before routing to an agent.",31 ],32)3334# Evaluate the accuracy of the Team's responses35evaluation = AccuracyEval(36 name="Multi Language Team",37 model=OpenAIResponses(id="gpt-5.2"),38 team=multi_language_team,39 input="Comment allez-vous?",40 expected_output="I can only answer in the following languages: English and Spanish.",41 num_iterations=1,42)4344result: Optional[AccuracyResult] = evaluation.run(print_results=True)45assert result is not None and result.avg_score >= 8Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall dependencies
1uv pip install -U openai kern-aiExport your OpenAI API key
1export OPENAI_API_KEY="your_openai_api_key_here"1$Env:OPENAI_API_KEY="your_openai_api_key_here"Run Team
1python accuracy_with_teams.py