Performance on Agent with Storage

Example showing how to analyze the runtime and memory usage of an Agent that is using storage.

Create a Python file

1"""Run `uv pip install openai kern-ai` to install dependencies."""
2
3from kern.agent import Agent
4from kern.db.sqlite import SqliteDb
5from kern.eval.performance import PerformanceEval
6from kern.models.openai import OpenAIResponses
7
8db = SqliteDb(db_file="tmp/storage.db")
9
10
11def run_agent():
12 agent = Agent(
13 model=OpenAIResponses(id="gpt-5.2"),
14 system_message="Be concise, reply with one sentence.",
15 add_history_to_context=True,
16 db=db,
17 )
18 response_1 = agent.run("What is the capital of France?")
19 print(response_1.content)
20
21 response_2 = agent.run("How many people live there?")
22 print(response_2.content)
23
24 return response_2.content
25
26
27response_with_storage_perf = PerformanceEval(
28 name="Storage Performance",
29 func=run_agent,
30 num_iterations=1,
31 warmup_runs=0,
32)
33
34if __name__ == "__main__":
35 response_with_storage_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_with_storage.py