すべてのプロダクト
Search
ドキュメントセンター

AnalyticDB:AnalyticDB for MySQL + ReMe ベストプラクティス

最終更新日:Mar 12, 2026

ReMe は、AI エージェント向けのメモリ管理フレームワークであり、エージェントのメモリシステムを Personal Memory、Task Memory、および Tool Memory の 3 つのモジュールに分割します。この設計により、エージェントはユーザーやタスクとのインタラクション中にメモリをインテリジェントに抽出し、再利用し、共有できます。このチュートリアルでは、ReMe と AnalyticDB for MySQL を使用した AI エージェントのメモリ管理プラクティスについて説明します。環境セットアップ、サービス起動、および 3 つのコアメモリモジュールの詳細なデモをカバーしています。

前提条件

開始する前に、次の前提条件が満たされていることを確認してください。

  • AnalyticDB for MySQL クラスターを作成し、そのバージョンがベクター検索(例:余弦類似度)をサポートしていることを確認します。詳細については、「Enterprise、Basic、およびData Lakehouse Edition向けのクイックスタート」をご参照ください。

  • AnalyticDB for MySQL をサポートする ReMe フレームワークのバージョンを取得してください。

    説明

    インストールパッケージを入手するには、DingTalk (DingTalk アカウント: x5v_rm8wqzuqf) 経由で Alibaba Cloud Service Support にお問い合わせください。

  • モデルサービス API キーを入手してください。このチュートリアルでは Alibaba Cloud Model Studio を使用します。サービスをアクティブ化し、API キーを取得してください。詳細については、「API キーの取得」をご参照ください。

ユーザーガイド

環境セットアップ

  • AnalyticDB for MySQL を準備します。

    1. ご利用の AnalyticDB for MySQL クラスターに、このチュートリアル用のデータベースを作成します。

      CREATE DATABASE reme;
    2. パブリックネットワーク経由で接続する予定がある場合は、AnalyticDB for MySQL コンソールでクラスターのパブリックネットワークアクセスを有効にし、ご利用のデモ環境のパブリック IP アドレスをホワイトリストに追加してください。

  • ReMe とその依存関係のインストール。

    1. Python 環境の確認: ご利用の環境に Python がインストールされていることを確認してください。このチュートリアルは Python 3.12.2 で検証済みです。

      # For Mac, check Python version. If not installed, install from https://www.python.org/
      python3 --version
      
      # For Linux, check Python version. If not installed, install using yum: sudo yum install python
      python --version
    2. ReMe フレームワークをインストールします。Mem0 フレームワークファイルを解凍し、必要な依存関係ライブラリをインストールします。

      # Unzip and install flowllm
      unzip flowllm.zip
      cd flowllm
      pip install .
      
      # Unzip and install ReMe
      unzip ReMe.zip
      cd Reme
      pip install .

構成と起動

  • 環境変数の構成:

    セキュリティのため、大規模言語モデル (LLM) API キーを環境変数として構成します。

    echo "export DASHSCOPE_API_KEY='<YOUR_DASHSCOPE_API_KEY>'" >> ~/.bashrc
    # オプション。デフォルトはシンガポールです。
    echo "export DASHSCOPE_BASE_URL='https://dashscope-intl.aliyuncs.com/compatible-mode/v1'" >> ~/.bashrc   
    
    source ~/.bashrc
    
    # Check if it took effect
    echo $DASHSCOPE_API_KEY
    echo $DASHSCOPE_BASE_URL  
  • AnalyticDB for MySQL の接続情報を環境変数として構成します。

    cd ReMe
    mv example.env .env

    .env ファイルを編集します。次の内容を実際の構成に置き換えてください。

    FLOW_EMBEDDING_API_KEY=<YOUR_DASHSCOPE_API_KEY>
    FLOW_EMBEDDING_BASE_URL=<YOUR_DASHSCOPE_BASE_URL>
    FLOW_LLM_API_KEY=<YOUR_DASHSCOPE_API_KEY>
    FLOW_LLM_BASE_URL=<YOUR_DASHSCOPE_BASE_URL>
    
    ADB_HOST=<YOUR_ADB_HOST>
    ADB_PORT=3306
    ADB_USER=<YOUR_ADB_USER>
    ADB_PASSWORD=<YOUR_ADB_PASSWORD>
    ADB_DATABASE=reme
  • ReMe サービスの起動。

    • 次のコマンドを実行して ReMe サービスを起動します。

      cd ReMe
      reme \
        backend=http \
        http.port=8002 \
        llm.default.model_name=qwen3-max \
        embedding_model.default.model_name=text-embedding-v4 \
        vector_store.default.backend=aliyun_adb_mysql
    • サービスが正常に起動すると、コンソールにサービスステータスが表示されます。

      image

    • 起動パラメーターの説明:

      パラメーター

      説明

      LLM

      Alibaba Cloud Model Studio の qwen3-max モデルを使用します (他のサポートされているモデルに置き換えることができます)。

      Embedder

      Alibaba Cloud Model Studio の text-embedding-v4 モデルを使用し、1536 ベクトル次元です。

      vector_store

      AnalyticDB for MySQL をベクターストアバックエンドとして使用します。

コアメモリ操作デモ

  • Personal Memory

    Personal Memory は、名前、職業、趣味など、特定のユーザーに関連する静的情報を保存および取得します。

    • デモを実行:

      cd ReMe
      python3 ./cookbook/simple_demo/use_personal_memory_demo.py
    • 結果の分析:

      1. 会話の作成と情報のフェッチ: デモではまず、マルチターン対話を通じて、ユーザーの個人情報 (名前、職業、興味など) を入力します。ReMe はこの情報を会話から自動的にフェッチし、Personal Memory に保存します。

      2. メモリの要約とストレージ: システムは、抽出された情報を、キーワード、ソースメッセージ、観測タイプなどのメタデータを含む構造化されたメモリのエントリに要約し、これらのエントリを AnalyticDB for MySQL に永続化します。

      3. セマンティック取得の検証: 最後に、デモでは一連の自然言語の質問をすることで、メモリ取得のパフォーマンスを検証します。

    • デモからの取得例と期待される結果:

      lhj@B-F21WMGFD-2205 ReMe % python3 ./cookbook/simple_demo/use_personal_memory_demo.py 
      既存のメモリをクリアしています...
      {"answer": "", "messages": [], "success": true, "metadata": {"action_result": ""}}
      
      個人情報を含む会話を作成しています...
      
      個人のメモリを要約しています...
      {
        "answer": "",
        "messages": [],
        "success": true,
        "metadata": {
          "memory_list": [
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "7f253fb5ab75402eaa84e23cee76ef52",
              "memory_type": "personal",
              "when_to_use": "John Smith、28 歳、ハイテク企業、サンフランシスコ",
              "content": "ユーザーの名前は John Smith、28 歳、サンフランシスコのハイテク企業に勤務",
              "score": 0.0,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "John Smith、28 歳、ハイテク企業、サンフランシスコ",
                "source_message": "私の名前は John Smith、28 歳で、サンフランシスコのハイテク企業で働いています",
                "observation_type": "personal_info"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "d423370cfa5e47e2b53f5c77f4e2353e",
              "memory_type": "personal",
              "when_to_use": "ソフトウェアエンジニア、バックエンド開発、Python、Go",
              "content": "ユーザーはソフトウェアエンジニアで、Python と Go を使用したバックエンド開発を専門としています",
              "score": 0.0,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "ソフトウェアエンジニア、バックエンド開発、Python、Go",
                "source_message": "私はソフトウェアエンジニアで、主に Python と Go を使ってバックエンド開発をしています",
                "observation_type": "personal_info"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "88474b71f7f24ac3961a349914407250",
              "memory_type": "personal",
              "when_to_use": "バスケットボール、SF 映画、Dune Part 2",
              "content": "ユーザーはバスケットボールと SF 映画鑑賞を楽しみ、最近 Dune Part 2 を観ました",
              "score": 0.0,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "バスケットボール、SF 映画、Dune Part 2",
                "source_message": "私はバスケットボールと SF 映画鑑賞が趣味です。最近、Dune Part 2 を観ました",
                "observation_type": "personal_info"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "9a8b4f81c66b4068b2e53146374ebc7a",
              "memory_type": "personal",
              "when_to_use": "猫、Shadow、ペット",
              "content": "ユーザーは Shadow という名前の 3 歳の猫を飼っています",
              "score": 0.0,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "猫、Shadow、ペット",
                "source_message": "私は Shadow という名前の 3 歳の猫を飼っています",
                "observation_type": "personal_info"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "b72a6d0927e04ea7a2de9e28b4c008ec",
              "memory_type": "personal",
              "when_to_use": "日本料理、寿司、ラーメン",
              "content": "ユーザーは日本料理、特に寿司とラーメンに興味があります",
              "score": 0.0,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "日本料理、寿司、ラーメン",
                "source_message": "私は日本料理、特に寿司とラーメンにとても興味があります",
                "observation_type": "personal_info"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "f900b79060804a1587d59032c63f1e3c",
              "memory_type": "personal",
              "when_to_use": "日本、東京、京都、旅行",
              "content": "ユーザーは 2025 年 12 月に東京と京都への旅行を計画しています",
              "score": 0.0,
              "time_created": "2025-11-04 17:22:46",
              "time_modified": "2025-11-04 17:22:46",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "日本、東京、京都、旅行",
                "time_info": "December 2025",
                "source_message": "来月、主に東京と京都へ日本旅行を計画しています",
                "observation_type": "personal_info_with_time"
              },
              "target": "user",
              "reflection_subject": ""
            }
          ],
          "deleted_memory_ids": [],
          "update_result": {
            "deleted_count": 0,
            "inserted_count": 6
          }
        }
      }
      
      メモリが処理されるのを待機しています...
      
      個人のメモリを取得しています...
      
      クエリ: 私の名前と年齢は?
      {
        "answer": "ユーザーの名前は John Smith、28 歳、サンフランシスコのハイテク企業に勤務\nユーザーは Shadow という名前の 3 歳の猫を飼っています\nユーザーは 2025 年 12 月に東京と京都への旅行を計画しています",
        "messages": [],
        "success": true,
        "metadata": {
          "memory_list": [
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "7f253fb5ab75402eaa84e23cee76ef52",
              "memory_type": "personal",
              "when_to_use": "John Smith、28 歳、ハイテク企業、サンフランシスコ",
              "content": "ユーザーの名前は John Smith、28 歳、サンフランシスコのハイテク企業に勤務",
              "score": 0.038895229,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "John Smith、28 歳、ハイテク企業、サンフランシスコ",
                "source_message": "私の名前は John Smith、28 歳で、サンフランシスコのハイテク企業で働いています",
                "observation_type": "personal_info",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "9a8b4f81c66b4068b2e53146374ebc7a",
              "memory_type": "personal",
              "when_to_use": "猫、Shadow、ペット",
              "content": "ユーザーは Shadow という名前の 3 歳の猫を飼っています",
              "score": 0.027221944999999997,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "猫、Shadow、ペット",
                "source_message": "私は Shadow という名前の 3 歳の猫を飼っています",
                "observation_type": "personal_info",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "f900b79060804a1587d59032c63f1e3c",
              "memory_type": "personal",
              "when_to_use": "日本、東京、京都、旅行",
              "content": "ユーザーは 2025 年 12 月に東京と京都への旅行を計画しています",
              "score": 0.024106982,
              "time_created": "2025-11-04 17:22:46",
              "time_modified": "2025-11-04 17:22:46",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "日本、東京、京都、旅行",
                "time_info": "December 2025",
                "source_message": "来月、主に東京と京都へ日本旅行を計画しています",
                "observation_type": "personal_info_with_time",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            }
          ]
        }
      }
      
      クエリ: 私の仕事は何ですか?
      {
        "answer": "ユーザーの名前は John Smith、28 歳、サンフランシスコのハイテク企業に勤務\nユーザーはソフトウェアエンジニアで、Python と Go を使用したバックエンド開発を専門としています\nユーザーは 2025 年 12 月に東京と京都への旅行を計画しています",
        "messages": [],
        "success": true,
        "metadata": {
          "memory_list": [
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "7f253fb5ab75402eaa84e23cee76ef52",
              "memory_type": "personal",
              "when_to_use": "John Smith、28 歳、ハイテク企業、サンフランシスコ",
              "content": "ユーザーの名前は John Smith、28 歳、サンフランシスコのハイテク企業に勤務",
              "score": 0.029179364000000003,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "John Smith、28 歳、ハイテク企業、サンフランシスコ",
                "source_message": "私の名前は John Smith、28 歳で、サンフランシスコのハイテク企業で働いています",
                "observation_type": "personal_info",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "d423370cfa5e47e2b53f5c77f4e2353e",
              "memory_type": "personal",
              "when_to_use": "ソフトウェアエンジニア、バックエンド開発、Python、Go",
              "content": "ユーザーはソフトウェアエンジニアで、Python と Go を使用したバックエンド開発を専門としています",
              "score": 0.024785686,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "ソフトウェアエンジニア、バックエンド開発、Python、Go",
                "source_message": "私はソフトウェアエンジニアで、主に Python と Go を使ってバックエンド開発をしています",
                "observation_type": "personal_info",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "f900b79060804a1587d59032c63f1e3c",
              "memory_type": "personal",
              "when_to_use": "日本、東京、京都、旅行",
              "content": "ユーザーは 2025 年 12 月に東京と京都への旅行を計画しています",
              "score": 0.017342727,
              "time_created": "2025-11-04 17:22:46",
              "time_modified": "2025-11-04 17:22:46",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "日本、東京、京都、旅行",
                "time_info": "December 2025",
                "source_message": "来月、主に東京と京都へ日本旅行を計画しています",
                "observation_type": "personal_info_with_time",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            }
          ]
        }
      }
      
      クエリ: 私の趣味は何ですか?
      {
        "answer": "ユーザーは 2025 年 12 月に東京と京都への旅行を計画しています\nユーザーはソフトウェアエンジニアで、Python と Go を使用したバックエンド開発を専門としています\nユーザーは日本料理、特に寿司とラーメンに興味があります",
        "messages": [],
        "success": true,
        "metadata": {
          "memory_list": [
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "f900b79060804a1587d59032c63f1e3c",
              "memory_type": "personal",
              "when_to_use": "日本、東京、京都、旅行",
              "content": "ユーザーは 2025 年 12 月に東京と京都への旅行を計画しています",
              "score": 0.025223058,
              "time_created": "2025-11-04 17:22:46",
              "time_modified": "2025-11-04 17:22:46",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "日本、東京、京都、旅行",
                "time_info": "December 2025",
                "source_message": "来月、主に東京と京都へ日本旅行を計画しています",
                "observation_type": "personal_info_with_time",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "d423370cfa5e47e2b53f5c77f4e2353e",
              "memory_type": "personal",
              "when_to_use": "ソフトウェアエンジニア、バックエンド開発、Python、Go",
              "content": "ユーザーはソフトウェアエンジニアで、Python と Go を使用したバックエンド開発を専門としています",
              "score": 0.024959816000000003,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "ソフトウェアエンジニア、バックエンド開発、Python、Go",
                "source_message": "私はソフトウェアエンジニアで、主に Python と Go を使ってバックエンド開発をしています",
                "observation_type": "personal_info",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "b72a6d0927e04ea7a2de9e28b4c008ec",
              "memory_type": "personal",
              "when_to_use": "日本料理、寿司、ラーメン",
              "content": "ユーザーは日本料理、特に寿司とラーメンに興味があります",
              "score": 0.020527664,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "日本料理、寿司、ラーメン",
                "source_message": "私は日本料理、特に寿司とラーメンにとても興味があります",
                "observation_type": "personal_info",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            }
          ]
        }
      }
      
      クエリ: ペットはいますか?
      {
        "answer": "ユーザーは Shadow という名前の 3 歳の猫を飼っています\nユーザーの名前は John Smith、28 歳、サンフランシスコのハイテク企業に勤務\nユーザーは 2025 年 12 月に東京と京都への旅行を計画しています",
        "messages": [],
        "success": true,
        "metadata": {
          "memory_list": [
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "9a8b4f81c66b4068b2e53146374ebc7a",
              "memory_type": "personal",
              "when_to_use": "猫、Shadow、ペット",
              "content": "ユーザーは Shadow という名前の 3 歳の猫を飼っています",
              "score": 0.044214043,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "猫、Shadow、ペット",
                "source_message": "私は Shadow という名前の 3 歳の猫を飼っています",
                "observation_type": "personal_info",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "7f253fb5ab75402eaa84e23cee76ef52",
              "memory_type": "personal",
              "when_to_use": "John Smith、28 歳、ハイテク企業、サンフランシスコ",
              "content": "ユーザーの名前は John Smith、28 歳、サンフランシスコのハイテク企業に勤務",
              "score": 0.026690182000000003,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "John Smith、28 歳、ハイテク企業、サンフランシスコ",
                "source_message": "私の名前は John Smith、28 歳で、サンフランシスコのハイテク企業で働いています",
                "observation_type": "personal_info",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "f900b79060804a1587d59032c63f1e3c",
              "memory_type": "personal",
              "when_to_use": "日本、東京、京都、旅行",
              "content": "ユーザーは 2025 年 12 月に東京と京都への旅行を計画しています",
              "score": 0.023277275,
              "time_created": "2025-11-04 17:22:46",
              "time_modified": "2025-11-04 17:22:46",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "日本、東京、京都、旅行",
                "time_info": "December 2025",
                "source_message": "来月、主に東京と京都へ日本旅行を計画しています",
                "observation_type": "personal_info_with_time",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            }
          ]
        }
      }
      
      クエリ: 私の旅行の計画は?
      {
        "answer": "ユーザーは 2025 年 12 月に東京と京都への旅行を計画しています\nユーザーの名前は John Smith、28 歳、サンフランシスコのハイテク企業に勤務\nユーザーはソフトウェアエンジニアで、Python と Go を使用したバックエンド開発を専門としています",
        "messages": [],
        "success": true,
        "metadata": {
          "memory_list": [
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "f900b79060804a1587d59032c63f1e3c",
              "memory_type": "personal",
              "when_to_use": "日本、東京、京都、旅行",
              "content": "ユーザーは 2025 年 12 月に東京と京都への旅行を計画しています",
              "score": 0.04186047600000001,
              "time_created": "2025-11-04 17:22:46",
              "time_modified": "2025-11-04 17:22:46",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "日本、東京、京都、旅行",
                "time_info": "December 2025",
                "source_message": "来月、主に東京と京都へ日本旅行を計画しています",
                "observation_type": "personal_info_with_time",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "7f253fb5ab75402eaa84e23cee76ef52",
              "memory_type": "personal",
              "when_to_use": "John Smith、28 歳、ハイテク企業、サンフランシスコ",
              "content": "ユーザーの名前は John Smith、28 歳、サンフランシスコのハイテク企業に勤務",
              "score": 0.025156727000000004,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "John Smith、28 歳、ハイテク企業、サンフランシスコ",
                "source_message": "私の名前は John Smith、28 歳で、サンフランシスコのハイテク企業で働いています",
                "observation_type": "personal_info",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "d423370cfa5e47e2b53f5c77f4e2353e",
              "memory_type": "personal",
              "when_to_use": "ソフトウェアエンジニア、バックエンド開発、Python、Go",
              "content": "ユーザーはソフトウェアエンジニアで、Python と Go を使用したバックエンド開発を専門としています",
              "score": 0.019123243,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "ソフトウェアエンジニア、バックエンド開発、Python、Go",
                "source_message": "私はソフトウェアエンジニアで、主に Python と Go を使ってバックエンド開発をしています",
                "observation_type": "personal_info",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            }
          ]
        }
      }
      
      クエリ: 私の好きな食べ物は何ですか?
      {
        "answer": "ユーザーは日本料理、特に寿司とラーメンに興味があります\nユーザーは 2025 年 12 月に東京と京都への旅行を計画しています\nユーザーはソフトウェアエンジニアで、Python と Go を使用したバックエンド開発を専門としています",
        "messages": [],
        "success": true,
        "metadata": {
          "memory_list": [
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "b72a6d0927e04ea7a2de9e28b4c008ec",
              "memory_type": "personal",
              "when_to_use": "日本料理、寿司、ラーメン",
              "content": "ユーザーは日本料理、特に寿司とラーメンに興味があります",
              "score": 0.0316972,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "日本料理、寿司、ラーメン",
                "source_message": "私は日本料理、特に寿司とラーメンにとても興味があります",
                "observation_type": "personal_info",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "f900b79060804a1587d59032c63f1e3c",
              "memory_type": "personal",
              "when_to_use": "日本、東京、京都、旅行",
              "content": "ユーザーは 2025 年 12 月に東京と京都への旅行を計画しています",
              "score": 0.022572586000000002,
              "time_created": "2025-11-04 17:22:46",
              "time_modified": "2025-11-04 17:22:46",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "日本、東京、京都、旅行",
                "time_info": "December 2025",
                "source_message": "来月、主に東京と京都へ日本旅行を計画しています",
                "observation_type": "personal_info_with_time",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            },
            {
              "workspace_id": "personal_memory_demo",
              "memory_id": "d423370cfa5e47e2b53f5c77f4e2353e",
              "memory_type": "personal",
              "when_to_use": "ソフトウェアエンジニア、バックエンド開発、Python、Go",
              "content": "ユーザーはソフトウェアエンジニアで、Python と Go を使用したバックエンド開発を専門としています",
              "score": 0.021622963000000002,
              "time_created": "2025-11-04 17:22:50",
              "time_modified": "2025-11-04 17:22:50",
              "author": "qwen3-max",
              "metadata": {
                "keywords": "ソフトウェアエンジニア、バックエンド開発、Python、Go",
                "source_message": "私はソフトウェアエンジニアで、主に Python と Go を使ってバックエンド開発をしています",
                "observation_type": "personal_info",
                "match_event_flag": "0",
                "match_msg_flag": "0"
              },
              "target": "user",
              "reflection_subject": ""
            }
          ]
        }
      }

      クエリの質問

      期待される取得結果

      "私の仕事は何ですか?"

      仕事関連のメモリ (ソフトウェアエンジニア、Python/Go バックエンド開発) を返します。

      "私の趣味は何ですか?"

      趣味関連のメモリ (日本料理、旅行計画) を返します。

      "ペットを飼っていますか?"

      ペット関連のメモリ (3歳の猫シャドウ) を返します。

  • Task Memory

    Task Memory は、エージェントが特定のタスクを完了する際に蓄積する経験と方法論を記録します。これにより、エージェントは同様の将来のタスクを処理する際にこの経験を再利用でき、効率と品質が向上します。

    • デモを実行:

      cd ReMe
      python3 ./cookbook/simple_demo/use_task_memory_demo.py
    • 実行結果の分析:

      1. 初期タスク実行: エージェントは「Tesla 社を分析」というタスクを受信します。タスクを会社概要、財務実績、技術革新などの 6 つのディメンションに分解します。次に、検索ツールを使用して情報を収集します。

      2. 方法論の改善: タスクが完了した後、システムは実行プロセスから再利用可能な方法論的経験を抽出します。例:

        • 複雑な分析タスクを複数のサブタスクに分解します。

        • 2段階取得戦略を使用して情報ギャップを埋めます。

        • レポートの可読性を向上させるために出力構造を整理します。

      3. メモリの再利用: エージェントが「Xiaomi 社を分析」のような同様の新しいタスクを受信すると、システムは以前に蓄積されたタスク経験を自動的に取得して適用します。これにより、より包括的で論理的に構造化された分析結果を生成するための、強化された最適化されたクエリ戦略が生成されます。

    • デモからの取得例と期待される結果:

      === Task Memory Demo ===
      
      1. Deleting workspace...
      Workspace 'test_workspace' deleted successfully
      
      2. Running agent with first query...
      Agent response: I have gathered comprehensive information about Xiaomi Corporation through multiple targeted searches. Here's a summary of the analysis:
      
      1. **Company Overview**: Xiaomi Corporation is a Chinese multinational technology company founded in 2010, known for its smartphones, smart home devices, and IoT ecosystem. It operates globally with a strong presence in Asia, Europe, and Latin America.
      
      2. **Financial Performance (2024)**: Xiaomi reported robust financial results in 2024, with significant revenue growth driven by smartphone sales and expansion in its Internet of Things (IoT) product lines. The company maintained profitability despite global economic challenges.
      
      3. **Product Portfolio & Innovations**: Xiaomi continues to innovate in areas such as high-performance smartphones (e.g., Mi series), foldable phones, electric vehicles (Xiaomi SU7), and an expanding range of smart home products integrated into its MIUI ecosystem.
      
      4. **Market Position**: Xiaomi remains one of the top five global smartphone manufacturers, particularly strong in emerging markets. Its competitive pricing strategy and focus on value-for-money products have helped it gain market share.
      
      5. **Challenges & Risks (2025)**: Key challenges include increasing competition from brands like Samsung, Apple, and Oppo, supply chain volatility, geopolitical tensions affecting international operations, and the need to sustain innovation in the EV sector.
      
      6. **Recent Developments (2025)**: In early 2025, Xiaomi launched its new electric vehicle model, the SU7 Pro, which received positive reviews. The company also expanded its AI-powered smart home platform and strengthened partnerships in Southeast Asia and Europe.
      
      This analysis provides a holistic view of Xiaomi Corporation’s current status, strategic direction, and future outlook.
      Messages saved to messages.jsonl
      
      3. Running memory-augmented agent workflow...
      
      --- Building memories with query: 'Analyze the company Tesla.' ---
      Agent response: I have gathered comprehensive information about Tesla through multiple search queries. Here is a summary of the key aspects:
      
      1. **Company Overview**: Tesla, Inc. is an American electric vehicle and clean energy company founded in 2003 by Martin Eberhard and Marc Tarpenning, with Elon Musk playing a pivotal role since 2004. The company designs, manufactures, and sells electric vehicles (EVs), solar panels, and energy storage systems.
      
      2. **Financial Performance (2024)**: Tesla reported strong financial results in 2024, with increased revenue driven by higher vehicle deliveries and growth in its energy products segment. However, the company faced challenges related to production scaling and global economic conditions affecting demand.
      
      3. **Recent Innovations and Technology Developments**: Tesla continues to lead in EV technology, including advancements in battery efficiency, autonomous driving (Full Self-Driving or FSD), and the development of next-generation platforms like the "Tesla Model 2" (rumored). The company also expanded its AI capabilities through projects like Optimus (humanoid robot).
      
      4. **CEO Elon Musk's Recent Activities**: Elon Musk has been actively involved in public discussions about AI ethics, infrastructure projects (e.g., Hyperloop), and the future of transportation. He has also engaged in high-profile social media interactions and strategic decisions impacting Tesla’s direction.
      
      5. **Market Position and Competition**: Tesla remains a dominant player in the global EV market, though it faces increasing competition from traditional automakers (e.g., Ford, Volkswagen) and new entrants (e.g., BYD, Rivian). Despite this, Tesla maintains a strong brand presence and technological edge.
      
      6. **Environmental Impact and Sustainability Initiatives**: Tesla is committed to reducing carbon emissions through its products and operations. The company emphasizes sustainable manufacturing practices, renewable energy integration, and recycling programs for batteries.
      
      This analysis provides a well-rounded view of Tesla’s current status, challenges, and future outlook.
      
      --- Summarizing conversation to create memories ---
      Memory list: [{'workspace_id': 'test_workspace', 'memory_id': '4a0f9408ee2b4cdda721d6bfed8a0a24', 'memory_type': 'task', 'when_to_use': 'When analyzing a complex, multi-faceted entity like a major corporation that requires coverage across business, financial, technological, leadership, competitive, and sustainability dimensions.', 'content': "The agent decomposed the broad request 'Analyze the company Tesla' into six distinct thematic subtasks (overview, financials, innovation, leadership, competition, sustainability) and executed parallel and sequential tool calls to gather targeted information. This structured decomposition ensured comprehensive coverage without redundancy, while iterative querying allowed refinement based on emerging context.", 'score': 0.85, 'time_created': '2025-11-04 19:35:23', 'time_modified': '2025-11-04 19:35:23', 'author': 'qwen3-max', 'metadata': {'when_to_use': 'When analyzing a complex, multi-faceted entity like a major corporation that requires coverage across business, financial, technological, leadership, competitive, and sustainability dimensions.', 'experience': "The agent decomposed the broad request 'Analyze the company Tesla' into six distinct thematic subtasks (overview, financials, innovation, leadership, competition, sustainability) and executed parallel and sequential tool calls to gather targeted information. This structured decomposition ensured comprehensive coverage without redundancy, while iterative querying allowed refinement based on emerging context.", 'tags': ['problem decomposition', 'multi-perspective analysis', 'corporate analysis', 'iterative search'], 'confidence': 0.95, 'step_type': 'reasoning', 'tools_used': ['dashscope_search']}}, {'workspace_id': 'test_workspace', 'memory_id': '51ddcd1b679e45fc86aacd5982a1cc54', 'memory_type': 'task', 'when_to_use': 'When initial information gathering is insufficient to form a holistic answer, and additional contextual layers (e.g., leadership impact or market dynamics) are needed to enrich understanding.', 'content': 'After an initial round of three searches, the agent proactively identified gaps—specifically around leadership influence and competitive landscape—and issued a second wave of targeted queries. This adaptive two-phase retrieval strategy demonstrates effective metacognition: assessing coverage completeness and filling critical knowledge gaps before synthesis.', 'score': 0.85, 'time_created': '2025-11-04 19:35:23', 'time_modified': '2025-11-04 19:35:23', 'author': 'qwen3-max', 'metadata': {'when_to_use': 'When initial information gathering is insufficient to form a holistic answer, and additional contextual layers (e.g., leadership impact or market dynamics) are needed to enrich understanding.', 'experience': 'After an initial round of three searches, the agent proactively identified gaps—specifically around leadership influence and competitive landscape—and issued a second wave of targeted queries. This adaptive two-phase retrieval strategy demonstrates effective metacognition: assessing coverage completeness and filling critical knowledge gaps before synthesis.', 'tags': ['adaptive querying', 'gap analysis', 'context enrichment', 'sequential tool use'], 'confidence': 0.9, 'step_type': 'decision', 'tools_used': ['dashscope_search']}}, {'workspace_id': 'test_workspace', 'memory_id': '79e7bb2e055640f3975c12c719e10092', 'memory_type': 'task', 'when_to_use': 'When synthesizing information from multiple heterogeneous sources into a coherent, structured summary for user consumption.', 'content': 'The final response organized findings into six clearly labeled thematic sections that directly mirrored the query decomposition strategy. This alignment between information-gathering structure and output format enhanced clarity, reduced cognitive load, and ensured all subtasks were visibly addressed—demonstrating strong traceability from intent to delivery.', 'score': 0.85, 'time_created': '2025-11-04 19:35:23', 'time_modified': '2025-11-04 19:35:23', 'author': 'qwen3-max', 'metadata': {'when_to_use': 'When synthesizing information from multiple heterogeneous sources into a coherent, structured summary for user consumption.', 'experience': 'The final response organized findings into six clearly labeled thematic sections that directly mirrored the query decomposition strategy. This alignment between information-gathering structure and output format enhanced clarity, reduced cognitive load, and ensured all subtasks were visibly addressed—demonstrating strong traceability from intent to delivery.', 'tags': ['structured synthesis', 'thematic organization', 'answer coherence', 'user-centric summarization'], 'confidence': 0.85, 'step_type': 'action', 'tools_used': []}}]
      Memory saved to memory.jsonl
      
      --- Retrieving memories for query: 'Analyze Xiaomi Corporation' ---
      Retrieved memory: To effectively analyze Xiaomi Corporation, adopt a structured, multi-dimensional approach that systematically examines its core business segments, financial performance, technological innovation, leadership strategy, competitive positioning, and sustainability initiatives. Begin by decomposing the analysis into these six thematic pillars to ensure comprehensive coverage without redundancy. Use parallel and sequential information-gathering methods to collect targeted data on each dimension—starting with Xiaomi’s product ecosystem (smartphones, IoT, EVs), revenue streams, and geographic footprint. If initial findings lack depth in critical areas such as leadership vision or competitive dynamics in key markets like China, India, or Europe, proactively issue follow-up queries to fill those gaps. This adaptive two-phase retrieval ensures a holistic understanding before synthesis. Finally, organize the output into clearly labeled sections that mirror the original analytical framework, creating a coherent, traceable narrative that directly addresses the user’s request while minimizing cognitive load. This method—proven effective for complex corporate analyses like Tesla—ensures actionable, well-rounded insights tailored to Xiaomi’s unique position at the intersection of consumer electronics, smart hardware, and emerging mobility.
      
      --- Running agent with memory-augmented query ---
      Augmented query: To effectively analyze Xiaomi Corporation, adopt a structured, multi-dimensional approach that systematically examines its core business segments, financial performance, technological innovation, leadership strategy, competitive positioning, and sustainability initiatives. Begin by decomposing the analysis into these six thematic pillars to ensure comprehensive coverage without redundancy. Use parallel and sequential information-gathering methods to collect targeted data on each dimension—starting with Xiaomi’s product ecosystem (smartphones, IoT, EVs), revenue streams, and geographic footprint. If initial findings lack depth in critical areas such as leadership vision or competitive dynamics in key markets like China, India, or Europe, proactively issue follow-up queries to fill those gaps. This adaptive two-phase retrieval ensures a holistic understanding before synthesis. Finally, organize the output into clearly labeled sections that mirror the original analytical framework, creating a coherent, traceable narrative that directly addresses the user’s request while minimizing cognitive load. This method—proven effective for complex corporate analyses like Tesla—ensures actionable, well-rounded insights tailored to Xiaomi’s unique position at the intersection of consumer electronics, smart hardware, and emerging mobility.
      
      User Question:
      Analyze Xiaomi Corporation
      Agent response: Based on the comprehensive analysis of Xiaomi Corporation, here is a structured overview across key dimensions:
      
      ### 1. **Business Segments & Product Ecosystem**
      Xiaomi operates through three core segments:
      - **Smartphones**: A cornerstone of its business, with a strong global presence.
      - **IoT and Smart Home Devices**: A rapidly growing segment including wearables, home appliances, and smart lighting. Xiaomi’s ecosystem approach integrates hardware, software, and services.
      - **Electric Vehicles (EVs)**: A strategic new venture launched in 2021, with the Mi EV model entering production. This marks a significant pivot into mobility.
      
      ### 2. **Financial Performance & Revenue Streams**
      In 2024, Xiaomi reported robust financial performance:
      - Revenue growth driven by smartphone sales and IoT expansion.
      - Diversified revenue streams: smartphones (~50%), IoT (~30%), and EVs (~20% projected).
      - Strong profitability in key markets like China and India, with increasing margins from high-margin IoT products.
      
      ### 3. **Technological Innovation**
      Xiaomi is investing heavily in R&D:
      - Development of proprietary AI chips (e.g., Surge series) to enhance performance in smartphones and IoT devices.
      - Focus on AI integration across its ecosystem, including voice assistants and smart home automation.
      - Advancements in battery technology and energy efficiency for both mobile and EV platforms.
      
      ### 4. **Leadership Strategy & Vision**
      Under CEO Lei Jun, Xiaomi’s strategy emphasizes:
      - "Internet + Hardware + Software" integration to create seamless user experiences.
      - Long-term vision of building a global smart lifestyle ecosystem.
      - Strategic focus on innovation, cost-efficiency, and rapid market entry.
      
      ### 5. **Competitive Positioning**
      Xiaomi holds strong positions in key markets:
      - **China**: One of the top 3 smartphone vendors, leveraging brand loyalty and affordable premium offerings.
      - **India**: Market leader in smartphones, with aggressive pricing and extensive retail networks.
      - **Europe**: Rapidly gaining share, particularly in mid-to-high-end segments, due to design quality and value-for-money propositions.
      
      ### 6. **Sustainability & Future Initiatives**
      Xiaomi is advancing sustainability efforts:
      - Commitment to carbon neutrality goals by 2030.
      - Eco-friendly materials in packaging and product design.
      - EV development aligns with global green mobility trends, with zero-emission vehicles under development.
      
      ### Additional Insights
      - **Global Expansion**: Aggressive international rollout via online platforms and local partnerships, especially in Southeast Asia, Latin America, and Europe.
      - **Supply Chain**: Collaborates with leading manufacturers (e.g., Foxconn, BYD) while maintaining control over core R&D and design.
      - **Consumer Loyalty**: High customer retention due to ecosystem lock-in and consistent product quality.
      
      Xiaomi’s future success hinges on its ability to scale EV production, deepen AI integration, and maintain its competitive edge in emerging markets.
      
      4. Dumping memory to disk...
      Memory dumped to ./
      
      5. Loading memory from disk...
      Memory loaded from ./
      
      === Demo Complete ===
  • Tool Memory

    Tool Memory は、API や関数など、さまざまなツールを使用したエージェントの経験を記録します。これには、ツールのコア機能、成功パターン、一般的な問題、およびベストプラクティスが含まれます。

    • デモを実行:

      cd ReMe
      python3 ./cookbook/simple_demo/use_tool_memory_demo.py
    • 結果の分析:

      1. ツール呼び出しのシミュレート: デモではまず、database_queryfile_processor、および web_search の 3 つのツールについて、70 件のツール呼び出しレコードをシミュレートします。

      2. 経験の要約の生成: システムはこれらの呼び出しレコードを自動的に分析し、各ツールの詳細な使用経験の要約を生成します。要約には、次の主要なディメンションが含まれます。

        ディメンション

        説明

        コア機能

        ツールの主な目的と適用可能なシナリオ。

        成功パターン

        成功したツール呼び出しの典型的な条件とパラメーターの組み合わせ。

        よくある質問

        失敗したツール呼び出しの一般的な理由の分析。

        ベストプラクティス

        使用に関する推奨事項と注意事項。

        統計

        成功率、平均消費時間、平均トークン消費量などの定量的メトリック。

    • デモからの取得例と期待される結果:

      2025-11-04 19:39:10.101 | INFO     | flowllm.utils.common_utils:load_env:64 - load env_path=.env
      set FLOW_APP_NAME=ReMe
      
      [1] Cleaning workspace...
      ✓ Workspace 'test_tool_memory_workspace' deleted
      
      [2] Adding mock tool call results...
      
      [ADD] 70 results for 3 tools: database_query, file_processor, web_search
      ✓ Added successfully, created/updated 3 tool memories
      
      [3] Summarizing tool memories...
      
      [SUMMARIZE] web_search,database_query,file_processor
      ✓ Summarized 3 tool memories
      
      ============================================================
      Tool: web_search
      ============================================================
      1. **Core Function**: The web_search tool retrieves authoritative technical documentation, tutorials, and best practices for specific developer-focused queries (e.g., "GraphQL advantages", "OAuth2 flow"). Use it when seeking reliable, in-depth technical information.
      
      2. **Success Patterns**: High-quality results occur with precise, domain-specific queries (e.g., "JWT authentication", "MongoDB schema design") combined with valid parameters like language="en" and filter="technical_docs". These consistently yield 14–19 relevant, authoritative sources.
      
      3. **Common Issues**: Queries fail or return minimal results when: (a) the query is overly generic (e.g., "test query 1"), (b) an unsupported language (e.g., "unknown") is specified, or (c) the request times out (10s cap). Nonsensical queries correctly return zero results but are handled gracefully.
      
      4. **Best Practices**: 
         - Always use specific, technical keywords that reflect real developer tasks or concepts.
         - Validate language parameters (use "en" or other supported codes) and avoid placeholder or invalid values.
      
      ## Statistics
      - **Success Rate**: 75.00%
      - **Average Score**: 0.350
      - **Average Time Cost**: 4.300s
      - **Average Token Cost**: 96.0
      
      ============================================================
      Tool: database_query
      ============================================================
      1. **Core Function**: Executes SQL-like queries on specified tables, returning matching rows up to a user-defined limit. Use when retrieving filtered, ordered, or pattern-matched data from known tables.
      
      2. **Success Patterns**: Queries succeed when using valid table/column names, clear WHERE conditions (e.g., id > N), and reasonable limits. Results are reliable when row counts respect the limit or truthfully reflect available data (even if fewer rows exist).
      
      3. **Common Issues**: Frequent failures occur when: (a) returned rows exceed the specified limit—indicating improper limit enforcement; (b) invalid table/column names cause errors; or (c) results omit actual data rows, returning only metadata.
      
      4. **Best Practices**: 
         - Always verify table and column names match the schema to avoid execution errors. 
         - Treat returned row counts skeptically if they exceed your limit—reformulate or validate the query.
         - For large datasets with LIKE or sorting, expect performance notes; consider indexing suggestions provided in successful responses.
      
      ## Statistics
      - **Success Rate**: 80.00%
      - **Average Score**: 0.650
      - **Average Time Cost**: 2.157s
      - **Average Token Cost**: 55.8
      
      ============================================================
      Tool: file_processor
      ============================================================
      1. **Core Function**: The file_processor reads structured and unstructured files (CSV, JSON, XML, TXT, PDF) and returns metadata—file size and record count—without exposing raw content. Use it to quickly assess file contents before deeper processing.
      
      2. **Success Patterns**: Works reliably on files under ~500KB across all supported formats when valid paths and encodings (e.g., UTF-8) are provided. Consistently returns useful metadata for small-to-medium files in under 3 seconds.
      
      3. **Common Issues**: Fails silently on large files (>500KB–1MB), returning only a size warning without metadata or content—despite marking the call as "successful." Also fails if the file path is invalid, though it correctly reports this error.
      
      4. **Best Practices**: 
         - Pre-check file size; avoid using file_processor on files likely exceeding 500KB. 
         - Always validate file paths before calling to prevent "file not found" errors. 
         - Use UTF-8 encoding for text-based formats unless otherwise required.
      
      ## Statistics
      - **Success Rate**: 83.33%
      - **Average Score**: 0.722
      - **Average Time Cost**: 7.058s
      - **Average Token Cost**: 173.6
      
      [4] Retrieving tool memories...
      
      [RETRIEVE] web_search
      ✓ Retrieved 1 memories
      
      Tool: web_search
      Calls: 30
      ------------------------------------------------------------
      1. **Core Function**: The web_search tool retrieves authoritative technical documentation, tutorials, and best practices for specific developer-focused queries (e.g., "GraphQL advantages", "OAuth2 flow"). Use it when seeking reliable, in-depth technical information.
      
      2. **Success Patterns**: High-quality results occur with precise, domain-specific queries (e.g., "JWT authentication", "MongoDB schema design") combined with valid parameters like language="en" and filter="technical_docs". These consistently yield 14–19 relevant, authoritative sources.
      
      3. **Common Issues**: Queries fail or return minimal results when: (a) the query is overly generic (e.g., "test query 1"), (b) an unsupported language (e.g., "unknown") is specified, or (c) the request times out (10s cap). Nonsensical queries correctly return zero results but are handled gracefully.
      
      4. **Best Practices**: 
         - Always use specific, technical keywords that reflect real developer tasks or concepts.
         - Validate language parameters (use "en" or other supported codes) and avoid placeholder or invalid values.
      
      ## Statistics
      - **Success Rate**: 75.00%
      - **Average Score**: 0.350
      - **Average Time Cost**: 4.300s
      - **Average Token Cost**: 96.0
      
      ✓ Saved to tool_memory.json
      
      [RETRIEVE] database_query
      ✓ Retrieved 1 memories
      
      Tool: database_query
      Calls: 22
      ------------------------------------------------------------
      1. **Core Function**: Executes SQL-like queries on specified tables, returning matching rows up to a user-defined limit. Use when retrieving filtered, ordered, or pattern-matched data from known tables.
      
      2. **Success Patterns**: Queries succeed when using valid table/column names, clear WHERE conditions (e.g., id > N), and reasonable limits. Results are reliable when row counts respect the limit or truthfully reflect available data (even if fewer rows exist).
      
      3. **Common Issues**: Frequent failures occur when: (a) returned rows exceed the specified limit—indicating improper limit enforcement; (b) invalid table/column names cause errors; or (c) results omit actual data rows, returning only metadata.
      
      4. **Best Practices**: 
         - Always verify table and column names match the schema to avoid execution errors. 
         - Treat returned row counts skeptically if they exceed your limit—reformulate or validate the query.
         - For large datasets with LIKE or sorting, expect performance notes; consider indexing suggestions provided in successful responses.
      
      ## Statistics
      - **Success Rate**: 80.00%
      - **Average Score**: 0.650
      - **Average Time Cost**: 2.157s
      - **Average Token Cost**: 55.8
      
      ✓ Saved to tool_memory.json
      
      [RETRIEVE] file_processor
      ✓ Retrieved 1 memories
      
      Tool: file_processor
      Calls: 18
      ------------------------------------------------------------
      1. **Core Function**: The file_processor reads structured and unstructured files (CSV, JSON, XML, TXT, PDF) and returns metadata—file size and record count—without exposing raw content. Use it to quickly assess file contents before deeper processing.
      
      2. **Success Patterns**: Works reliably on files under ~500KB across all supported formats when valid paths and encodings (e.g., UTF-8) are provided. Consistently returns useful metadata for small-to-medium files in under 3 seconds.
      
      3. **Common Issues**: Fails silently on large files (>500KB–1MB), returning only a size warning without metadata or content—despite marking the call as "successful." Also fails if the file path is invalid, though it correctly reports this error.
      
      4. **Best Practices**: 
         - Pre-check file size; avoid using file_processor on files likely exceeding 500KB. 
         - Always validate file paths before calling to prevent "file not found" errors. 
         - Use UTF-8 encoding for text-based formats unless otherwise required.
      
      ## Statistics
      - **Success Rate**: 83.33%
      - **Average Score**: 0.722
      - **Average Time Cost**: 7.058s
      - **Average Token Cost**: 173.6
      
      ✓ Saved to tool_memory.json
      
      [5] Testing memory persistence...
      ✓ Memory dumped to ./
      ✓ Memory loaded from ./
      
      ============================================================
      DEMO COMPLETE ✓
      ============================================================

発展的な実践:AppWorld 比較実験 (オプション)

ReMe の cookbook フォルダには、AppWorld などのベンチマークに基づいた比較実験が含まれています。この実験では、メモリ拡張によってエージェントのパフォーマンスがどのように向上するかを測定します。

警告

この実験は実行に時間がかかり、多くのモデルサービスのトークンを消費します。必要な場合にのみ、この実験を実行してください。

  • ステップ 1:実験環境の準備

    # conda 環境を作成
    conda create -p ./appworld-env python==3.12
    conda activate ./appworld-env
    
    # 依存関係をインストール
    pip install -r requirements.txt
    
    # AppWorld をインストールし、データセットをダウンロード
    pip install appworld
    appworld install
    appworld download data
  • ステップ 2:メモリライブラリのロード

    curl -X POST "http://0.0.0.0:8002/vector_store" \
      -H "Content-Type: application/json" \
      -d '{
        "workspace_id": "appworld",
        "action": "load",
        "path": "./docs/library"
      }'
    
  • ステップ 3:実験スクリプトの実行

    python run_appworld.py

    このスクリプトは、開発者データセットで AppWorld タスクを実行します。ReMe メモリを使用するモード (use_memory=True) とメモリを使用しないモードの 2 つのモードで、エージェントのパフォーマンスを比較します。

    主な設定パラメーター:

    パラメーター

    説明

    デフォルト値

    max_workers

    パラレルワーカースレッドの数

    6

    num_runs

    各タスクの繰り返し回数

    4

    use_memory

    ReMe メモリライブラリを有効にするかどうかを指定します

    -

  • ステップ 4:実験結果の分析

    python run_exp_statistic.py

    実験メトリック:

    メトリック

    説明

    best@1

    1 回の実行の平均パフォーマンス

    best@k

    k 回の実行における最高のパフォーマンスの平均。k の値が大きいほど、潜在的なパフォーマンスが高いことを示します。

    実験結果ファイルは ./exp_result/ フォルダに保存されます。結果のまとめは experiment_summary.csv ファイルに出力されます。