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."""
2
3from kern.agent import Agent
4from kern.eval.performance import PerformanceEval
5
6
7def instantiate_agent():
8 return Agent(system_message="Be concise, reply with one sentence.")
9
10
11instantiation_perf = PerformanceEval(
12 name="Instantiation Performance", func=instantiate_agent, num_iterations=1000
13)
14
15if __name__ == "__main__":
16 instantiation_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

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