Async Performance Evaluation

Example showing how to run performance evaluations on async functions.

Create a Python file

1"""This example shows how to run a Performance evaluation on an async function."""
2
3import asyncio
4
5from kern.agent import Agent
6from kern.eval.performance import PerformanceEval
7from kern.models.openai import OpenAIResponses
8
9
10# Simple async function to run an Agent.
11async def arun_agent():
12 agent = Agent(
13 model=OpenAIResponses(id="gpt-5.2"),
14 system_message="Be concise, reply with one sentence.",
15 )
16 response = await agent.arun("What is the capital of France?")
17 return response
18
19
20performance_eval = PerformanceEval(func=arun_agent, num_iterations=10)
21
22# Because we are evaluating an async function, we use the arun method.
23asyncio.run(performance_eval.arun(print_summary=True, print_results=True))

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Install dependencies

1uv pip install -U openai kern-ai

Export your OpenAI API key

1export OPENAI_API_KEY="your_openai_api_key_here"
1$Env:OPENAI_API_KEY="your_openai_api_key_here"

Run Agent

1python performance_async.py