Team Performance with Memory

Example showing how to evaluate team performance with memory tracking and growth monitoring.

Create a Python file

1import asyncio
2import random
3
4from kern.agent import Agent
5from kern.db.postgres import PostgresDb
6from kern.eval.performance import PerformanceEval
7from kern.models.openai import OpenAIResponses
8from kern.team.team import Team
9
10cities = [
11 "New York",
12 "Los Angeles",
13 "Chicago",
14 "Houston",
15 "Miami",
16 "San Francisco",
17 "Seattle",
18 "Boston",
19 "Washington D.C.",
20 "Atlanta",
21 "Denver",
22 "Las Vegas",
23]
24
25
26# Setup the database
27db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
28db = PostgresDb(db_url=db_url)
29
30
31def get_weather(city: str) -> str:
32 return f"The weather in {city} is sunny."
33
34
35weather_agent = Agent(
36 id="weather_agent",
37 model=OpenAIResponses(id="gpt-5.2"),
38 role="Weather Agent",
39 description="You are a helpful assistant that can answer questions about the weather.",
40 instructions="Be concise, reply with one sentence.",
41 tools=[get_weather],
42 db=db,
43 update_memory_on_run=True,
44 add_history_to_context=True,
45)
46
47team = Team(
48 members=[weather_agent],
49 model=OpenAIResponses(id="gpt-5.2"),
50 instructions="Be concise, reply with one sentence.",
51 db=db,
52 markdown=True,
53 update_memory_on_run=True,
54 add_history_to_context=True,
55)
56
57
58async def run_team():
59 random_city = random.choice(cities)
60 _ = team.arun(
61 input=f"I love {random_city}! What weather can I expect in {random_city}?",
62 stream=True,
63 stream_events=True,
64 )
65
66 return "Successfully ran team"
67
68
69team_response_with_memory_impact = PerformanceEval(
70 name="Team Memory Impact",
71 func=run_team,
72 num_iterations=5,
73 warmup_runs=0,
74 measure_runtime=False,
75 debug_mode=True,
76 memory_growth_tracking=True,
77)
78
79if __name__ == "__main__":
80 asyncio.run(
81 team_response_with_memory_impact.arun(print_results=True, print_summary=True)
82 )

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 psycopg

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 Team

1python performance_team_with_memory.py