1from kern.agent import Agent
2from kern.db.postgres import PostgresDb
3from kern.models.perplexity import Perplexity
4from rich.pretty import pprint
5
6db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
7agent = Agent(
8 model=Perplexity(id="sonar-pro"),
9 # Store the memories and summary in a database
10 db=PostgresDb(db_url=db_url),
11 update_memory_on_run=True,
12 enable_session_summaries=True,
13)
14
15# -*- Share personal information
16agent.print_response("My name is john billings", stream=True)
17# -*- Print memories and summary
18if agent.db:
19 pprint(agent.get_user_memories(user_id="test_user"))
20 pprint(
21 agent.get_session(session_id="test_session").summary # type: ignore
22 )
23
24# -*- Share personal information
25agent.print_response("I live in nyc", stream=True)
26# -*- Print memories and summary
27if agent.db:
28 pprint(agent.get_user_memories(user_id="test_user"))
29 pprint(
30 agent.get_session(session_id="test_session").summary # type: ignore
31 )
32
33# -*- Share personal information
34agent.print_response("I'm going to a concert tomorrow", stream=True)
35# -*- Print memories and summary
36if agent.db:
37 pprint(agent.get_user_memories(user_id="test_user"))
38 pprint(
39 agent.get_session(session_id="test_session").summary # type: ignore
40 )
41
42# Ask about the conversation
43agent.print_response(
44 "What have we been talking about, do you know my name?", stream=True
45)