Session Summary
This example shows how to use the session summary to store the conversation summary.
1"""2Session Summary3=============================45This example shows how to use the session summary to store the conversation summary.6"""78from kern.agent.agent import Agent9from kern.db.postgres import PostgresDb10from kern.models.openai import OpenAIResponses11from kern.session.summary import SessionSummaryManager # noqa: F4011213db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"1415db = PostgresDb(db_url=db_url, session_table="sessions")1617# Method 1: Set enable_session_summaries to True1819# ---------------------------------------------------------------------------20# Create Agent21# ---------------------------------------------------------------------------22agent = Agent(23 model=OpenAIResponses(id="gpt-5-mini"),24 db=db,25 enable_session_summaries=True,26 session_id="session_123",27)2829# ---------------------------------------------------------------------------30# Run Agent31# ---------------------------------------------------------------------------32if __name__ == "__main__":33 agent.print_response("Hi my name is John and I live in New York")34 agent.print_response("I like to play basketball and hike in the mountains")3536 print(agent.get_session_summary(session_id="session_123"))3738 # Method 2: Set session_summary_manager3940 # session_summary_manager = SessionSummaryManager(model=OpenAIResponses(id="gpt-5-mini"))4142 # agent = Agent(43 # model=OpenAIResponses(id="gpt-5-mini"),44 # db=db,45 # session_id="session_summary",46 # session_summary_manager=session_summary_manager,47 # )4849 # agent.print_response("Hi my name is John and I live in New York")50 # agent.print_response("I like to play basketball and hike in the mountains")Run the Example
1# Clone and setup repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/02_agents/05_state_and_session45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python session_summary.py