Skip to content

エージェントメモリーサービス

プレミアム機能

DataRobot's Agentic AI capabilities are a premium feature; contact your DataRobot representative for enablement information. DataRobotの試用版では、この機能を制限付きでお試しいただけます。

DataRobotのエージェントメモリーサービスでは、異なるユースケースに対応する2つの異なるAPIが提供されています。 お使いのビルドに合った方法を選択し、その方法に関するドキュメントに従ってください。 1つのアプリケーションで2つをマージする必要はありません。

DataRobotモデル(datarobot.models.memory.Sessionまたはdatarobot.models.memory.MemorySpace経由でアクセス)を使用して、DataRobotのREST APIおよびPython APIクライアントを通じてチャットスタイルの履歴(セッション)を保持および取得する必要がある場合は、チャット履歴APIセクションに説明があるチャット履歴APIを利用します。 詳細については、REST APIおよびPython APIクライアントのリファレンスドキュメントを参照してください。

長期的なmem0スタイルのメモリー(オープンソースのmem0スタックからの移行を含む)を使用している場合、またはmem0製品に準拠した例やリクエスト形式が必要な場合は、mem0 APIを利用します。 このインターフェイスの場合、標準のリソースはmem0ドキュメントです。

チャット履歴APIは、DataRobotに統合されたパスです。これは、他のDataRobotリソースに使用するのと同じREST APIであり、DataRobot Python APIクライアントでも同様の機能が提供されています。

Python APIクライアント:Python APIクライアントには、構築を容易にするために専用の型が追加されています。

  • datarobot.models.memory.MemorySpaceは、メモリースペース(保存された会話データのコンテナ)に基本的なCRUDを提供します。
  • datarobot.models.memory.Sessiondatarobot.models.memory.Eventは、チャットスタイルのエージェントアプリケーションを構築する際、セッションイベント(セッション内のメッセージ)を使用します。

REST API:これらのリソースにはREST APIを使用します。認証およびベースURLのパターンは、DataRobot APIの他の部分と同様です。 詳細については、関連する操作とスキーマのREST APIリファレンスを参照してください。

DataRobotのチャット履歴およびセッションモデルを、プラットフォームのAPIやPythonパッケージと連携させたい場合は、この方法を選択します。

DataRobotには、オープンソースのmem0製品のインターフェイスと1対1で対応することを目的とした、mem0互換のREST APIも用意されています。

概念の概要、エンドポイントの動作、特に例(言語およびフレームワーク固有のスニペットを含む)については、その製品用に管理されている公式のmem0ドキュメントを参照してください。

https://docs.mem0.aiからmem0の主要なドキュメントにアクセスし、リクエストとレスポンスの形式、メモリーの追加や検索の方法、一般的なエージェントフレームワークとの連携方法について確認してください。 DataRobotサービスは同じAPIサーフェスと互換性があるように構築されているため、これらのガイドはDataRobotのエンドポイントと認証に適用されます。 mem0のセマンティクスやエコシステムをターゲットとする場合、またはオープンソースサービスに対して作成された統合を移植する場合は、この方法を選択してください。

クイックスタート

以下のクイックスタートワークフローを確認します。

前提条件

  • Python 3.9以降
  • DataRobotアカウント、APIキー、エンドポイントURL(例:https://app.datarobot.com/api/v2
  • pip install "datarobot>=3.17" "mem0ai>=2.0"

環境変数(DATAROBOT_API_TOKENDATAROBOT_ENDPOINT)または~/.config/datarobot/drconfig.yamlを使用して、資格情報を一度設定します。 以下のスニペットは、それらを明示的に渡します。

接続する

import datarobot as dr

dr.Client(token="<YOUR_DATAROBOT_API_TOKEN>", endpoint="https://app.datarobot.com/api/v2") 

メモリー空間の作成

メモリー空間とは、1つのアプリケーションまたは1人のエンドユーザーに対する分離境界のことです。

from datarobot.models.memory import MemorySpace

space = MemorySpace.create(
    description="Acme support assistant",
    llm_model_name="vertex_ai/claude-sonnet-4-6",  # used for mem0 fact extraction
)
print(space.id) 

llm_model_nameは、mem0の事実抽出に使用されるLLMを選択します。 DataRobot LLM Gatewayを通じて利用可能なモデルに対して検証が行われます。不明な名前は拒否され、許可されたモデルを一覧表示する422レスポンスが返されます。 プロバイダーごとに提供されているモデルについては、利用可能なLLMを参照してください。 推論モデルは、事実抽出において処理速度が著しく遅くなるだけでなく、結果の品質も向上しないため、推論機能のないモデルの使用をお勧めします。 あるいは、llm_base_urlを設定することで、メモリー空間をLLM Gatewayではなく、OpenAI互換のカスタムエンドポイントに向けることができます。そのホストは、管理者が設定した許可リストと一致している必要があります。

セッションの作成

セッションは1つの会話です。 participantsはMongoDB-ObjectId文字列のリストで、通常はエンドユーザーです。

from datarobot.models.memory import Session

session = Session.create(
    memory_space_id=space.id,
    participants=["67500a000000000000000001"],
    description="Triage chat #42",
)
print(session.id) 

ソフト削除ライフサイクル戦略を指定しない場合、サーバーはデフォルトの戦略(180日間)を割り当てます。

メッセージの投稿

各メッセージはイベントです。 bodyは自由形式のJSONです。emitterは送信者を識別します。

event = session.post_event(
    body={"content": "Hello, my deployment is failing"},
    emitter={"type": "user", "id": "67500a000000000000000001"},
    event_type="message",
)
print(event.sequence_id)  # 0 

バッチ追加(最大200イベント、単一トランザクション):

session.post_events([
    {
        "body": {"content": "Looking at it now."},
        "emitter": {"type": "agent", "id": "67500a000000000000000002"},
        "event_type": "message",
    },
    {
        "body": {"content": "Found the issue - rolling back."},
        "emitter": {"type": "agent", "id": "67500a000000000000000002"},
        "event_type": "message",
    },
]) 

イベントの読み取りと編集

# Newest 20 events:
recent = session.events(last_n=20)
for e in recent:
    print(e.sequence_id, e.emitter_type, e.body)

# Edit message #1:
session.update_event(
    sequence_id=1,
    body={"content": "Looking at it now (ETA 5min)."},
) 

update_eventは、楽観的並行性のためにオプションのcreated_atを受け付けます。そのタイムスタンプ以降にイベントが変更されている場合、サーバーは更新を拒否し、呼び出し元は再読み込みして再試行する必要があります。

標準のmem0クライアントを使用したメモリーの抽出

このサービスは、メモリー空間ごとにmem0互換のサブルートを公開します。 標準のmem0ai.MemoryClientがそのルートを参照するようにすれば、通常のmem0クライアントは変更なしで動作します(add()get()search()get_all()delete())。

from mem0 import MemoryClient

endpoint = f"https://app.datarobot.com/api/v2/memory/{space.id}"
memory = MemoryClient(host=endpoint, api_key="<YOUR_DATAROBOT_API_TOKEN>")

memory.add(
    [{"role": "user", "content": "I deploy on Fridays using ArgoCD"}],
    user_id="alice",
    agent_id="support-bot",
)

hits = memory.search(
    "when do we deploy",
    filters={"user_id": "alice", "agent_id": "support-bot"},
) 

api_keyはDataRobot APIトークンです。 メモリー空間のスコープは完全にURLパス内にあり、追加のヘッダーは不要です。

Session lifecycle and retention

Every session carries one or more lifecycle strategies that control what happens to it over time. A strategy pairs an action—soft_delete (hide the session and its events) or extract_memories (promote the conversation to long-term memory)—with a trigger that decides when the action fires. If you do not supply any strategies at creation time, the server attaches a default soft_delete strategy with a 180-day TTL.

The following triggers are available:

トリガー Fires
ttl When the session age exceeds the given number of seconds (maximum two years).
eventCount When the number of events in the session reaches the threshold.
tokenCount When the total token count of the session's events reaches the threshold.
idle When no event has been added to the session for the given number of seconds (maximum two years).
never Never. The session is retained until you delete it explicitly.
session = Session.create(
    memory_space_id=space.id,
    participants=["67500a000000000000000001"],
    description="Triage chat #42",
    lifecycle_strategies=[{"type": "soft_delete", "trigger": {"ttl": 604800}}],
) 

Never-expire sessions

The never trigger opts a session out of automatic lifecycle execution entirely: the session and its events are retained until an explicit session delete (or an administrator-triggered permanent deletion) removes them.

session = Session.create(
    memory_space_id=space.id,
    participants=["67500a000000000000000001"],
    description="Application settings store",
    lifecycle_strategies=[{"type": "soft_delete", "trigger": {"never": True}}],
) 

Lifecycle strategies are set when the session is created and cannot be changed afterwards, so the never trigger applies to new sessions only. Sessions created earlier keep the expiry they were given; to hold existing data indefinitely, create a new session with the never trigger and write the data to it.

Use the never trigger for:

  • Application system data: Records such as user profiles, settings, and workspaces stored in session metadata, where expiry would break the application rather than clean up stale data. A dormant installation survives any retention window without keep-alive traffic.
  • Compliance retention beyond two years: The ttl and idle triggers cap at two years, so a longer retention floor (for example, a six-year regulatory requirement for chat history) is only expressible with never.

Avoid the never trigger for ordinary conversational history: nothing collects never-expire sessions automatically, so deleting them becomes your application's responsibility. Prefer ttl or idle for data with a natural end of life.

本機能の提供について

The never trigger is available on Self-Managed AI Platform and Single-tenant SaaS installations only; it is not available on the Multi-tenant SaaS AI Platform. The trigger is disabled by default and is enabled per installation by an administrator—see the memory service configuration. Where it is not enabled, session creation with a never trigger is rejected with a 422 response.