Skip to main content
Glama

session-migrator

English | 中文

クロスエージェントセッション記憶移行レイヤー:ターゲットモデルのコンテキストウィンドウ容量に基づいて、会話を自動的に移行または圧縮します。

解決する問題

エージェント1で進行中の会話をエージェント2に引き継ぐ必要があるが、2つのエージェントは異なるコンテキストウィンドウを持つ異なるモデルを使用しています。ルールはシンプルです:

  • ターゲットモデルが会話全体を収まる場合 → そのまま移行、圧縮なし;

  • 収まらない場合 → 最も価値のあるコンテキストのみを保持(最新メッセージ優先)。

Related MCP server: OpenAI Assistant MCP Server

ディレクトリ構造

session-migrator/
├── session_migrator/
│   ├── context_windows.py   # model capacity mapping table (the soul)
│   ├── exporter.py          # session export/serialization + token estimation
│   ├── decision.py          # decision engine: compare capacity → direct/compress
│   ├── compressors.py       # compressor: budget truncation, keeps latest
│   ├── storage.py           # shared storage: JSON files, per-workspace isolation
│   ├── codex_adapter.py     # Codex session → Session adapter
│   ├── llm_summarizer.py    # LLM topic summarization (deepseek/OpenAI-compatible)
│   ├── server.py            # MCP server entry (exposes migration tools)
│   └── __init__.py
├── examples/
│   ├── demo.py                     # full demo, zero dependencies
│   ├── codex_to_workbuddy_demo.py  # Codex → memory (truncation)
│   └── llm_summarize_demo.py       # Codex → memory (LLM topic summarization)
├── tests/test_core.py       # core logic tests
├── pyproject.toml
├── requirements.txt
└── LICENSE

クイックスタート

1. まずコアロジックを実行(依存関係ゼロ)

python examples/demo.py
python tests/test_core.py

どちらも標準ライブラリのみを使用します。インストール不要 — 「決定+圧縮+保存」がエンドツーエンドで動作するのをすぐに確認できます。

2. MCPサーバーとして実行

pip install mcp
python -m session_migrator.server

3. 任意のMCPクライアントに接続

例としてClaude Codeを使用する場合、これをプロジェクトの.mcp.json(またはグローバル設定)に追加します:

{
  "mcpServers": {
    "session-migrator": {
      "command": "python",
      "args": ["-m", "session_migrator.server"]
    }
  }
}

Cursor / Codex / WorkBuddy、またはMCP stdioをサポートする任意のクライアントでも同様に動作します。接続後、エージェントはmodel_context_windowlist_known_modelsmigrate_sessionを呼び出すことができます。

4. LLM APIを設定(「トピック要約」にのみ必要)

Codexセッションを構造化メモリに圧縮するには、OpenAI互換のLLMが必要です。deepseek / OpenAI、または/chat/completionsと互換性のある任意のサービスで動作します — 環境変数を設定するだけです:

export DEEPSEEK_API_KEY="sk-xxx"          # or OPENAI_API_KEY

3つのコアMCPツールには不要です(決定/切り詰め圧縮のみを行い、LLM呼び出しはありません)。

MCPツール

ツール

目的

model_context_window(model)

モデルのコンテキストウィンドウ容量を照会

list_known_models()

組み込みモデルとその容量を一覧表示

migrate_session(messages_json, source_model, target_model, ...)

移行を実行、決定+移行済みメッセージ+トークン前後を返す

migrate_sessionmessages_jsonは次のようになります:

[{"role": "user", "content": "..."}, {"role": "assistant", "content": "..."}]

コアコンセプト

決定エンジン decide(session, target_model)

基準は「ターゲット容量がセッションの実際のトークン数を収容できるか」であり、単に2つのモデルの容量を比較するのではありません — ターゲット容量がソースモデルより小さくても、小さなセッションはそのまま移行されます。

コンプレッサー TruncationCompressor

デフォルト実装は外部依存ゼロ:最新から遡ってメッセージ全体を保持し、収まらない以前のメッセージは省略し、先頭にプレースホルダーノート(省略数+最古メッセージのプレビュー)を挿入します。

トピック要約(Codex → メモリ)

Codexセッションを構造化メモリに移行するための完全なパイプライン(アダプター+LLM):

from session_migrator.codex_adapter import get_thread_meta, extract_rollout
from session_migrator.llm_summarizer import summarize_session

meta = get_thread_meta("your-codex-thread-id")
session = extract_rollout(meta["rollout_path"], meta["id"], meta["model"])
markdown = summarize_session(session, meta, target_chars=5000)  # needs LLM key set first

LLMを使用しない切り詰め版:codex_adapter.to_memory_markdown(session, meta)

モデル容量テーブル

session_migrator/context_windows.pyには静的マッピングテーブル(OpenAI / Anthropic / Google / 中国モデル)が同梱されています。注意:これらは静的フォールバック値であり、プロバイダーの更新に応じて変更される可能性があります。

ロードマップ

  • LLMトピック要約(llm_summarizer.py、「トピック要約」を参照)

  • 動的容量取得(各プロバイダーの/models APIを呼び出し)

  • ヘッドルーム可逆圧縮(元のテキストを復元可能)

  • ベクターストア検索インジェクション(オンデマンド検索)

  • tiktokenによる正確なトークンカウント

ライセンス

MIT

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    Not graded
    quality
    Not graded
    maintenance
    Enables Claude and other MCP-compatible tools to communicate with OpenAI's GPT models (GPT-5, GPT-5-mini, o3) with conversation history and session management. Features advanced controls like reasoning effort settings, token tracking, and parallel conversation sessions for efficient AI workflows.
    9
  • A
    license
    Not graded
    quality
    C
    maintenance
    Provides context compression via the tokenslim engine, enabling MCP hosts to reduce token usage while preserving key information. Offers compress, retrieve, and stats tools for managing compressed content.
    Apache 2.0

View all related MCP servers

Related MCP Connectors

  • Hosted MCP server for LLM cost estimation, model comparison, and budget-aware routing.

  • Free OpenAI-compatible inference with signed provenance receipts and 3 focused MCP tools.

  • Remote MCP for Gemini upgrade evals, prompt regressions, output diffs, and eval receipts.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/liangyuan0219/session-migrator'

If you have feedback or need assistance with the MCP directory API, please join our Discord server