Memory
Store personalized memories and session summaries with Claude on Vertex AI using PostgreSQL.
The source uses claude-sonnet-4@20250514, which Anthropic lists as deprecated on Google Cloud. Google's Sonnet 4 card does not establish a completed retirement. For a new deployment, choose a current model and its supported settings, such as Sonnet 4.6. Provider availability and lifecycle dates can differ from the direct Anthropic API.
"""
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 anthropic sqlalchemy 'psycopg[binary]' pgvector` to install the dependencies
3. Run: `python cookbook/90_models/vertexai/claude/memory.py` to run the agent
"""
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.vertexai.claude import Claude
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
# Setup the database
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
db = PostgresDb(db_url=db_url)
agent = Agent(
model=Claude(id="claude-sonnet-4@20250514"),
# Pass the database to the Agent
db=db,
# Store the memories and summary in the database
update_memory_on_run=True,
enable_session_summaries=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
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
passRun the Example
Use the standalone setup below; the repository-relative commands in the source docstring assume a cookbook checkout. This is a single-user demo: without user_id, memories use the default user bucket. For an application, pass a stable authenticated user_id to the Agent or each run. Also reuse a stable session_id when resuming a conversation after restarting the script. The memory and summary managers inherit this agent’s Vertex model.
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno "anthropic[vertex]" "psycopg[binary]" sqlalchemySet up Google Cloud access
Use a project with billing and aiplatform.googleapis.com enabled, enable the chosen Claude model in Model Garden, and give your calling identity permission to use it. Follow Google's Claude setup guide. Install the Google Cloud CLI for the local sign-in command below.
Set the project and a location supported by your model. us-east5 is a supported example for Sonnet 4 and Sonnet 4.6; check the model's current availability before switching models or locations.
export ANTHROPIC_VERTEX_PROJECT_ID="your-project-id"
export CLOUD_ML_REGION="us-east5"Authenticate locally with Application Default Credentials:
gcloud auth application-default loginADC supplies credentials; it does not enable models or grant IAM permissions. These examples authenticate to Google Cloud without an Anthropic API key.
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:18Run the example
Save the code above as memory.py, then run:
python memory.pyFull source: cookbook/90_models/vertexai/claude/memory.py