03 Automatic Cultural Management

Automatically update cultural knowledge based on Agent interactions.

1"""
203 Automatic Cultural Management
3=============================
4
5Automatically update cultural knowledge based on Agent interactions.
6"""
7
8from kern.agent import Agent
9from kern.db.sqlite import SqliteDb
10from kern.models.openai import OpenAIResponses
11
12# ---------------------------------------------------------------------------
13# Step 1. Initialize the database (same one used in 01_create_cultural_knowledge.py)
14# ---------------------------------------------------------------------------
15db = SqliteDb(db_file="tmp/demo.db")
16
17# ---------------------------------------------------------------------------
18# Create Agent
19# ---------------------------------------------------------------------------
20# The Agent will automatically add or update cultural knowledge after each run.
21agent = Agent(
22 db=db,
23 model=OpenAIResponses(id="gpt-5.2"),
24 update_cultural_knowledge=True, # enables automatic cultural updates
25)
26
27# ---------------------------------------------------------------------------
28# Run Agent
29# ---------------------------------------------------------------------------
30if __name__ == "__main__":
31 # ---------------------------------------------------------------------------
32 # Step 3. Ask the Agent to generate a response
33 # ---------------------------------------------------------------------------
34 agent.print_response(
35 "What would be the best way to cook ramen? Detailed and specific instructions generally work better than general advice.",
36 stream=True,
37 markdown=True,
38 )

Run the Example

1# Clone and setup repo
2git clone https://github.com/kern-ai/kern.git
3cd kern/cookbook/02_agents/14_advanced
4
5# Create and activate virtual environment
6./scripts/demo_setup.sh
7source .venvs/demo/bin/activate
8
9python 03_automatic_cultural_management.py