Performance with Database Logging
Example showing how to store performance evaluation results in the database.
Create a Python file
1"""Example showing how to store evaluation results in the database."""23from kern.agent import Agent4from kern.db.postgres.postgres import PostgresDb5from kern.eval.performance import PerformanceEval6from kern.models.openai import OpenAIResponses789# Simple function to run an agent which performance we will evaluate10def run_agent():11 agent = Agent(12 model=OpenAIResponses(id="gpt-5.2"),13 system_message="Be concise, reply with one sentence.",14 )15 response = agent.run("What is the capital of France?")16 print(response.content)17 return response181920# Setup the database21db_url = "postgresql+psycopg://ai:ai@localhost:5432/ai"22db = PostgresDb(db_url=db_url, eval_table="eval_runs_cookbook")2324simple_response_perf = PerformanceEval(25 db=db, # Pass the database to the evaluation. Results will be stored in the database.26 name="Simple Performance Evaluation",27 func=run_agent,28 num_iterations=1,29 warmup_runs=0,30)3132if __name__ == "__main__":33 simple_response_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-ai psycopgExport 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_db_logging.py