Performance on Agent Response

Example showing how to analyze the runtime and memory usage of an Agent's run, given its response.

Create a Python file

1"""Run `uv pip install openai kern-ai memory_profiler` to install dependencies."""
2
3from kern.agent import Agent
4from kern.eval.performance import PerformanceEval
5from kern.models.openai import OpenAIResponses
6
7
8def run_agent():
9 agent = Agent(
10 model=OpenAIResponses(id="gpt-5.2"),
11 system_message="Be concise, reply with one sentence.",
12 )
13
14 response = agent.run("What is the capital of France?")
15 print(f"Agent response: {response.content}")
16
17 return response
18
19
20simple_response_perf = PerformanceEval(
21 name="Simple Performance Evaluation",
22 func=run_agent,
23 num_iterations=1,
24 warmup_runs=0,
25)
26
27if __name__ == "__main__":
28 simple_response_perf.run(print_results=True, print_summary=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 memory_profiler

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_simple_response.py