Performance with Memory Updates

Example showing how to evaluate performance when memory updates are involved.

Create a Python file

1"""Run `uv pip install openai kern-ai memory_profiler` 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
8# Memory creation requires a db to be provided
9db = SqliteDb(db_file="tmp/memory.db")
10
11
12def run_agent():
13 agent = Agent(
14 model=OpenAIResponses(id="gpt-5.2"),
15 system_message="Be concise, reply with one sentence.",
16 db=db,
17 update_memory_on_run=True,
18 )
19
20 response = agent.run("My name is Tom! I'm 25 years old and I live in New York.")
21 print(f"Agent response: {response.content}")
22
23 return response
24
25
26response_with_memory_updates_perf = PerformanceEval(
27 name="Memory Updates Performance",
28 func=run_agent,
29 num_iterations=5,
30 warmup_runs=0,
31)
32
33if __name__ == "__main__":
34 response_with_memory_updates_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 memory_profiler

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