エージェント・メモリーの開始

この記事では、エージェント・メモリーのインストールと、ユーザー・コンテキストの格納および取得などの基本的なメモリー操作の実行について説明します。

前提条件

次のものがあることを確認します。

SDKのインストール

エージェント・メモリーをインストールするには、次を実行します。

pip install "oracleagentmemory==26.4.0"

pipを使用してインストールすると、サポートされているプラットフォームで事前構築済のバイナリ・ホイールがプルされます。

メモリー・インスタンスの初期化

埋込み、LLMおよびデータベース接続を構成して、OracleAgentMemoryインスタンスを作成します。

from oracleagentmemory.core.oracleagentmemory import OracleAgentMemory
from oracleagentmemory.apis.searchscope import SearchScope
from oracleagentmemory.core.embedders.embedder import Embedder
from oracleagentmemory.core.llms.llm import Llm

embedder = Embedder(model="YOUR_EMBEDDING_MODEL")
llm = Llm(model="YOUR_LLM")
db_pool = ...  #an oracledb connection or connection pool
memory = OracleAgentMemory(connection=db_pool, embedder=embedder, llm=llm)

メモリー・エントリの格納

スレッドを作成し、メッセージを追加し、ユーザーのメモリー・エントリを格納することから始めます。

messages = [
    {
        "role": "user",
        "content": (
            "Orange juice has become my favorite breakfast drink lately, "
            "what can I pair it with?"
        ),
    },
    {
        "role": "assistant",
        "content": (
            "Nice! Orange juice goes great with something savory. "
            "Try eggs and toast, avocado toast, or a breakfast sandwich."
        ),
    },
]

thread = memory.create_thread(user_id="user_123")
#add_messages will add messages to the DB and extract memories automatically
thread.add_messages(messages)
#add_memory adds memory to the DB
thread.add_memory("The user likes orange juice with breakfast.")

メモリー・エントリの取得

ユーザー・スコープ問合せを使用してメモリーを検索します。

results = memory.search(query="orange juice", scope=SearchScope(user_id="user_123"))
for result in results:
    print(f"- [{result.record.record_type}] {result.content}")

出力:

-[memory] The user likes orange juice with breakfast.
-[message] Orange juice has become my favorite breakfast drink lately, what can I pair it with?
-[message] Nice! Orange juice goes great with something savory. 
        Try eggs and toast,avocado toast, or a breakfast sandwich.

ノート:示されている出力は図です。将来のバージョンでは、追加の結果タイプ、フィールド、または順序付けが返される場合があります。

モデル互換性

2026年4月時点で、次の大規模言語モデル(LLM)および埋込みモデルはoracleagentmemoryと互換性があります。

LLM

次の大規模言語モデル(LLM)が互換性があることが確認されました。

vllm

oci

ジェミニ

人類

オープンアイ

埋込み

次の埋込みモデルが互換性があることが確認されました。

host_vllm

oci

ジェミニ

オープンアイ