01 Create Cultural Knowledge
Create cultural knowledge to use with your Agents.
1"""201 Create Cultural Knowledge3=============================45Create cultural knowledge to use with your Agents.6"""78from kern.culture.manager import CultureManager9from kern.db.sqlite import SqliteDb10from kern.models.openai import OpenAIResponses11from rich.pretty import pprint1213# ---------------------------------------------------------------------------14# Step 1. Initialize the database used for storing cultural knowledge15# ---------------------------------------------------------------------------16db = SqliteDb(db_file="tmp/demo.db")1718# ---------------------------------------------------------------------------19# Step 2. Create the Culture Manager20# ---------------------------------------------------------------------------21# The CultureManager distills reusable insights into the shared cultural layer22# that your Agents can access for consistent reasoning and behavior.23culture_manager = CultureManager(24 db=db,25 model=OpenAIResponses(id="gpt-5.2"),26)2728# ---------------------------------------------------------------------------29# Step 3. Create cultural knowledge from a message30# ---------------------------------------------------------------------------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 practices36# - Decision-making patterns37# - Design or engineering principles38#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)5354culture_manager.create_cultural_knowledge(message=message)5556# ---------------------------------------------------------------------------57# Step 4. Retrieve and inspect the stored cultural knowledge58# ---------------------------------------------------------------------------59cultural_knowledge = culture_manager.get_all_knowledge()6061# ---------------------------------------------------------------------------62# Run Agent63# ---------------------------------------------------------------------------64if __name__ == "__main__":65 print("\n=== Cultural Knowledge Entries ===")66 pprint(cultural_knowledge)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 01_create_cultural_knowledge.py