Culture Metrics
Track culture model token usage under the culture_model detail key.
1"""Culture model token usage tracked under the "culture_model" detail key."""23from kern.agent import Agent4from kern.culture.manager import CultureManager5from kern.db.postgres import PostgresDb6from kern.models.openai import OpenAIChat7from rich.pretty import pprint89db = PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")1011agent = Agent(12 model=OpenAIChat(id="gpt-4o-mini"),13 culture_manager=CultureManager(model=OpenAIChat(id="gpt-4o-mini"), db=db),14 update_cultural_knowledge=True,15 db=db,16)1718if __name__ == "__main__":19 run_response = agent.run(20 "Our team always does code reviews before merging. We pair program on complex features."21 )2223 print("=" * 50)24 print("RUN METRICS")25 print("=" * 50)26 pprint(run_response.metrics)2728 print("=" * 50)29 print("MODEL DETAILS")30 print("=" * 50)31 if run_response.metrics and run_response.metrics.details:32 for model_type, model_metrics_list in run_response.metrics.details.items():33 print(f"\n{model_type}:")34 for model_metric in model_metrics_list:35 pprint(model_metric)Run the Example
1# Clone and setup repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/02_agents/14_advanced45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python culture_metrics.py