Skip to main content
Glama

session-migrator

English | 中文

크로스 에이전트 세션 마이그레이션 레이어: 대상 모델의 컨텍스트 윈도우 용량에 따라 대화를 자동으로 마이그레이션하거나 압축합니다.

해결하는 문제

Agent 1이 진행 중인 대화를 Agent 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_window, list_known_models, migrate_session을 호출할 수 있습니다.

4. LLM API 구성 ("주제 요약"에만 필요)

Codex 세션을 구조화된 메모리로 압축하려면 OpenAI 호환 LLM이 필요합니다. deepseek / OpenAI 등 /chat/completions를 지원하는 모든 서비스에서 동작합니다. 환경 변수만 설정하면 됩니다:

export DEEPSEEK_API_KEY="sk-xxx"          # or OPENAI_API_KEY

세 가지 핵심 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)

판단 기준은 "대상 용량이 세션의 실제 토큰 수를 수용할 수 있는가"입니다. 두 모델의 용량을 단순 비교하는 것이 아닙니다 — 대상 용량이 소스 모델보다 작더라도, 세션이 작다면 그대로 마이그레이션됩니다.

압축기 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