Quickstart

Enable learning in your agents.

Enable Learning

The simplest way: set learning=True.

1from kern.agent import Agent
2from kern.db.sqlite import SqliteDb
3from kern.models.openai import OpenAIResponses
4
5agent = 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 information
2agent.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)
7
8# Session 2: Agent remembers
9agent.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 LearningMachine
2
3agent = 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 observations
9 session_context=True, # Session summary and goals
10 entity_memory=False, # Facts about external entities
11 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)
7
8agent = 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)
ModeHow it works
AlwaysExtraction runs automatically after each response
AgenticAgent receives tools and decides what to save
ProposeAgent proposes learnings, you approve before saving

See Learning Modes for details.

Production Database

For production, use PostgreSQL:

1from kern.db.postgres import PostgresDb
2
3db = PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")
4
5agent = Agent(
6 model=OpenAIResponses(id="gpt-5.2"),
7 db=db,
8 learning=True,
9)

Next Steps