./cookbook/scripts/run_pgvector.sh to start a postgres container with pgvector 2. Run: uv pip install ollama sqlalchemy 'psycopg[binary]' pgvector to install the dependencies 3. Run: python cookbook/92_models/ollama/memory.py to run the agent
Copy
Ask AI
"""
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: `uv pip install ollama sqlalchemy 'psycopg[binary]' pgvector` to install the dependencies
3. Run: `python cookbook/92_models/ollama/memory.py` to run the agent
"""
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.ollama.chat import Ollama
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
# Setup the database
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
db = PostgresDb(db_url=db_url)
agent = Agent(
model=Ollama(id="qwen2.5:latest"),
# Pass the database to the Agent
db=db,
# Enable user memories
update_memory_on_run=True,
# Enable session summaries
enable_session_summaries=True,
# Show debug logs so, you can see the memory being created
)
# -*- 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
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
pass
Run the Example
Copy
Ask AI
# Clone and setup repo
git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/90_models/ollama/chat
# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate
# Optiona: Run PgVector (needs docker)
./cookbook/scripts/run_pgvector.sh
python memory.py