Quickstart
Enable learning in your agents.
Enable Learning
The simplest way: set learning=True.
1from kern.agent import Agent2from kern.db.sqlite import SqliteDb3from kern.models.openai import OpenAIResponses45agent = Agent(6 model=OpenAIResponses(id="gpt-5.2"),7 db=SqliteDb(db_file="tmp/agents.db"),8 learning=True,9)This enables user profile and user memory extraction in Always mode. The agent automatically captures information and recalls it in future sessions.
Test It
1# Session 1: Share information2agent.print_response(3 "Hi! I'm Sarah, I work at Acme Corp as a data scientist.",4 user_id="sarah@acme.com",5 session_id="session_1",6)78# Session 2: Agent remembers9agent.print_response(10 "What do you know about me?",11 user_id="sarah@acme.com",12 session_id="session_2",13)Session 2 is a new conversation, but the agent remembers Sarah.
Choose What Gets Learned
For more control, configure stores individually:
1from kern.learn import LearningMachine23agent = Agent(4 model=OpenAIResponses(id="gpt-5.2"),5 db=db,6 learning=LearningMachine(7 user_profile=True, # Structured facts (name, role, preferences)8 user_memory=True, # Unstructured observations9 session_context=True, # Session summary and goals10 entity_memory=False, # Facts about external entities11 learned_knowledge=False # Insights across users (requires Knowledge)12 ),13)See Learning Stores for details on each store.
Choose How Learning Happens
Each store can use a different learning mode:
1from kern.learn import (2 LearningMachine,3 LearningMode,4 UserProfileConfig,5 UserMemoryConfig,6)78agent = Agent(9 model=OpenAIResponses(id="gpt-5.2"),10 db=db,11 learning=LearningMachine(12 user_profile=UserProfileConfig(mode=LearningMode.ALWAYS),13 user_memory=UserMemoryConfig(mode=LearningMode.AGENTIC),14 ),15)| Mode | How it works |
|---|---|
| Always | Extraction runs automatically after each response |
| Agentic | Agent receives tools and decides what to save |
| Propose | Agent proposes learnings, you approve before saving |
See Learning Modes for details.
Production Database
For production, use PostgreSQL:
1from kern.db.postgres import PostgresDb23db = PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")45agent = Agent(6 model=OpenAIResponses(id="gpt-5.2"),7 db=db,8 learning=True,9)