Code

cookbook/memory/db/mem-postgres-memory.py
from agno.agent import Agent
from agno.db.postgres import PostgresDb

# Setup Postgres
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
db = PostgresDb(db_url=db_url)

agent = Agent(
    db=db,
    enable_user_memories=True,
)

agent.print_response("My name is John Doe and I like to play basketball on the weekends.")
agent.print_response("What's do I do in weekends?")

Usage

1

Create a virtual environment

Open the Terminal and create a python virtual environment.
python3 -m venv .venv
source .venv/bin/activate
2

Set environment variables

export OPENAI_API_KEY=xxx
3

Install libraries

pip install -U agno openai sqlalchemy 'psycopg[binary]'
4

Run Example

python cookbook/memory/db/mem-postgres-memory.py