Memory
Use Perplexity for answers and an OpenAI memory manager to persist user memories in Postgres.
The source below reads user/session IDs it never sets, then dereferences a missing session. Its inherited Perplexity memory manager also cannot call the memory-storage tools through this adapter. Run the complete Current Example with explicit identity and a tool-capable memory model.
"""
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 openai sqlalchemy 'psycopg[binary]' pgvector` to install the dependencies
3. Run: `python cookbook/agents/personalized_memories_and_summaries.py` to run the agent
"""
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.perplexity import Perplexity
from rich.pretty import pprint
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
agent = Agent(
model=Perplexity(id="sonar-pro"),
# Store the memories and summary in a database
db=PostgresDb(db_url=db_url),
update_memory_on_run=True,
enable_session_summaries=True,
)
# -*- Share personal information
agent.print_response("My name is john billings?", stream=True)
# -*- Print memories and summary
if agent.db:
pprint(agent.get_user_memories(user_id="test_user"))
pprint(
agent.get_session(session_id="test_session").summary # type: ignore
)
# -*- Share personal information
agent.print_response("I live in nyc?", stream=True)
# -*- Print memories and summary
if agent.db:
pprint(agent.get_user_memories(user_id="test_user"))
pprint(
agent.get_session(session_id="test_session").summary # type: ignore
)
# -*- Share personal information
agent.print_response("I'm going to a concert tomorrow?", stream=True)
# -*- Print memories and summary
if agent.db:
pprint(agent.get_user_memories(user_id="test_user"))
pprint(
agent.get_session(session_id="test_session").summary # type: ignore
)
# 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__":
passCurrent Example
Perplexity answers and generates summaries; the OpenAI memory manager writes memories to the same database. Reuse these demo IDs for the same person/conversation and assign different user IDs to different people. Both providers need account/model access.
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.memory import MemoryManager
from agno.models.openai import OpenAIChat
from agno.models.perplexity import Perplexity
from rich.pretty import pprint
user_id = "test_user"
session_id = "test_session"
db = PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")
agent = Agent(
model=Perplexity(id="sonar-pro"),
db=db,
user_id=user_id,
session_id=session_id,
memory_manager=MemoryManager(model=OpenAIChat(id="gpt-5.6-luna"), db=db),
update_memory_on_run=True,
enable_session_summaries=True,
add_history_to_context=True,
)
for message in (
"My name is John Billings.",
"I live in NYC.",
"I'm going to a concert tomorrow.",
):
agent.print_response(message, stream=True)
pprint(agent.get_user_memories(user_id=user_id))
session = agent.get_session(session_id=session_id)
if session is not None:
pprint(session.summary)
agent.print_response("What have we been talking about, do you know my name?", stream=True)Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno "psycopg[binary]" openai sqlalchemyExport your Perplexity API key
export PERPLEXITY_API_KEY="your_perplexity_api_key_here"Run PgVector
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql \
-v pgvolume:/var/lib/postgresql \
-p 5532:5432 \
--name pgvector \
agnohq/pgvector:18Set the memory model key
export OPENAI_API_KEY="your_openai_api_key_here"Run the example
Save the complete Current Example above as memory.py, then run:
python memory.pyFull source: cookbook/90_models/perplexity/memory.py