-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathmemory.py
41 lines (35 loc) · 1.47 KB
/
memory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
This recipe shows how to use personalized memories and summaries in an agent.
Steps:
1. Run: `./cookbook/scripts/run_pgvector.sh` to start a postgres container with pgvector
2. Run: `pip install anthropic sqlalchemy 'psycopg[binary]' pgvector` to install the dependencies
3. Run: `python cookbook/models/anthropic/memory.py` to run the agent
"""
from agno.agent import Agent, AgentMemory
from agno.memory.db.postgres import PgMemoryDb
from agno.models.anthropic import Claude
from agno.storage.postgres import PostgresStorage
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
agent = Agent(
model=Claude(id="claude-3-5-sonnet-20241022"),
# Store the memories and summary in a database
memory=AgentMemory(
db=PgMemoryDb(table_name="agent_memory", db_url=db_url),
create_user_memories=True,
create_session_summary=True,
),
# Store agent sessions in a database
storage=PostgresStorage(table_name="personalized_agent_sessions", db_url=db_url),
# Show debug logs so, you can see the memory being created
# debug_mode=True,
)
# -*- Share personal information
agent.print_response("My name is john billings?", stream=True)
# -*- Share personal information
agent.print_response("I live in nyc?", stream=True)
# -*- Share personal information
agent.print_response("I'm going to a concert tomorrow?", stream=True)
# Ask about the conversation
agent.print_response(
"What have we been talking about, do you know my name?", stream=True
)