Accuracy with Database Logging
Example showing how to store evaluation results in the database for tracking and analysis.
Create a Python file
1"""Example showing how to store evaluation results in the database."""23from typing import Optional45from kern.agent import Agent6from kern.db.postgres.postgres import PostgresDb7from kern.eval.accuracy import AccuracyEval, AccuracyResult8from kern.models.openai import OpenAIResponses9from kern.tools.calculator import CalculatorTools1011# Setup the database12db_url = "postgresql+psycopg://ai:ai@localhost:5432/ai"13db = PostgresDb(db_url=db_url, eval_table="eval_runs_cookbook")141516evaluation = AccuracyEval(17 db=db, # Pass the database to the evaluation. Results will be stored in the database.18 name="Calculator Evaluation",19 model=OpenAIResponses(id="gpt-5.2"),20 agent=Agent(21 model=OpenAIResponses(id="gpt-5.2"),22 tools=[CalculatorTools()],23 ),24 input="What is 10*5 then to the power of 2? do it step by step",25 expected_output="2500",26 additional_guidelines="Agent output should include the steps and the final answer.",27 num_iterations=1,28)2930result: Optional[AccuracyResult] = evaluation.run(print_results=True)31assert result is not None and result.avg_score >= 8Set 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 accuracy_db_logging.py