Zero-friction builtin memory for CodeRouter — capture, consolidate (Ollama), inject
Project description
coderouter-plugin-memory
毎セッション同じ説明を繰り返す問題、
ルーター層で透過的に直します。
日本語 · English · CodeRouter 本体
v0.4.0: builtin backend を JSONL + Ollama (qwen3:1.7b) ベースに完全再設計。外部依存ゼロ (stdlib only)、
coderouter-memoryCLI で動作確認が即できる。CodeRouterv2.3.0a1+の Plugin SDK と組み合わせて動作。
30 秒で
あなたのエージェント (Claude Code / Cursor / 自作 agent)
│ ← memory のことを知らなくていい
▼
┌─ CodeRouter ──────────────────┐
│ ① pre-request hook │ ─→ facts.jsonl を system prompt に注入
│ ② 通常の routing + L1-L6 ガード │
│ ③ post-response hook │ ─→ buffer.jsonl に応答を追記
└───────────────────────────────┘
│
▼
Local LLM (Ollama / LM Studio / ...)
[作業終了後に 1 コマンド]
coderouter-memory consolidate
→ Ollama (qwen3:1.7b) が buffer を読み、key facts を抽出 → facts.jsonl
→ 次のセッションから自動注入
3 フェーズの仕組み:
| フェーズ | タイミング | 何をするか |
|---|---|---|
| capture | レスポンスごと (自動) | buffer.jsonl に応答テキストを追記 |
| consolidate | 作業終了後 (手動 or cron) | Ollama が buffer → key facts を抽出 → facts.jsonl |
| inject | 次セッションの各リクエスト前 (自動) | facts.jsonl を system prompt の先頭に注入 |
使い方
1. インストール
# CodeRouter 本体 (v2.3.0+ が必要)
uv tool install coderouter-cli
# このプラグイン
pip install coderouter-plugin-memory
# consolidate 用の Ollama モデル (1 回だけ)
ollama pull qwen3:1.7b
2. providers.yaml に追記
plugins:
enabled:
- memory
config:
memory:
# project は省略可 — cwd のハッシュから自動検出
project: myapp
consolidate_model: qwen3:1.7b # お好みの軽量モデルに変更可
inject_token_budget: 2000 # system prompt への注入上限 (tokens)
min_buffer_entries: 3 # consolidate のトリガー件数
3. CodeRouter 起動
coderouter serve --port 8088
# 起動ログに [memory] plugin-loaded が出る
4. 作業後に consolidate
coderouter-memory consolidate
# buffer 5 件 → Ollama で fact 抽出 → facts.jsonl に書き込み
# 次のセッションから自動注入される
CLI リファレンス
# 現在の状態を確認 (動いているかの第一確認)
coderouter-memory status
# facts 一覧を表示
coderouter-memory list
# 手動で固定 fact を追加 (CLAUDE.md 感覚で使える)
coderouter-memory add "FastAPI を使用、asyncio ベース"
# buffer → Ollama → facts.jsonl (--dry-run で内容を確認してから実行)
coderouter-memory consolidate --dry-run
coderouter-memory consolidate
# buffer の内容を確認 (デバッグ用)
coderouter-memory buffer
# buffer を削除
coderouter-memory clear
status の出力例:
project : proj-fd5766aa25d0 ← cwd から自動検出
state_dir : ~/.coderouter/memory/proj-fd5766aa25d0
buffer : 7 entries
facts : 12 entries
manual : 2 lines
model : qwen3:1.7b
ollama : http://localhost:11434
💡 buffer が 7 件あります。consolidate を実行できます:
coderouter-memory consolidate
ストレージ
すべてプレーンテキスト。テキストエディタで直接確認・編集できます。
~/.coderouter/memory/{project}/
buffer.jsonl — capture された生応答 (1行=1エントリ)
facts.jsonl — consolidate 済みの key facts (1行=1 fact)
manual.md — 手動で書く固定メモ
なぜ「wire 層」?
ほとんどの agent memory ツール (agentmemory / mem0) は agent 側で動きます。memory_save / memory_recall を MCP tool や SDK 経由で agent が能動的に呼ぶ設計です。
このプラグインは代わりに wire 層 (agent ↔ LLM backend の中間) に置きます:
| 観点 | agent 側 memory ツール | このプラグイン (wire 層) |
|---|---|---|
| agent 側のコード | MCP client / SDK 呼び出しが必要 | 不要 (CodeRouter を通すだけ) |
| 対応 agent | MCP 対応 agent のみ | Anthropic API を話す全 agent |
| 追加プロセス | memory サーバーの起動が必要 | Ollama だけ (すでに使っているはず) |
| 外部依存 | httpx 等 | stdlib only |
自作 agent から見た価値 (walkthrough)
30 行の自作 agent
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:14b",
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 — すべて CodeRouter の wire 層が裏で処理しています。
動かし方 (2 セッション)
# Session 1
python agent.py "プロジェクトのテーマカラーは indigo です。覚えておいて。"
# → "了解しました。indigo を覚えておきます。"
# 作業終了後
coderouter-memory consolidate
# → Ollama が "テーマカラーは indigo" を fact として抽出
# Session 2 (翌日でも)
python agent.py "プロジェクトのテーマカラーは何でしたっけ?"
# → "indigo です。" ← facts.jsonl が system prompt に自動注入された
ロードマップ
| バージョン | 内容 | 状態 |
|---|---|---|
| v0.1–0.3 | Plugin SDK 統合 / multi-backend (sqlite3・agentmemory・null) / circuit breaker | ✅ shipped |
| v0.4.0 | builtin JSONL + Ollama consolidation に完全再設計 / CLI / stdlib-only | ✅ 現在 |
| v0.5 (予定) | agentmemory backend を optional で復活 (community 要望ベース) | ⏳ |
関連プロジェクト
| プロジェクト | 役割 | このプラグインとの関係 |
|---|---|---|
| CodeRouter | wire 層ルーター本体 | 必須。Plugin SDK の host |
| Ollama | ローカル LLM ランタイム | consolidate フェーズで使用 |
| agentmemory | agent memory MCP server | 将来の optional backend 候補 |
| Hermes Agent | self-improving agent framework | 上位レイヤー、補完関係 |
ライセンス
MIT — LICENSE を参照。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coderouter_plugin_memory-0.4.0.tar.gz.
File metadata
- Download URL: coderouter_plugin_memory-0.4.0.tar.gz
- Upload date:
- Size: 40.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d1d9a0f959b86b33636b36517b347d7551f0a1bef90f609f676cbe59035df3c
|
|
| MD5 |
ee77be6b0110da5d4c55c9ae1cda56dc
|
|
| BLAKE2b-256 |
d6018a5e8c8472bda441a6bb402cb7a91fbe75f72be32c2828ce72b44187e3b6
|
Provenance
The following attestation bundles were made for coderouter_plugin_memory-0.4.0.tar.gz:
Publisher:
release.yml on zephel01/coderouter-plugin-memory
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coderouter_plugin_memory-0.4.0.tar.gz -
Subject digest:
2d1d9a0f959b86b33636b36517b347d7551f0a1bef90f609f676cbe59035df3c - Sigstore transparency entry: 1540082037
- Sigstore integration time:
-
Permalink:
zephel01/coderouter-plugin-memory@76508aba26cb29089b18ddc2fce07cfb1449a180 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/zephel01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@76508aba26cb29089b18ddc2fce07cfb1449a180 -
Trigger Event:
push
-
Statement type:
File details
Details for the file coderouter_plugin_memory-0.4.0-py3-none-any.whl.
File metadata
- Download URL: coderouter_plugin_memory-0.4.0-py3-none-any.whl
- Upload date:
- Size: 23.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6166ba6547343916776f14135fbd845dd732c7258ead62d1d5f5f2e38859cfa5
|
|
| MD5 |
80158155ebb7b07e133c75276e5b82d0
|
|
| BLAKE2b-256 |
56be3529f7944c6fc825b135087659b47c277324a61f9faf3ca285919c7fd2bc
|
Provenance
The following attestation bundles were made for coderouter_plugin_memory-0.4.0-py3-none-any.whl:
Publisher:
release.yml on zephel01/coderouter-plugin-memory
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coderouter_plugin_memory-0.4.0-py3-none-any.whl -
Subject digest:
6166ba6547343916776f14135fbd845dd732c7258ead62d1d5f5f2e38859cfa5 - Sigstore transparency entry: 1540082152
- Sigstore integration time:
-
Permalink:
zephel01/coderouter-plugin-memory@76508aba26cb29089b18ddc2fce07cfb1449a180 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/zephel01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@76508aba26cb29089b18ddc2fce07cfb1449a180 -
Trigger Event:
push
-
Statement type: