Persistent Session
Persistent Session Example.
1"""2Persistent Session3=============================45Persistent Session Example.6"""78from kern.agent.agent import Agent9from kern.db.postgres import PostgresDb10from kern.models.openai import OpenAIResponses1112db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"1314db = PostgresDb(db_url=db_url, session_table="sessions")1516# ---------------------------------------------------------------------------17# Create Agent18# ---------------------------------------------------------------------------19agent = Agent(20 model=OpenAIResponses(id="gpt-5-mini"),21 db=db,22 session_id="session_storage",23 add_history_to_context=True,24)2526# ---------------------------------------------------------------------------27# Run Agent28# ---------------------------------------------------------------------------29if __name__ == "__main__":30 agent.print_response("Tell me a new interesting fact about space")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 persistent_session.py