Skip to main content

Wire-level memory plugin for CodeRouter — pluggable backends (builtin / agentmemory / mem0 / null).

Project description

coderouter-plugin-memory

毎セッション同じ説明を繰り返す問題、
ルーター層で透過的に直します。

status version python deps license

日本語 · English · 設計ドキュメント · CodeRouter 本体

現在の状態: スケルトンのみ。最初の機能リリース (0.1.0、builtin sqlite3 backend) は CodeRouter v2.3.0 の Plugin SDK 出荷後。詳細は CHANGELOG設計ドキュメント


30 秒で

あなたのエージェント (Claude Code / Cursor / 自作 agent)
                │  ← memory のことを知らなくていい
                ▼
        ┌─ CodeRouter ──────────────┐
        │  ① pre-request hook        │ ─→ memory backend に検索
        │     append_system_prompt 注入 │
        │  ② 通常の routing + L1-L6 ガード │
        │  ③ post-response hook       │ ─→ memory backend に蓄積
        └────────────────────────────┘
                │
                ▼
            Local LLM (Ollama / LM Studio / ...)

何をしてくれるか:

  • agent が memory ツールを 知らなくても wire 層で会話文脈が引き継がれる
  • backend は 差し替え可能 (sqlite3 内蔵 / agentmemory 推奨 / mem0 / null)
  • agent 側のコードを 1 行も変えない (CodeRouter を経由するだけ)
  • memory が壊れても routing は止まらない (degrade pathway 完備)
  • Claude Code でも自作 agent でも同じ wire 経由なので 同じ memory 体験

なぜ「wire 層」?

ほとんどの agent memory ツール (agentmemory / mem0 / Letta) は agent 側で動きます。memory_save / memory_recall を MCP tool や SDK 経由で agent が能動的に呼ぶ設計です。

これは Claude Code / Cursor のような MCP 対応 agent には便利ですが、自作 agent や MCP 非対応のクライアントは対象外です。

このプラグインは代わりに wire 層 (agent ↔ LLM backend の中間) に置きます:

観点 agent 側 memory ツール (agentmemory 等) このプラグイン (wire 層)
agent 側のコード MCP client / SDK 呼び出しが必要 不要 (CodeRouter を通すだけ)
対応 agent MCP 対応 agent のみ Anthropic API を話す全 agent
Memory engine 自前実装 agentmemory 等を backend として委譲
機能の depth 単独で完結 wire 透過注入のみ (engine は backend 側)

両者は競合せず、組み合わせが理想です: agent が MCP で agentmemory を直接叩きつつ、CodeRouter も wire で透過注入することで、memory tool 利用率に依存せず確実に文脈が引き継がれます。


使い方 (0.1.0 出荷後の予定)

1. インストール

# CodeRouter 本体 (v2.3.0+ が必要)
uv tool install coderouter-cli

# このプラグイン
pip install coderouter-plugin-memory

2. memory backend を起動 (agentmemory を推奨)

# 別ターミナルで
npx -y @agentmemory/agentmemory
# → http://localhost:3111 で待ち受け

3. providers.yaml に追記

plugins:
  enabled:
    - memory                       # ← entry point 名 (パッケージ名ではない)
  config:
    memory:
      backend: agentmemory         # builtin / agentmemory / mem0 / null
      endpoint: http://localhost:3111
      inject_token_budget: 2000    # システムプロンプトに注入する上限
      secret_env: AGENTMEMORY_SECRET  # 認証トークンの環境変数名

4. CodeRouter 起動

coderouter serve --port 8088
# 起動ログに plugin-loaded plugin=memory group=input_filter / observer が出る

これだけ。あなたの agent は CodeRouter を経由する設定にするだけで、自動的に前回セッションの文脈が引き継がれます。


バックエンド一覧

Backend リリース予定 こういう人向け
builtin 0.1.0 (P2) 余計なサービスを増やしたくない。sqlite3 + LIKE 検索の最小機能。お試しに。
agentmemory 0.2.0 (P3) 推奨。LongMemEval-S R@5 95.2%、4 層 consolidation、token 92% 削減 (公称)。npx で起動。
null 0.3.0 (P4) 明示的に memory を切る、または backend が落ちたときの自動 fallback 先。
mem0 0.4.0+ (P5、任意) すでに mem0 を使っているユーザー。

すべての backend は同じ MemoryBackend プロトコルを実装するので、providers.yamlbackend: を書き換えるだけで切り替えられます。


進捗

Phase 内容 状態
P0 agentmemory smoke 検証 (実 endpoint の response shape 確認) ⏳ 手動実施 (scripts/smoke_agentmemory.sh)
P1 CodeRouter 本体に Plugin SDK を追加 (coderouter.plugins) ✅ 実装済 (CodeRouter unreleased)
P2 0.1.0: builtin backend / project_id / Inject / Record + tests ✅ 実装済
P3 0.2.0: agentmemory backend + integration tests + smoke script ✅ 実装済
P4 0.3.0: 回路ブレーカー (連続失敗で degrade) + 自作 agent walkthrough + examples ✅ 実装済
P5 0.4.0+: mem0 backend (任意、要望ベース) ⏳ 任意

詳細な実装計画: v2.3-plugin-memory-plan.md


自作 agent から見た価値 (walkthrough)

このプラグインの本領は「自作 agent がコードを書かずに memory を得られる」点にあります。

30 行の自作 agent (examples/walkthrough_agent.py 抜粋)

import sys, os
from openai import OpenAI

client = OpenAI(
    base_url=os.environ.get("CODEROUTER_BASE_URL", "http://localhost:8088/v1"),
    api_key=os.environ.get("OPENAI_API_KEY", "dummy"),
)

resp = client.chat.completions.create(
    model="qwen3.6:35b-a3b",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": " ".join(sys.argv[1:])},
    ],
)
print(resp.choices[0].message.content)

書かれていないもの:

  • memory_save / memory_recall の呼び出し
  • MCP client のセットアップ
  • sqlite / vector store / Redis の import
  • レート制限・fallback chain・drift detection

すべて CodeRouter の wire 層が裏で処理しています。

動かし方 (2 セッション)

# Terminal 1: 必要なら agentmemory を起動
npx -y @agentmemory/agentmemory   # builtin backend を使うなら不要

# Terminal 2: CodeRouter を起動
coderouter serve --port 8088

# Terminal 3: agent を 2 回実行
python examples/walkthrough_agent.py "プロジェクトのテーマカラーは indigo です。覚えておいて。"
# → "了解しました。indigo を覚えておきます。"

python examples/walkthrough_agent.py "プロジェクトのテーマカラーは何でしたっけ?"
# → "indigo です。"   ← 前回の文脈が透過的に注入されている

agent コードには「過去のセッション」を取り出すロジックは 1 行もない。それでも 2 回目の応答が 1 回目を覚えているのは、wire 層の plugin が <previous-session-context> を system prompt に prepend しているから。

サンプル設定 / 完全なコードは examples/ を参照。

Build less in your agent, get more from the wire


関連プロジェクト

プロジェクト 役割 このプラグインとの関係
CodeRouter wire 層ルーター本体 必須。Plugin SDK の host
agentmemory agent memory MCP server 推奨 backend。R@5 95.2%
mem0 memory layer API 任意 backend
Hermes Agent self-improving agent framework 上位レイヤー、補完関係
Plugin SDK 設計 CodeRouter 側の plugin 契約 このプラグインが従う仕様

ライセンス

MIT — LICENSE を参照。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coderouter_plugin_memory-0.3.0.tar.gz (50.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coderouter_plugin_memory-0.3.0-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file coderouter_plugin_memory-0.3.0.tar.gz.

File metadata

  • Download URL: coderouter_plugin_memory-0.3.0.tar.gz
  • Upload date:
  • Size: 50.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for coderouter_plugin_memory-0.3.0.tar.gz
Algorithm Hash digest
SHA256 264280244ffbb29d076f3ea45ea4bbac2792e03125f0535158598b8300138e02
MD5 1025e59a878330ae10c8078ea1756a5c
BLAKE2b-256 b78e88757fade0dfde80799f7f189bece54bcb1197a782b0fdad5b3b6fc58a63

See more details on using hashes here.

Provenance

The following attestation bundles were made for coderouter_plugin_memory-0.3.0.tar.gz:

Publisher: release.yml on zephel01/coderouter-plugin-memory

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file coderouter_plugin_memory-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for coderouter_plugin_memory-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c1f67a72dd68364824fd599b477a2c1885f8460fbf87620de880643ef9b613ae
MD5 523d6c1d47ef671c399d44989a5d6201
BLAKE2b-256 2276bedfdf336bedf2c801117166ba97ed52b79fef54af460832508741ca9542

See more details on using hashes here.

Provenance

The following attestation bundles were made for coderouter_plugin_memory-0.3.0-py3-none-any.whl:

Publisher: release.yml on zephel01/coderouter-plugin-memory

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page