Performance on Agent Instantiation
Example showing how to analyze the runtime and memory usage of an Agent.
Create a Python file
1"""Run `uv pip install kern-ai openai` to install dependencies."""23from kern.agent import Agent4from kern.eval.performance import PerformanceEval567def instantiate_agent():8 return Agent(system_message="Be concise, reply with one sentence.")91011instantiation_perf = PerformanceEval(12 name="Instantiation Performance", func=instantiate_agent, num_iterations=100013)1415if __name__ == "__main__":16 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-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 Agent
1python performance_agent_instantiation.py