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."""23from kern.agent import Agent4from kern.eval.performance import PerformanceEval5from kern.models.openai import OpenAIResponses678def run_agent():9 agent = Agent(10 model=OpenAIResponses(id="gpt-5.2"),11 system_message="Be concise, reply with one sentence.",12 )1314 response = agent.run("What is the capital of France?")15 print(f"Agent response: {response.content}")1617 return response181920simple_response_perf = PerformanceEval(21 name="Simple Performance Evaluation",22 func=run_agent,23 num_iterations=1,24 warmup_runs=0,25)2627if __name__ == "__main__":28 simple_response_perf.run(print_results=True, print_summary=True)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 openai kern-ai memory_profilerExport 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