メモリバンクは、メモリ リビジョン リソースを使用して、メモリの変更履歴を自動的に保持します。メモリが作成または変更されるたびに、新しい不変のリビジョンが保存されるため、情報の進化の過程と各ステップで抽出された内容を把握できます。
このドキュメントでは、メモリとそのリビジョンのライフサイクルについて説明し、リビジョンの一覧表示、取得、ロールバックなどのオペレーションについて説明します。
メモリの生成の詳細については、 メモリを生成するをご覧ください。
メモリとそのリビジョンのライフサイクル

メモリは、直接(CreateMemory、UpdateMemory、DeleteMemory を使用)または動的に(GenerateMemories を使用)作成、更新、削除できます。メモリ リビジョン リソースは、すべてのミューテーション オペレーションにわたるメモリ リソースの完全なバージョン履歴を提供します。メモリが作成または変更されるたびに、新しい不変のリビジョンが自動的に保存されます。これにより、メモリーがどのように進化してきたか、また(メモリーの生成の場合)各ステップでどのような特定の情報が抽出され、統合されたかを把握できます。
すべてのメモリ リソースには、1 つ以上の子メモリ リビジョン リソースが関連付けられています。
Memoryリソースは常に、情報の現在の統合された状態を反映します。1 つのメモリで、複数のリクエストとデータソースから派生したデータを反映できます。Memory( create_time=datetime.datetime(...), fact='This is my current memory content after consolidation', name='projects/.../locations/.../reasoningEngines/../memories/...', scope={ 'my_scope_key': 'my_scope_value' }, topics=[ MemoryTopicId( managed_memory_topic=<ManagedTopicEnum.USER_PERSONAL_INFO: 'USER_PERSONAL_INFO'> ), ], update_time=datetime.datetime(...) )MemoryRevisionsリソースは、親メモリの履歴状態を表します。各リビジョンは、ミューテーション イベント時のメモリのスナップショットです。GenerateMemoriesを使用してメモリが変更された場合、リビジョンには、メモリの既存のコンテンツと統合される前にデータソースから抽出された情報(extracted_memories)も含まれます。MemoryRevision( create_time=datetime.datetime(...), expire_time=datetime.datetime(...), extracted_memories=[ IntermediateExtractedMemory( fact='This information was extracted from my data source' ), ], fact='This is my current memory content after consolidation', name='projects/.../locations/.../reasoningEngines/.../memories/.../revisions/...' )メモリ リビジョンはデフォルトで有効になっています。メモリ リビジョンを無効にするには、 メモリ リビジョンを無効にするをご覧ください。
メモリの作成
メモリは、CreateMemory を使用して直接作成することも、GenerateMemories を使用して動的に作成することもできます。メモリーの生成では、同じスコープの同様の情報をカバーする既存のメモリーがない場合に、メモリーが作成されます。
# Direct creation using CreateMemory
client.agent_engines.memories.create(name=memory_bank_name, ...)
# Dynamic creation using GenerateMemory
client.agent_engines.memories.generate_memories(name=memory_bank_name, ...)
メモリが作成されると、1 つの Memory リソースと子
MemoryRevision が作成されます。
client.agent_engines.memories.get(name=memory_name)
"""
Memory(
name="projects/123/locations/us-central1/reasoningEngines/456/memories/789",
fact="This is my original fact.",
...
)
"""
list(client.agent_engines.memories.revisions.list(name=memory_name))
"""
[
MemoryRevision(
name="projects/123/locations/us-central1/reasoningEngines/456/memories/789/revision/123",
fact="This is my original fact",
...
)
]
"""
メモリの更新
メモリは、UpdateMemory を使用して直接更新することも、GenerateMemories を使用して動的に更新することもできます。メモリーの生成では、統合プロセスで、新しい情報が同じスコープの既存のすべてのメモリーと重複している、補完的である、または矛盾していると判断された場合に、メモリーが動的に
更新されます。
# Direct update using UpdateMemory
client.agent_engines.memories.update(name=memory_name, ...)
# Dynamic update using GenerateMemories
client.agent_engines.memories.generate_memories(name=memory_bank_name, ...)
メモリが更新されると、既存の Memory リソースが更新され、新しい
子 MemoryRevision が作成されます。
client.agent_engines.memories.get(name=memory_name)
"""
Memory(
name="projects/123/locations/us-central1/reasoningEngines/456/memories/789",
fact="This is my updated fact.",
...
)
"""
list(client.agent_engines.memories.revisions.list(name=memory_name))
"""
[
MemoryRevision(
name="projects/123/locations/us-central1/reasoningEngines/456/memories/789/revision/456",
fact="This is my updated fact",
...
),
MemoryRevision(
name="projects/123/locations/us-central1/reasoningEngines/456/memories/789/revision/123",
fact="This is my original fact",
...
)
]
"""
メモリの削除
メモリは、DeleteMemory を使用して直接削除することも、GenerateMemories を使用して動的に削除することもできます。メモリーの生成では、統合プロセスで、新しい情報が同じスコープの既存の情報を無効にすると判断された場合に、メモリーが動的に削除されます。
# Direct deletion using UpdateMemory
client.agent_engines.memories.delete(name=memory_name, ...)
# Dynamic delete using GenerateMemories
client.agent_engines.memories.generate_memories(name=memory_bank_name, ...)
メモリが削除されると、既存の Memory リソースが削除され、新しい
子 MemoryRevision が作成されます。最新のメモリ リビジョンの fact は、削除ミューテーションを反映しているため空です。
client.agent_engines.memories.get(name=memory_name)
"""
404 Not Found.
"""
list(client.agent_engines.memories.revisions.list(name=memory_name))
"""
[
MemoryRevision(
name="projects/123/locations/us-central1/reasoningEngines/456/memories/789/revision/789",
fact="",
...
),
MemoryRevision(
name="projects/123/locations/us-central1/reasoningEngines/456/memories/789/revision/456",
fact="This is my updated fact",
...
),
MemoryRevision(
name="projects/123/locations/us-central1/reasoningEngines/456/memories/789/revision/123",
fact="This is my original fact",
...
)
]
"""
子メモリ リビジョンには、親メモリの削除後 48 時間までしかアクセスできません。この復旧期間中は、メモリ リビジョンを引き続き 検査できます。また、以前のリビジョンにロールバックすることでメモリを復元できます。
メモリ リビジョンのオペレーション
このセクションでは、メモリ リビジョンを検査し、メモリを以前のリビジョンにロールバックする方法について説明します。
リビジョン リストを取得
ListMemoryRevisions を使用して、メモリに属するすべてのメモリ リビジョンを返します。
list(client.agent_engines.memories.revisions.list(name=MEMORY_NAME))
次のように置き換えます。
MEMORY_NAME: メモリのリソース名。形式はprojects/.../locations/.../reasoningEngines/.../memories/...です。
メモリを生成するときに、関連するリビジョンに適用されるリビジョン ラベルを指定できます。ラベルは任意の Key-Value ペアです。たとえば、メモリの生成に使用されたデータソースの ID でリビジョンにラベルを付け、このラベルでリビジョンをフィルタできます。
response = client.agent_engines.memories.generate(
...,
config={
"revision_labels": {
"data_source": "321"
}
}
)
list(client.agent_engines.memories.revisions.list(
name=MEMORY_NAME,
config={
"filter": "labels.data_source=\"321\""
}
))
"""
[
MemoryRevision(
name="projects/123/locations/us-central1/reasoningEngines/456/memories/789/revision/123",
labels={
"data_source": "123"
}
...
)
]
"""
リビジョンを取得する
GetMemoryRevision を使用して、個々のメモリ リビジョンを取得します。
client.agent_engines.memories.revisions.get(name=MEMORY_REVISION_NAME)
次のように置き換えます。
MEMORY_REVISION_NAME: 取得するメモリ リビジョンのリソース名。形式はprojects/.../locations/.../reasoningEngines/.../memories/.../revisions/...です。
メモリをロールバックする
RollbackMemory を使用して、メモリを以前のリビジョンにロールバックします。
client.agent_engines.memories.rollback(
name=name=MEMORY_NAME,
target_revision_id=REVISION_ID
)
次のように置き換えます。
MEMORY_NAME: 更新するメモリのリソース名。形式はprojects/.../locations/.../reasoningEngines/.../memories/...です。REVISION_ID: ロールバックするリビジョンの ID。これは、メモリ リビジョン リソース 名の最後のセグメントです(projects/MyProject/locations/us-central1/reasoningEngines/123/memories/456/revisions/789の789など)。
GenerateMemories によって行われたメモリの変更を元に戻す場合は、変更前のリビジョンにメモリをロールバックします。メモリーの生成レスポンスには、更新または削除されたメモリーごとに、以前のリビジョンへの参照(previous_revision)が含まれます。
operation = client.agent_engines.memories.generate(
...
)
# Rollback the first generated memory to the previous revision.
client.agent_engines.memories.rollback(
name=operation.response.generated_memories[0].memory.name,
target_revision_id=operation.response.generated_memories[0].previous_revision
)
メモリ リビジョンを無効にする
メモリ リビジョンはデフォルトで有効になっています。メモリ リビジョンは、Memory Bank インスタンスへのすべてのリクエストに対して、または個々のリクエストに対して無効にできます。メモリ リビジョンが無効になっている場合、メモリが変更されてもメモリ リビジョンは作成されません。
インスタンスの設定時に、Memory Bank インスタンスへのすべてのリクエストに対してメモリ リビジョンを無効にできます。
memory_bank = client.agent_engines.create(
config={
"context_spec": {
"memory_bank_config": {
"disable_memory_revisions": True
}
}
}
)
リクエストの送信時に、リクエスト レベルでメモリ リビジョンを無効にできます。
生成
client.agent_engines.memories.generate(
...,
"config": {
"disable_memory_revisions": True
}
)
作成
client.agent_engines.memories.create(
...,
"config": {
"disable_memory_revisions": True
}
)
更新
client.agent_engines.memories.update(
...,
"config": {
"disable_memory_revisions": True
}
)
リビジョンの有効期限
メモリ リビジョンは永続的に保持されません。リビジョンの有効期限を設定するか、デフォルトの有効期限を使用する必要があります。デフォルトの有効期間(TTL)は 365 日です。有効期限は、Memory Bank インスタンスへのすべてのリクエストに対して、または個々のリクエストに対して構成できます。メモリ リビジョンの有効期限が切れると、検査やロールバックに使用できなくなります。
インスタンスの設定時に、メモリバンク インスタンスへのすべてのリクエストに対して TTL を構成できます。
client.agent_engines.create(
config={
"context_spec": {
"memory_bank_config": {
"ttl_config": {
# Persist memory revisions for 30 days after they're created.
"revision_ttl": f"{30 * 60 * 60 * 24}s"
}
}
}
}
)
リクエスト レベルで各メモリ リビジョンの TTL を構成するには、リクエストに revision_expire_time または revision_ttl を含めます。
TTL
config = {
# Persist memory revisions for 30 days after they're created.
"revision_ttl": f"{30 * 60 * 60 * 24}s"
}
client.agent_engines.memories.create(
...,
config=config
)
client.agent_engines.memories.update(
...,
config=config
)
client.agent_engines.memories.generate(
...,
config=config
)
有効期限
import datetime
config = {
"revision_expire_time": datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(weeks=3)
}
client.agent_engines.memories.create(
...,
config=config
)
client.agent_engines.memories.update(
...,
config=config
)
client.agent_engines.memories.generate(
...,
config=config
)