01 Create Cultural Knowledge

Create cultural knowledge to use with your Agents.

1"""
201 Create Cultural Knowledge
3=============================
4
5Create cultural knowledge to use with your Agents.
6"""
7
8from kern.culture.manager import CultureManager
9from kern.db.sqlite import SqliteDb
10from kern.models.openai import OpenAIResponses
11from rich.pretty import pprint
12
13# ---------------------------------------------------------------------------
14# Step 1. Initialize the database used for storing cultural knowledge
15# ---------------------------------------------------------------------------
16db = SqliteDb(db_file="tmp/demo.db")
17
18# ---------------------------------------------------------------------------
19# Step 2. Create the Culture Manager
20# ---------------------------------------------------------------------------
21# The CultureManager distills reusable insights into the shared cultural layer
22# that your Agents can access for consistent reasoning and behavior.
23culture_manager = CultureManager(
24 db=db,
25 model=OpenAIResponses(id="gpt-5.2"),
26)
27
28# ---------------------------------------------------------------------------
29# Step 3. Create cultural knowledge from a message
30# ---------------------------------------------------------------------------
31# You can feed in any insight, principle, or lesson you’d like the system to remember.
32# The model will generalize it into structured cultural knowledge entries.
33#
34# For example:
35# - Communication best practices
36# - Decision-making patterns
37# - Design or engineering principles
38#
39# Try to phrase inputs as *reusable truths* or *guiding principles*,
40# not one-off observations.
41message = (
42 "All technical guidance should follow the 'Operational Thinking' principle:\n"
43 "\n"
44 "1. **State the Objective** — What outcome are we trying to achieve and why.\n"
45 "2. **Show the Procedure** — List clear, reproducible steps (prefer commands or configs).\n"
46 "3. **Surface Pitfalls** — Mention what usually fails and how to detect it early.\n"
47 "4. **Define Validation** — How to confirm it’s working (logs, tests, metrics).\n"
48 "5. **Close the Loop** — Suggest next iterations or improvements.\n"
49 "\n"
50 "Keep answers short, structured, and directly actionable. Avoid general theory unless "
51 "it informs an operational decision."
52)
53
54culture_manager.create_cultural_knowledge(message=message)
55
56# ---------------------------------------------------------------------------
57# Step 4. Retrieve and inspect the stored cultural knowledge
58# ---------------------------------------------------------------------------
59cultural_knowledge = culture_manager.get_all_knowledge()
60
61# ---------------------------------------------------------------------------
62# Run Agent
63# ---------------------------------------------------------------------------
64if __name__ == "__main__":
65 print("\n=== Cultural Knowledge Entries ===")
66 pprint(cultural_knowledge)

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 01_create_cultural_knowledge.py