Agent Platform メモリバンクを使用するには、まず Gemini Enterprise Agent Platform インスタンスを作成して構成する必要があります。このインスタンスは記憶を管理し、さまざまなランタイムのエージェントと統合できます。
このドキュメントでは、 Google Cloud プロジェクトを設定し、 必要なライブラリをインストールして、トピックや TTL などのカスタム構成 でインスタンスを作成または更新する方法について説明します。
使ってみる
メモリバンク を使用する前に、環境を設定する必要があります。
プロジェクトを設定する Google Cloud
すべてのプロジェクトは、プロジェクト番号またはプロジェクト ID によって識別できます。PROJECT_NUMBER はプロジェクトの作成時に自動的に作成されますが、PROJECT_ID はプロジェクトの作成者が作成します。プロジェクトを設定するには:
- アカウントにログインします。 Google Cloud を初めて使用する場合は、 アカウントを作成して、実際のシナリオで Google プロダクトのパフォーマンスを評価してください。 Google Cloud新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Agent Platform API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Agent Platform API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.
必要なロールを取得する
Memory Bank の使用に必要な権限を取得するには、プロジェクトに対する次の IAM ロールを付与するよう管理者に依頼してください。
-
すべて:
Agent Platform ユーザー (
roles/aiplatform.user)
ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。
必要な権限は、カスタム ロールや他の事前定義 ロールから取得することもできます。
Google Kubernetes Engine または Cloud Run にデプロイされたエージェントからメモリバンクにリクエストを送信する場合は、サービス アカウントに必要な権限があることを確認してください。Reasoning Engine Service Agent には、メモリバンクの読み取りと書き込みに必要な権限がすでに付与されているため、Agent Runtime からのアウトバウンド リクエストには、 メモリバンクにアクセスする権限がすでに付与されているはずです。
ライブラリをインストールする
このセクションでは、Python 開発環境を設定しているか、Python 開発環境(Colab など)を含むランタイムを使用していることを前提としています。
Agent Platform SDK をインストールします。
pip install google-cloud-aiplatform>=1.111.0認証
Agent Platform SDK クライアントを設定する
次のコードを実行して、Agent Platform SDK クライアントを設定します。
Agent Platform SDK
import vertexai
client = vertexai.Client(
project="PROJECT_ID",
location="LOCATION",
)
ここで
PROJECT_IDは、エージェントを 開発 して デプロイ する Google Cloud プロジェクト ID です。LOCATIONは、メモリバンクでサポートされているリージョンの一つです。
Agent Platform インスタンスを作成または更新する
Memory Bank を使用するには、まず Agent Platform インスタンスが必要です。インスタンスがまだない場合は、デフォルト構成を使用して作成できます。
agent_engine = client.agent_engines.create()
# Optionally, print out the Agent Platform resource name. You will need the
# resource name to interact with your Agent Platform instance later on.
print(agent_engine.api_resource.name)
新規または既存の メモリバンク インスタンスの動作の構成をカスタマイズする場合は、Agent Platform インスタンスをメモリバンク用に構成するをご覧ください。たとえば、メモリバンク が保持するのに意味があると考える情報を指定できます。
Agent Platform インスタンスは、 セッションと メモリバンクをすぐにサポートします。インスタンスの作成時にエージェントはデプロイされません。Agent Runtime を使用するには、Agent Platform インスタンスの 作成または更新時にデプロイする エージェントを指定する必要があります。
Agent Platform インスタンスを作成したら、インスタンスの名前を使用して記憶の読み取りまたは書き込みを行えます。次に例を示します。
# Generate memories using your Memory Bank instance.
client.agent_engines.memories.generate(
# `name` should have the format `projects/.../locations/.../reasoningEngines/...`.
name=agent_engine.api_resource.name,
...
)
Agent Runtime で使用する
Memory Bank は任意のランタイムで使用できますが、Agent Runtime と組み合わせて使用して、デプロイされたエージェントからメモリバンクを読み書きすることも可能です。
Agent Platform でメモリバンクを使用してエージェントをデプロイするには、 まず Agent Runtime の環境を設定します。次に、記憶統合機能を備えた Agent Runtime にデプロイするエージェントを準備します。デプロイされたエージェントは、必要に応じて記憶の読み取りと書き込みを行う必要があります。
AdkApp
Agent Platform Agent Development Kit
テンプレートを使用している場合、エージェントは
VertexAiMemoryBankServiceを Agent Platform にデプロイするときにデフォルトで使用します。つまり、ADK Memory ツールはメモリバンクから記憶を読み取ります。
from google.adk.agents import Agent
from vertexai.preview.reasoning_engines import AdkApp
# Develop an agent using the ADK template.
agent = Agent(...)
adk_app = AdkApp(
agent=adk_agent,
...
)
# Deploy the agent to Agent Runtime.
agent_engine = client.agent_engines.create(
agent_engine=adk_app,
config={
"staging_bucket": "STAGING_BUCKET",
"requirements": ["google-cloud-aiplatform[agent_engines,adk]"],
# Optional.
**context_spec
}
)
# Update an existing Agent Runtime to add or modify the Runtime.
agent_engine = client.agent_engines.update(
name=agent_engine.api_resource.name,
agent=adk_app,
config={
"staging_bucket": "STAGING_BUCKET",
"requirements": ["google-cloud-aiplatform[agent_engines,adk]"],
# Optional.
**context_spec
}
)
次のように置き換えます。
- STAGING_BUCKET: Agent Runtime のステージングに使用する Cloud Storage バケット。
ADK でのメモリバンクの使用に関する詳細は、 Agent Development Kit のクイックスタートをご覧ください。
カスタム エージェント
Memory Bank は、カスタム エージェントを Agent Runtime にデプロイして使用できます。この場合、エージェントはメモリバンクへの呼び出しをオーケストレートして、記憶 生成と 記憶取得 の呼び出しをトリガーする必要があります。
Agent Runtime にデプロイされたアプリケーションは、環境変数 GOOGLE_CLOUD_PROJECT、GOOGLE_CLOUD_LOCATION、GOOGLE_CLOUD_AGENT_ENGINE_ID を読み取って、環境から Agent Runtime の名前を推測できます。
project = os.environ.get("GOOGLE_CLOUD_PROJECT")
location = os.environ.get("GOOGLE_CLOUD_LOCATION")
agent_engine_id = os.environ.get("GOOGLE_CLOUD_AGENT_ENGINE_ID")
agent_engine_name = f"projects/{project}/locations/{location}/reasoningEngines/{agent_engine_id}"
Agent Runtime でエージェントのデフォルトのサービス エージェントを使用している場合、エージェントにはすでに記憶の読み取りと書き込みの権限が付与されています。カスタム サービスアカウント
を使用している場合は、サービス
アカウントに記憶の読み取りと書き込みの権限を付与する必要があります。必要な権限は、エージェントが実行できるオペレーションによって異なります。エージェントが記憶を取得して生成するだけでよい場合は、
aiplatform.memories.generate
と
aiplatform.memories.retrieve
で十分です。
他のすべてのランタイムで使用する
Cloud Run や Colab などの別の環境でメモリバンクを使用する場合は、エージェントを指定せずに Agent Runtime を作成します。構成を指定しない場合、メモリーの生成と取得を管理するためのデフォルト設定でメモリバンクが作成されます。
agent_engine = client.agent_engines.create()
Agent Platform を以前に使用したことがある場合、ランタイムなしで新しい Agent Platform インスタンスを作成するには数秒しかかかりません。Agent Platform を初めて使用する場合は、時間がかかることがあります(1 ~ 2 分)。
動作を構成する場合は、メモリバンク 構成を指定します。
作成
agent_engine = client.agent_engines.create(
config={
"context_spec": {
"memory_bank_config": ...
}
}
)
更新
Memory Bank の構成を変更する場合は、Agent Platform インスタンスを更新できます。
agent_engine = client.agent_engines.update(
# You can access the name using `agent_engine.api_resource.name` for an AgentEngine object.
name="AGENT_ENGINE_NAME",
config={
"context_spec": {
"memory_bank_config": ...
}
}
)
次のように置き換えます。
- RUNTIME_NAME: Agent Runtime の名前。
形式は
projects/.../locations/.../reasoningEngines/...にする必要があります。Memory Bank のサポートされている リージョンをご覧ください。
メモリバンクは、記憶の読み取りと書き込みの権限を持つ環境で使用できます。たとえば、Cloud Run でメモリバンクを使用するには、記憶の読み取りと書き込みを行う権限を Cloud Run サービス
ID に付与します。必要な権限は、エージェントが実行できるオペレーションによって異なります。エージェントが記憶を取得して生成するだけでよい場合は、
記憶、
aiplatform.memories.generate
と
aiplatform.memories.retrieve
で十分です。
メモリバンク 用に Agent Platform インスタンスを構成する
Memory Bank を構成して、記憶の生成と管理の方法をカスタマイズできます。構成を指定しない場合、メモリバンクは各構成タイプのデフォルト設定を使用します。
インスタンスに対して次のメモリバンク設定を構成できます。
- カスタマイズ構成: ソースデータから 記憶を抽出して、既存の 記憶と統合する方法を構成します。
- 類似性検索の構成: メモリバンクが類似性検索に使用するエンベディング モデルを指定します。デフォルトは
text-embedding-005です。 - 生成構成: メモリバンクがメモリーの生成に使用する LLM を構成します。デフォルトは
gemini-2.5-flashです。 - TTL の構成: 作成または更新された記憶の TTL を自動的に設定する方法を構成します 。デフォルトでは TTL は設定されません。
次のサンプルは、デフォルトのメモリバンクを示しています。
辞書
memory_bank_config = {
"generation_config": {
# `gemini-2.5-flash` will be used to extract and consolidate memories.
# Note: The global endpoint will be used for regions that don't have a
# regional endpoint available.
"model": "projects/{PROJECT}/locations/{LOCATION}/publishers/google/models/gemini-2.5-flash"
},
"similarity_search_config": {
# `text-embedding-005` will be used for similarity search, including
# during consolidation. Consolidation uses similarity search to find
# candidate memories that may be updated with new information.
"embedding_model": "projects/{PROJECT}/locations/{LOCATION}/publishers/google/models/text-embedding-005"
},
"ttl_config": {
# Default TTL for memory revisions is 365 days.
"memory_revision_default_ttl": f"{365 * 24 * 60 * 60}s"
},
"customization_configs": [
{
# Extract user information, preferences, key conversation details,
# and information that the user explicitly asked to be remembered.
"memory_topics": [
{"managed_memory_topic": "USER_PERSONAL_INFO"},
{"managed_memory_topic": "USER_PREFERENCES"},
{"managed_memory_topic": "KEY_CONVERSATION_DETAILS"},
{"managed_memory_topic": "EXPLICIT_INSTRUCTIONS"}
],
"consolidation_config": {
# Only use the latest memory revision of each candidate memory during
# consolidation.
"revisions_per_candidate_count": 1
},
# Only use the pre-defined set of examples.
"generate_memories_examples": [],
# Generate memories in the first person.
"enable_third_person_memories": False
}
],
# Memory revisions will be persisted. This can be overridden on a request-level.
"disable_memory_revisions": False
}
クラスベース
from vertexai.types import MemoryBankCustomizationConfig as CustomizationConfig
from vertexai.types import MemoryBankCustomizationConfigConsolidationConfig as ConsolidationConfig
from vertexai.types import MemoryBankCustomizationConfigMemoryTopic as MemoryTopic
from vertexai.types import MemoryBankCustomizationConfigMemoryTopicManagedMemoryTopic as ManagedMemoryTopic
from vertexai.types import ManagedTopicEnum
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfig as MemoryBankConfig
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigGenerationConfig as GenerationConfig
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigSimilaritySearchConfig as SimilaritySearchConfig
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigTtlConfig as TtlConfig
memory_bank_config = MemoryBankConfig(
generation_config=GenerationConfig(
# `gemini-2.5-flash` will be used to extract and consolidate memories.
# Note: The global endpoint will be used for regions that don't have a
# regional endpoint available.
model="projects/{PROJECT}/locations/{LOCATION}/publishers/google/models/gemini-2.5-flash"
),
similarity_search_config=SimilaritySearchConfig(
# `text-embedding-005` will be used for similarity search, including
# during consolidation. Consolidation uses similarity search to find
# candidate memories that may be updated with new information.
embedding_model="projects/{PROJECT}/locations/{LOCATION}/publishers/google/models/text-embedding-005"
),
ttl_config=TtlConfig(
# Default TTL for memory revisions is 365 days.
memory_revision_default_ttl=f"{365 * 24 * 60 * 60}s"
),
customization_configs=[
CustomizationConfig(
# Extract personal information, preferences, key conversation details,
# and information that the user explicitly asked to be remembered.
memory_topics=[
MemoryTopic(
managed_memory_topic=ManagedMemoryTopic(
managed_topic_enum=ManagedTopicEnum.USER_PERSONAL_INFO)),
MemoryTopic(
managed_memory_topic=ManagedMemoryTopic(
managed_topic_enum=ManagedTopicEnum.USER_PREFERENCES)),
MemoryTopic(
managed_memory_topic=ManagedMemoryTopic(
managed_topic_enum=ManagedTopicEnum.KEY_CONVERSATION_DETAILS)),
MemoryTopic(
managed_memory_topic=ManagedMemoryTopic(
managed_topic_enum=ManagedTopicEnum.EXPLICIT_INSTRUCTIONS))
],
# Only use the pre-defined set of examples.
generate_memories_examples=[],
consolidation_config=ConsolidationConfig(
# Only use the latest memory revision of each candidate memory during
# consolidation.
revisions_per_candidate_count=1
),
# Generate memories in the first person.
enable_third_person_memories=False,
)
],
# Memory revisions will be persisted. This can be overridden on a request-level.
disable_memory_revisions=False
)
Agent Platform インスタンスの作成時または更新時に、メモリバンクの構成を調整できます。次の例は、特定のメモリバンク構成でインスタンスを作成または更新する方法を示しています。
client.agent_engines.create(
...,
config={
"context_spec": {
"memory_bank_config": memory_bank_config
}
}
)
# Alternatively, update an existing Agent Platform instance's Memory Bank config.
agent_engine = client.agent_engines.update(
name=agent_engine.api_resource.name,
config={
"context_spec": {
"memory_bank_config": memory_bank_config
}
}
)
自然言語記憶のカスタマイズ構成
Memory Bank が自然言語の記憶を抽出する方法をカスタマイズするには、インスタンスの設定時に抽出動作を構成します。次のオプションを使用して動作をカスタマイズします。
- 記憶のトピックを構成する: メモリバンクが永続化するのに意味があると考える情報の種類を定義します。これらの記憶のトピックのいずれかに該当する情報のみがメモリバンクに保存されます。
- 少数ショットの例を提供する: メモリバンク に記憶抽出の想定される 動作を示します。
- 記憶の視点を構成する: 記憶を 一人称(デフォルト)で生成するか三人称で生成するかを構成します。
- 統合を構成する: メモリバンクが各記憶候補を統合する際に考慮する記憶リビジョンの数を構成します。
Memory Bank の抽出動作のカスタマイズは、2 つのステップ(伝えることと示すこと)で考えることができます。記憶のトピックは、メモリバンクに保持する情報を伝えます。 少数ショットは、メモリバンクに特定の記憶につながる情報の種類を示し、理解すべきパターン、ニュアンス、言い回しを学習させます。
必要に応じて、スコープレベルごとに異なる動作を構成できます。たとえば、セッション
レベルの記憶にとって意味のあるトピックが、ユーザーレベルの記憶(複数のセッションにわたる)にとって意味のあるトピックとは限りません。特定の記憶のサブセットの動作を構成するには、カスタマイズ構成のスコープキーを設定します。これらのスコープキーを含む GenerateMemories リクエストのみがその構成を使用します。scope_key フィールドを省略して、デフォルトの動作(スコープキーのすべてのセットに適用)を構成することもできます。この構成は、別のカスタマイズ構成のスコープキーと完全に一致する構成がないすべてのリクエストに適用されます。
たとえば、user_level_config は、スコープキー user_id(追加のキーがない scope={"user_id":
"123"})を正確に使用する GenerateMemories
リクエストにのみ適用されます。default_config は他のリクエストに適用されます。
辞書
user_level_config = {
"scope_keys": ["user_id"],
"memory_topics": [...],
"generate_memories_examples": [...]
}
default_config = {
"memory_topics": [...],
"generate_memories_examples": [...]
}
memory_bank_config = {
"customization_configs": [
user_level_config,
default_config
]
}
クラスベース
from vertexai.types import MemoryBankCustomizationConfig as CustomizationConfig
user_level_config = CustomizationConfig(
scope_keys=["user_id"],
memory_topics=[...],
generate_memories_examples=[...]
)
記憶のトピックの構成
「メモリトピック」は、メモリバンクが有意義と判断し、生成されたメモリとして保持すべきと判断した情報を特定します。Memory Bank は、次の 2 種類の記憶のトピックをサポートしています。
管理対象トピック: ラベルと手順はメモリバンクによって定義されます。指定する必要があるのは、マネージド トピックの名前だけです。次に例を示します。
辞書
memory_topic = { "managed_memory_topic": { "managed_topic_enum": "USER_PERSONAL_INFO" } }クラスベース
from vertexai.types import ManagedTopicEnum from vertexai.types import MemoryBankCustomizationConfigMemoryTopic as MemoryTopic from vertexai.types import MemoryBankCustomizationConfigMemoryTopicManagedMemoryTopic as ManagedMemoryTopic memory_topic = MemoryTopic( managed_memory_topic=ManagedMemoryTopic( managed_topic_enum=ManagedTopicEnum.USER_PERSONAL_INFO ) )Memory Bank では、次のマネージド トピックがサポートされています。
- ユーザー情報 (
USER_PERSONAL_INFO): 名前、関係、趣味、重要な日付など、ユーザーに関する重要な情報。たとえば、「私は Google で働いています」、「結婚記念日は 12 月 31 日です」などです。 - ユーザーの好み(
USER_PREFERENCES): 明示的または暗黙的な好み、嫌いなもの、好みのスタイル、パターン。たとえば、「真ん中の席がいいです」と入力します。 - 会話の重要なイベントとタスクの結果(
KEY_CONVERSATION_DETAILS): 会話内の重要なマイルストーンまたは結論。たとえば、「JFK と SFO 間の往復航空券を予約しました。2025 年 6 月 1 日に出発し、2025 年 6 月 7 日に帰ります。」 - 明示的な記憶 / 忘却の指示(
EXPLICIT_INSTRUCTIONS): エージェントに記憶または忘却を明示的に指示する情報。たとえば、ユーザーが「私は主に Python を使用していることを覚えておいて」と言うと、メモリバンクは「私は主に Python を使用している」という記憶を生成します。
- ユーザー情報 (
カスタム トピック: メモリバンク インスタンスの設定時に、ラベルと手順を定義します。これらは、Memory Bank の抽出ステップのプロンプトで使用されます。次に例を示します。
辞書
memory_topic = { "custom_memory_topic": { "label": "business_feedback", "description": """Specific user feedback about their experience at the coffee shop. This includes opinions on drinks, food, pastries, ambiance, staff friendliness, service speed, cleanliness, and any suggestions for improvement.""" } }クラスベース
from vertexai.types import MemoryBankCustomizationConfigMemoryTopic as MemoryTopic from vertexai.types import MemoryBankCustomizationConfigMemoryTopicCustomMemoryTopic as CustomMemoryTopic memory_topic = MemoryTopic( custom_memory_topic=CustomMemoryTopic( label="business_feedback", description="""Specific user feedback about their experience at the coffee shop. This includes opinions on drinks, food, pastries, ambiance, staff friendliness, service speed, cleanliness, and any suggestions for improvement.""" ) )カスタム トピックを使用する場合は、会話から記憶を抽出する方法を示す少量のサンプルも指定することをおすすめします。
カスタマイズでは、記憶のトピックを自由に組み合わせることが可能です。たとえば、使用可能な記憶のマネージド トピックのサブセットを使用できます。
辞書
customization_config = {
"memory_topics": [
{ "managed_memory_topic": { "managed_topic_enum": "USER_PERSONAL_INFO" } },
{ "managed_memory_topic": { "managed_topic_enum": "USER_PREFERENCES" } }
]
}
クラスベース
from vertexai.types import MemoryBankCustomizationConfig as CustomizationConfig
from vertexai.types import MemoryBankCustomizationConfigMemoryTopic as MemoryTopic
from vertexai.types import MemoryBankCustomizationConfigMemoryTopicManagedMemoryTopic as ManagedMemoryTopic
from vertexai.types import ManagedTopicEnum
customization_config = CustomizationConfig(
memory_topics=[
MemoryTopic(
managed_memory_topic=ManagedMemoryTopic(
managed_topic_enum=ManagedTopicEnum.USER_PERSONAL_INFO)
),
MemoryTopic(
managed_memory_topic=ManagedMemoryTopic(
managed_topic_enum=ManagedTopicEnum.USER_PREFERENCES)
),
]
)
マネージド トピックとカスタム トピックを組み合わせて使用することや、カスタム トピックのみを使用することが可能です。
辞書
customization_config = {
"memory_topics": [
{ "managed_memory_topic": { "managed_topic_enum": "USER_PERSONAL_INFO" } },
{
"custom_memory_topic": {
"label": "business_feedback",
"description": """Specific user feedback about their experience at
the coffee shop. This includes opinions on drinks, food, pastries, ambiance,
staff friendliness, service speed, cleanliness, and any suggestions for
improvement."""
}
}
]
}
クラスベース
from vertexai.types import MemoryBankCustomizationConfig as CustomizationConfig
from vertexai.types import MemoryBankCustomizationConfigMemoryTopic as MemoryTopic
from vertexai.types import MemoryBankCustomizationConfigMemoryTopicCustomMemoryTopic as CustomMemoryTopic
from vertexai.types import MemoryBankCustomizationConfigMemoryTopicManagedMemoryTopic as ManagedMemoryTopic
from vertexai.types import ManagedTopicEnum
customization_config = CustomizationConfig(
memory_topics=[
MemoryTopic(
managed_memory_topic=ManagedMemoryTopic(
managed_topic_enum=ManagedTopicEnum.USER_PERSONAL_INFO)
),
MemoryTopic(
custom_memory_topic=CustomMemoryTopic(
label="business_feedback",
description="""Specific user feedback about their experience at
the coffee shop. This includes opinions on drinks, food, pastries, ambiance,
staff friendliness, service speed, cleanliness, and any suggestions for
improvement."""
)
)
]
)
少数ショットの例
少数ショットの例を使用すると、Memory Bank に記憶抽出の想定される動作を示すことができます。たとえば、入力会話のサンプルと、その会話から抽出されることが想定される記憶を指定できます。
Memory Bank が意図した動作を学習できるように、カスタム トピックで常に少数ショットを使用することをおすすめします。マネージド トピックを使用する場合、メモリバンクが各トピックの例を定義するため、少数ショットは省略できます。空の generated_memories
リストを指定して、記憶が生成されない会話を示します。
たとえば、少数ショットの例を使用して、顧客メッセージからビジネスに関するフィードバックを抽出する方法を示すことができます。
辞書
example = {
"conversationSource": {
"events": [
{
"content": {
"role": "model",
"parts": [{ "text": "Welcome back to The Daily Grind! We'd love to hear your feedback on your visit." }] }
},
{
"content": {
"role": "user",
"parts": [{ "text": "Hey. The drip coffee was a bit lukewarm today, which was a bummer. Also, the music was way too loud, I could barely hear my friend." }] }
}
]
},
"generatedMemories": [
{
"fact": "The user reported that the drip coffee was lukewarm."
},
{
"fact": "The user felt the music in the shop was too loud."
}
]
}
クラスベース
from google.genai.types import Content, Part
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExample as GenerateMemoriesExample
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleConversationSource as ConversationSource
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleConversationSourceEvent as ConversationSourceEvent
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleGeneratedMemory as ExampleGeneratedMemory
example = GenerateMemoriesExample(
conversation_source=ConversationSource(
events=[
ConversationSourceEvent(
content=Content(
role="model",
parts=[Part(text="Welcome back to The Daily Grind! We'd love to hear your feedback on your visit.")]
)
),
ConversationSourceEvent(
content=Content(
role="user",
parts=[Part(text= "Hey. The drip coffee was a bit lukewarm today, which was a bummer. Also, the music was way too loud, I could barely hear my friend.")]
)
)
]
),
generated_memories=[
ExampleGeneratedMemory(
fact="The user reported that the drip coffee was lukewarm."
),
ExampleGeneratedMemory(
fact="The user felt the music in the shop was too loud."
)
]
)
想定される出力(generated_memories)に空のリストを指定して、記憶が生成されない会話の例を示すこともできます。
辞書
example = {
"conversationSource": {
"events": [
{
"content": {
"role": "model",
"parts": [{ "text": "Good morning! What can I get for you at The Daily Grind?" }] }
},
{
"content": {
"role": "user",
"parts": [{ "text": "Thanks for the coffee." }] }
}
]
},
"generatedMemories": []
}
クラスベース
from google.genai.types import Content, Part
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExample as GenerateMemoriesExample
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleConversationSource as ConversationSource
from vertexai.types import MemoryBankCustomizationConfigGenerateMemoriesExampleConversationSourceEvent as ConversationSourceEvent
example = GenerateMemoriesExample(
conversation_source=ConversationSource(
events=[
ConversationSourceEvent(
content=Content(
role="model",
parts=[Part(text="Welcome back to The Daily Grind! We'd love to hear your feedback on your visit.")]
)
),
ConversationSourceEvent(
content=Content(
role="user",
parts=[Part(text= "Thanks for the coffee!")]
)
)
]
),
generated_memories=[]
)
記憶の視点
デフォルトでは、記憶は一人称で生成されます(例: 「メモリバンクを使用して記憶を管理しています」)。enable_third_person_memories パラメータを使用して、メモリバンク が三人称で生成するように構成できます(例: 「ユーザーは メモリバンク を使用してメモリ管理をしています」)。
辞書
customization_config = {
"enable_third_person_memories": True
}
クラスベース
from vertexai.types import MemoryBankCustomizationConfig as CustomizationConfig
customization_config = CustomizationConfig(
enable_third_person_memories=True
)
統合のカスタマイズ
統合中、メモリバンクは新しく取得した情報を既存の記憶セットに統合する方法を決定します。メモリバンクは、新しい記憶を追加するか、追加のコンテキストで既存の記憶を更新するか、古い記憶を削除するかを評価します。
高品質で裏付けられた記憶を確保するために、メモリバンク は必要に応じて記憶の履歴を分析して、長期的な傾向と一時的な外れ値を区別できます。
デフォルトでは、メモリバンクは新しい情報を候補の記憶の最新のスナップショット("記憶リビジョン")と比較します。この分析の深さを増やすには、revisions_per_candidate_count パラメータを構成します。このパラメータは、統合中にメモリバンクが考慮する各「候補の記憶」(更新のために評価される特定のレコード)の以前のリビジョンの数を定義します。
辞書
customization_config = {
"consolidation_customization": {
"revisions_per_candidate_count": 10
}
}
クラスベース
from vertexai.types import MemoryBankCustomizationConfig as CustomizationConfig
from vertexai.types import MemoryBankCustomizationConfigConsolidationConfig as ConsolidationConfig
customization_config = CustomizationConfig(
consolidation_customization=ConsolidationConfig(
revisions_per_candidate_count=10
)
)
revisions_per_candidate_count
を増やすと、取り込まれた情報の繰り返しを考慮することで、より一貫性があり、裏付けられた記憶が得られます。ただし、カウントを増やすと、統合プロセス中のトークン消費量が増加します。
類似性検索の構成
類似性検索構成は、類似性検索用にインスタンスで使用されるエンベディング
モデルを制御します。類似性検索は、統合の候補となる記憶を特定するためと、類似性検索ベースの記憶取得のために使用されます。この構成が指定されていない場合、メモリバンク はデフォルトのモデルとして text-embedding-005 を使用します。
ユーザーの会話が英語以外の言語で行われることが想定される場合は、複数の言語をサポートする
モデルを使用して、gemini-embedding-001 や
text-multilingual-embedding-002 などの取得品質を向上させます。
辞書
memory_bank_config = {
"similarity_search_config": {
"embedding_model": "EMBEDDING_MODEL",
}
}
クラスベース
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfig as MemoryBankConfig
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigSimilaritySearchConfig as SimilaritySearchConfig
memory_bank_config = MemoryBankConfig(
similarity_search_config=SimilaritySearchConfig(
embedding_model="EMBEDDING_MODEL"
)
)
次のように置き換えます。
- EMBEDDING_MODEL:類似性検索に使用する Google テキスト エンベディング モデル。形式は
projects/{project}/locations/{location}/publishers/google/models/{model}です。
生成構成
生成構成は、記憶の生成 に使用される LLM を制御します。これには、記憶の抽出や、新しい記憶と既存の記憶の統合が含まれます。
メモリバンク はデフォルトのモデルとして gemini-2.5-flash を使用します。リージョン Gemini
が利用できないリージョンでは
、グローバル エンドポイントが使用されます。
辞書
memory_bank_config = {
"generation_config": {
"model": "LLM_MODEL",
}
}
クラスベース
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfig as MemoryBankConfig
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigGenerationConfig as GenerationConfig
memory_bank_config = MemoryBankConfig(
generation_config=GenerationConfig(
model="LLM_MODEL"
)
)
次のように置き換えます。
- LLM_MODEL: 記憶の抽出と
統合に使用する Google LLM モデル(
projects/{project}/locations/{location}/publishers/google/models/{model}形式)。
有効期間(TTL)の構成
TTL 構成は、メモリバンクが記憶の有効期限を動的に設定する方法を制御します。有効期限が切れると、記憶は取得できなくなり、削除されます。
構成が指定されていない場合、作成または更新された記憶の有効期限は動的に設定されないため、有効期限が手動で設定されていない限り、記憶は期限切れになりません。
TTL 構成には次の 2 つのオプションがあります。
デフォルト TTL: TTL は、記憶を作成または 更新するすべてのオペレーションに適用されます。これには、
UpdateMemory、CreateMemory、およびGenerateMemoriesが含まれます。辞書
memory_bank_config = { "ttl_config": { "default_ttl": f"TTLs" } }クラスベース
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfig as MemoryBankConfig from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigTtlConfig as TtlConfig memory_bank_config = MemoryBankConfig( ttl_config=TtlConfig( default_ttl=f"TTLs" ) )次のように置き換えます。
- TTL: TTL の期間(秒単位)。更新された記憶の場合、新たに計算された有効期限(現在 + TTL)によって、記憶の以前の有効期限が上書きされます。
詳細な(オペレーション単位の)TTL: TTL は、どのオペレーションがメモリーを作成または更新したかに基づいて計算されます。特定のオペレーションに設定されていない場合、オペレーションは記憶の有効期限を更新しません。
辞書
memory_bank_config = { "ttl_config": { "granular_ttl": { "create_ttl": f"CREATE_TTLs", "generate_created_ttl": f"GENERATE_CREATED_TTLs", "generate_updated_ttl": f"GENERATE_UPDATED_TTLs" } } }クラスベース
from vertexai.types import ReasoningEngineContextSpecMemoryBankConfig as MemoryBankConfig from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigTtlConfig as TtlConfig from vertexai.types import ReasoningEngineContextSpecMemoryBankConfigTtlConfigGranularTtlConfig as GranularTtlConfig memory_bank_config = MemoryBankConfig( ttl_config=TtlConfig( granular_ttl_config=GranularTtlConfig( create_ttl=f"CREATE_TTLs", generate_created_ttl=f"GENERATE_CREATED_TTLs", generate_updated_ttl=f"GENERATE_UPDATED_TTLs", ) ) )次のように置き換えます。
- CREATE_TTL:
CreateMemoryを使用して作成された記憶の TTL の秒単位の期間。 - GENERATE_CREATED_TTL:
GenerateMemoriesを使用して作成された記憶の TTL の秒単位の期間。 - GENERATE_UPDATED_TTL:
GenerateMemoriesを使用して更新された記憶の TTL の秒単位の期間。新たに計算された有効期限(現在 + TTL)は、記憶の以前の有効期限を上書きします。
- CREATE_TTL: