Reliability with Database Logging
Example showing how to store reliability evaluation results in the database.
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.reliability import ReliabilityEval, ReliabilityResult8from kern.models.openai import OpenAIResponses9from kern.run.agent import RunOutput10from kern.tools.calculator import CalculatorTools1112# Setup the database13db_url = "postgresql+psycopg://ai:ai@localhost:5432/ai"14db = PostgresDb(db_url=db_url, eval_table="eval_runs")151617agent = Agent(18 model=OpenAIResponses(id="gpt-5.2"),19 tools=[CalculatorTools()],20)21response: RunOutput = agent.run("What is 10!?")2223evaluation = ReliabilityEval(24 db=db, # Pass the database to the evaluation. Results will be stored in the database.25 name="Tool Call Reliability",26 agent_response=response,27 expected_tool_calls=["factorial"],28)29result: Optional[ReliabilityResult] = evaluation.run(print_results=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 reliability_db_logging.py