Performance on Agent Instantiation with Tool
Example showing how to analyze the runtime and memory usage of an Agent that is using tools.
Create a Python file
1"""Run `uv pip install kern-ai openai memory_profiler` to install dependencies."""23from typing import Literal45from kern.agent import Agent6from kern.eval.performance import PerformanceEval7from kern.models.openai import OpenAIResponses8910def get_weather(city: Literal["nyc", "sf"]):11 """Use this to get weather information."""12 if city == "nyc":13 return "It might be cloudy in nyc"14 elif city == "sf":15 return "It's always sunny in sf"161718tools = [get_weather]192021def instantiate_agent():22 return Agent(model=OpenAIResponses(id="gpt-5.2"), tools=tools) # type: ignore232425instantiation_perf = PerformanceEval(26 name="Tool Instantiation Performance", func=instantiate_agent, num_iterations=100027)2829if __name__ == "__main__":30 instantiation_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_instantiation_with_tool.py