mcpField
C
context-compactor

context-compactor

github.com/adaptationioエージェントワークフロー40 回インストール
リポジトリ

context-compactor について

context-compactorは、トークン上限が近づいた際に会話コンテキストを圧縮するPythonコンポーネントです。古い出力や重複メッセージを除き、設計判断、未解決の問題、現在の状態を優先して保持します。

主な機能

  1. 01コンテキスト圧縮の必要性を確認
  2. 02メッセージの重要度を評価
  3. 03重要な判断、問題、状態を保持
  4. 04内容を要約し古い情報を削除
  5. 05トークン使用量を推定

活用シーン

  1. 01トークン上限が近いときにコンテキストを縮小
  2. 02セッション引き継ぎ用の簡潔な状態を準備
  3. 03長いセッションで重要なプロジェクト情報を維持

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/adaptationio/skrillz --skill context-compactor

インストール後、Claude Code で/context-compactorを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

references/
COMPACTION-STRATEGY.md
scripts/
compactor.py
importance_scorer.py
summarizer.py
token_estimator.py

詳細

コンテキストコンパクター

トークン上限に近づくと、重要な情報を保持しながらコンテキストを自動的に要約・圧縮します。

クイックスタート

圧縮が必要かどうかを確認
from scripts.compactor import ContextCompactor

compactor = ContextCompactor()
if compactor.should_compact(context, limit=100000):
    compacted = compactor.compact(context)
コンテキストを圧縮
compacted = compactor.compact(context)
# Preserves: architectural decisions, bugs, current state
# Discards: stale tool outputs, redundant messages

保持戦略

┌─────────────────────────────────────────────────────────────┐
│                  PRESERVATION PRIORITY                       │
├─────────────────────────────────────────────────────────────┤
│                                                              │
│  MUST PRESERVE (Never remove)                               │
│  ├─ Architectural decisions                                 │
│  ├─ Unresolved bugs and blockers                           │
│  ├─ Current feature state                                   │
│  ├─ Recent file changes (last 5)                           │
│  └─ Error patterns and solutions                           │
│                                                              │
│  CAN SUMMARIZE (Compress to summary)                        │
│  ├─ Completed features (list of IDs)                       │
│  ├─ Resolved errors (brief mention)                        │
│  └─ Historical decisions (key points)                      │
│                                                              │
│  CAN DISCARD (Remove entirely)                              │
│  ├─ Redundant tool outputs                                 │
│  ├─ Stale search results                                   │
│  ├─ Superseded messages                                    │
│  └─ Verbose logging                                         │
│                                                              │
└─────────────────────────────────────────────────────────────┘

圧縮プロセス

  1. 重要度を評価:各メッセージ/コンテンツにスコアを割り当てます
  2. 重要な情報を特定:必ず保持するコンテンツに印を付けます
  3. 中間部分を要約:要約可能なコンテンツを圧縮します
  4. 古い情報を破棄:破棄可能なコンテンツを削除します
  5. 検証:圧縮後のコンテキストに一貫性があることを確認します

トークン予算

コンテキストの種類上限対応
< 50%通常対応不要
50-75%警告圧縮の準備
75-90%圧縮圧縮を実行
> 90%重大積極的に圧縮

統合ポイント

  • autonomous-session-manager:圧縮チェックを実行します
  • memory-manager:圧縮済みの要約を保存します
  • handoff-coordinator:引き継ぎに圧縮済みの状態を使用します

参考資料

  • references/COMPACTION-STRATEGY.md - 詳細な戦略
  • references/TOKEN-BUDGETS.md - 予算管理

スクリプト

  • scripts/compactor.py - ContextCompactor のコア機能
  • scripts/importance_scorer.py - メッセージのスコアリング
  • scripts/summarizer.py - コンテンツの要約
  • scripts/token_estimator.py - トークン数のカウント

コメント