Code
memory.py
Usage
1
Set up your virtual environment
2
Install Ollama
Follow the Ollama installation guide and run:
3
Install dependencies
4
Run Agent
Save the code above as
memory.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Persist user memories and session summaries in Postgres for an Ollama qwen2.5 agent across a multi-turn conversation.
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.ollama.chat import Ollama
# 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
)
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install Ollama
ollama pull qwen2.5:latest
Install dependencies
uv pip install -U ollama agno sqlalchemy psycopg pgvector
Run Agent
memory.py, then run:python memory.py
Was this page helpful?