自動メモリー抽出のカスタマイズ
自動メモリー抽出では、追加の構成なしで有用な詳細を取得できます。カスタム指示により、アプリケーションは、特定のユース・ケースに対してデフォルトの動作を調整する必要がある場合に、抽出プロセスにガイダンスを追加できます。
この記事では、Oracle AI Agent Memoryの自動メモリー抽出をカスタム手順でガイドする方法について説明します。
カスタム手順では、アプリケーション固有のメモリー抽出に関する追加のガイダンスを提供します。これらは、ドメイン・ナレッジ、製品ポリシーまたは会話固有の優先度を反映するためにアプリケーションの抽出が必要な場合に役立ちます。
ノート:メモリー抽出がアプリケーション固有のガイダンスに従う必要がある場合は、カスタム手順を使用してください。追加のガイダンスが不要な場合は、デフォルトの抽出が適切です。
ヒント: oracleagentmemoryをインストールする方法は、エージェント・メモリーの開始を参照してください。この例にローカルOracleデータベースが必要な場合は、「Oracle AI Databaseのローカル実行」に従います。
クライアントレベルの抽出手順の構成
Oracle DB接続またはプール、埋込み、LLMおよびサポートに焦点を当てた抽出手順を使用して、Oracle Agent Memoryコンポーネントを作成します。これらの命令は、スレッドが独自の抽出命令を提供しないかぎり、このクライアントを介して作成またはロードされたスレッドに適用されます。
import oracledb
from oracleagentmemory.core import MemoryExtractionConfig
from oracleagentmemory.core.embedders.embedder import Embedder
from oracleagentmemory.core.llms.llm import Llm
from oracleagentmemory.core.oracleagentmemory import OracleAgentMemory
embedder = Embedder(model="YOUR_EMBEDDING_MODEL")
memory_llm = Llm(model="YOUR_MEMORY_LLM")
db_pool = oracledb.SessionPool(
user="YOUR DB USER",
password="YOUR DB PASSWORD",
dsn="YOUR DB CONNECT STRING",
)
support_extraction_instructions = """
Only extract customer support facts:
- order ids
- return requests
- delivery problems
Ignore greetings, small talk, and one-off troubleshooting text.
""".strip()
memory = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
llm=memory_llm,
memory_extraction_config=MemoryExtractionConfig(
memory_extraction_custom_instructions=support_extraction_instructions
),
)
| APIリファレンス: OracleAgentMemory | OracleThread |
スレッド・メッセージからのサポート・メモリーの抽出
サポート・スレッドを作成し、ユーザーおよびアシスタントのメッセージを追加します。この例では、memory_extraction_config=MemoryExtractionConfig(memory_extraction_frequency=1)を設定して、add_messages()が挿入されたターンに対して自動抽出を即時に実行します。カスタム命令により、抽出されたメモリーは注文ID、返品要求および配送の問題に集中します。
support_thread = memory.create_thread(
thread_id="support_ticket_7421",
user_id="customer_123",
memory_extraction_config=MemoryExtractionConfig(memory_extraction_frequency=1),
)
#add_messages persists the turn and runs automated memory extraction because
#MemoryExtractionConfig(memory_extraction_frequency=1) is set for this thread.
support_thread.add_messages(
[
{
"role": "user",
"content": (
"Hi, order 7421 arrived damaged. I need a return request "
"and a replacement delivery."
),
},
{
"role": "assistant",
"content": "I can help start the return request for order 7421.",
},
]
)
results = support_thread.search(
"return request order 7421",
max_results=5,
record_types=["fact"],
)
for result in results:
print(f"- [{result.record.record_type}] {result.content}")
出力:
- [fact] Customer reported damaged order 7421 and requested a return and replacement delivery.
上の出力は例示です。正確なメモリー・テキストは、構成された抽出LLMに依存しますが、抽出されたメモリーはクライアントに提供されるカスタム指示に従う必要があります。
この違いは、エクストラクタが保持するように求められるメモリーの種類を比較することによって最も簡単に確認できます。
カスタム指示あり
抽出器は耐久の顧客サポートの事実を保ち、挨拶および会話の表現を無視します。
- [fact] Customer reported damaged order 7421 and requested a return and replacement delivery.
カスタム指示なし
デフォルトの抽出プロンプトは操作をサポートするようにスコープ指定されていないため、エクストラクタはより広範な会話メモリーを保持できます。
- [memory] The user contacted support about order 7421 and discussed a damaged delivery.
| APIリファレンス: OracleThread | OracleSearch結果 |
1つのスレッドのオーバーライド指示
1つのスレッドでクライアントのデフォルトより狭い抽出ポリシーが必要な場合は、memory_extraction_config=MemoryExtractionConfig(memory_extraction_custom_instructions=...)をcreate_thread()に渡します。スレッド・レベルの値は、そのスレッドに対して優先され、スレッド構成によって維持されます。
billing_thread = memory.create_thread(
thread_id="billing_ticket_9310",
user_id="customer_123",
memory_extraction_config=MemoryExtractionConfig(
memory_extraction_frequency=1,
memory_extraction_custom_instructions=(
"Only extract billing facts, invoice identifiers, and payment issues."
),
),
)
billing_thread.add_messages(
[
{
"role": "user",
"content": "Invoice INV-9310 was paid twice and needs a refund.",
}
]
)
| APIリファレンス: OracleAgentMemory | OracleThread |
スレッド指示の更新またはクリア
update_thread()を使用して、既存のスレッドの永続抽出命令を変更します。Noneを渡してスレッド・レベルの命令をクリアし、将来のスレッド・ハンドルがクライアント・レベルの命令を使用するか、何も構成されていない場合はSDKの通常の抽出動作を使用するようにします。
memory.update_thread(
"support_ticket_7421",
memory_extraction_config=MemoryExtractionConfig(
memory_extraction_custom_instructions=(
"Only extract product defects and replacement requests."
)
),
)
memory.update_thread(
"support_ticket_7421",
memory_extraction_config=MemoryExtractionConfig(
memory_extraction_custom_instructions=None
),
)
ノート: get_thread(..., memory_extraction_config=MemoryExtractionConfig(memory_extraction_custom_instructions=...))では、永続スレッド構成を更新せずに、戻されたライブ・スレッド・ハンドルに指示を適用できます。
| APIリファレンス: OracleAgentMemory | OracleThread |
まとめ
このガイドでは、クライアント・レベルのカスタム抽出命令の構成方法、特定のスレッドのカスタム抽出命令のオーバーライド方法、およびスレッド・レベルの抽出命令の更新またはクリア方法を学習しました。
自動抽出をカスタマイズする方法を学習した後、「エージェント・メモリーのLangGraphでの短期APIの使用」に進むことができます。
完全コード
#Copyright © 2026 Oracle and/or its affiliates.
#This software is under the Apache License 2.0
#(LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) or Universal Permissive License
#(UPL) 1.0 (LICENSE-UPL or https://oss.oracle.com/licenses/upl), at your option.
#Oracle Agent Memory Code Example - Customize Automatic Memory Extraction
#------------------------------------------------------------------------
##Configure custom memory extraction instructions
import oracledb
from oracleagentmemory.core import MemoryExtractionConfig
from oracleagentmemory.core.embedders.embedder import Embedder
from oracleagentmemory.core.llms.llm import Llm
from oracleagentmemory.core.oracleagentmemory import OracleAgentMemory
embedder = Embedder(model="YOUR_EMBEDDING_MODEL")
memory_llm = Llm(model="YOUR_MEMORY_LLM")
db_pool = oracledb.SessionPool(
user="YOUR DB USER",
password="YOUR DB PASSWORD",
dsn="YOUR DB CONNECT STRING",
)
support_extraction_instructions = """
Only extract customer support facts:
- order ids
- return requests
- delivery problems
Ignore greetings, small talk, and one-off troubleshooting text.
""".strip()
memory = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
llm=memory_llm,
memory_extraction_config=MemoryExtractionConfig(
memory_extraction_custom_instructions=support_extraction_instructions
),
)
##Extract support memories from thread messages
support_thread = memory.create_thread(
thread_id="support_ticket_7421",
user_id="customer_123",
memory_extraction_config=MemoryExtractionConfig(memory_extraction_frequency=1),
)
#add_messages persists the turn and runs automated memory extraction because
#MemoryExtractionConfig(memory_extraction_frequency=1) is set for this thread.
support_thread.add_messages(
[
{
"role": "user",
"content": (
"Hi, order 7421 arrived damaged. I need a return request "
"and a replacement delivery."
),
},
{
"role": "assistant",
"content": "I can help start the return request for order 7421.",
},
]
)
results = support_thread.search(
"return request order 7421",
max_results=5,
record_types=["fact"],
)
for result in results:
print(f"- [{result.record.record_type}] {result.content}")
#- [fact] Customer reported damaged order 7421 and requested a return and replacement delivery.
##Override custom instructions for one thread
billing_thread = memory.create_thread(
thread_id="billing_ticket_9310",
user_id="customer_123",
memory_extraction_config=MemoryExtractionConfig(
memory_extraction_frequency=1,
memory_extraction_custom_instructions=(
"Only extract billing facts, invoice identifiers, and payment issues."
),
),
)
billing_thread.add_messages(
[
{
"role": "user",
"content": "Invoice INV-9310 was paid twice and needs a refund.",
}
]
)
##Update or clear thread custom instructions
memory.update_thread(
"support_ticket_7421",
memory_extraction_config=MemoryExtractionConfig(
memory_extraction_custom_instructions=(
"Only extract product defects and replacement requests."
)
),
)
memory.update_thread(
"support_ticket_7421",
memory_extraction_config=MemoryExtractionConfig(
memory_extraction_custom_instructions=None
),
)