Governance with Vertex AI Memory Bank

Source notebook

Repo path: agents/agent_engine/memory_bank/get_started_with_memory_bank_governance.ipynb · Open on GitHub · advanced

Builds a governed Vertex AI Memory Bank with TTL, topics, revision history, rollback, and cleanup.

Summary

This notebook teaches how to use Vertex AI Memory Bank governance features for a customer support agent. It demonstrates creating an Agent Engine with Memory Bank, adding and generating customer memories, configuring granular TTL retention, filtering by managed topics, inspecting revisions, rolling back to a prior revision, filtering revisions by labels, and deleting resources.

Key code patterns

Initialize Vertex AI client

import vertexai
 
client = vertexai.Client(
    project=PROJECT_ID,
    location=LOCATION,
)

Creates the Vertex AI client used for Agent Engine, sessions, memories, and revisions.

Create Memory Bank Agent Engine

basic_memory_config = MemoryBankConfig(
    similarity_search_config=SimilaritySearchConfig(
        embedding_model=f"projects/{PROJECT_ID}/locations/{LOCATION}/publishers/google/models/text-embedding-005"
    ),
    generation_config=GenerationConfig(
        model=f"projects/{PROJECT_ID}/locations/{LOCATION}/publishers/google/models/gemini-2.5-flash"
    ),
)
agent_engine = client.agent_engines.create(
    config={"context_spec": {"memory_bank_config": basic_memory_config}}
)

Defines embedding and generation models before provisioning the Agent Engine container.

Generate memories from session

operation = client.agent_engines.memories.generate(
    name=agent_engine_name,
    vertex_session_source={"session": session_name},
    config={"wait_for_completion": True},
)

Extracts structured customer facts from a support conversation stored as session events.

Configure granular TTL

ttl_config = TtlConfig(
    granular_ttl_config=GranularTtlConfig(
        create_ttl="2592000s",
        generate_created_ttl="7776000s",
        generate_updated_ttl="31536000s",
    )
)

Applies different retention windows for manual, newly generated, and updated memories.

Rollback memory revision

rollback_operation = client.agent_engines.memories.rollback(
    name=rollback_memory_name,
    target_revision_id=previous_revision_id,
)

Restores a memory to a previous verified revision after an incorrect update.

Models & APIs used

  • Models: text-embedding-005, gemini-2.5-flash
  • APIs / services: Vertex AI, Vertex AI Agent Engine, Vertex AI Memory Bank
  • SDKs / libraries: vertexai, google-cloud-aiplatform

When to use this

Use this pattern when building support agents that need governed long-term memory with retention, auditability, and rollback.

Gotchas & caveats

  • Requires an existing Google Cloud project with the Vertex AI API enabled.
  • Colab users must authenticate with google.colab.auth.authenticate_user().
  • Notebook installs google-cloud-aiplatform>=1.123.0 for Memory Bank features.
  • LOCATION defaults to us-central1 in the notebook.
  • Manual create is described as limited and does not provide consolidation benefits.
  • Cleanup deletes the Agent Engine with force=True, removing contained memories and sessions.

Best practices

  • Use GenerateMemories with direct_memories_source or direct_contents_source when consolidation is needed instead of manual create.
  • Set granular TTL values for different memory creation and update paths.
  • Use scopes such as user_id to isolate customer memories.
  • Use managed topic labels to filter customer data by category.
  • Use revision labels such as data_source and verified for governance workflows.
  • Delete the Agent Engine when finished to avoid unnecessary costs.