Consolidate agent harness course into 19 lessons

This commit is contained in:
Haoran
2026-08-04 02:25:40 +08:00
parent 2ad77cee19
commit b36dbcd84f
168 changed files with 6544 additions and 10400 deletions

View File

@@ -22,77 +22,77 @@
<!-- タイトルバー -->
<rect x="0" y="0" width="760" height="44" fill="url(#header)" rx="8"/>
<rect x="0" y="36" width="760" height="8" fill="url(#header)"/>
<text x="380" y="28" fill="#fff" font-size="14" font-weight="700" text-anchor="middle">コンテキスト圧縮 — 前処理パイプライン + 自動圧縮 + 緊急フォールバック</text>
<text x="380" y="28" fill="#fff" font-size="14" font-weight="700" text-anchor="middle">コンテキスト圧縮4 ステップと API エラー後の回復</text>
<!-- 設計原則(左側) -->
<rect x="20" y="62" width="220" height="80" rx="6" fill="#f8fafc" stroke="#cbd5e1" stroke-width="1"/>
<text x="130" y="82" fill="#1e3a5f" font-size="12" font-weight="700" text-anchor="middle">設計原則</text>
<text x="130" y="100" fill="#475569" font-size="10" text-anchor="middle">安価な処理を先に、高価な処理を後に</text>
<text x="130" y="116" fill="#475569" font-size="10" text-anchor="middle">テキスト修正 → メッセージ削除の順</text>
<text x="130" y="132" fill="#475569" font-size="10" text-anchor="middle">メッセージ削除 → LLM 呼び出しの順</text>
<text x="130" y="100" fill="#475569" font-size="10" text-anchor="middle">低コストな処理を先に実行</text>
<text x="130" y="116" fill="#475569" font-size="10" text-anchor="middle">再取得できる情報を保持</text>
<text x="130" y="132" fill="#475569" font-size="10" text-anchor="middle">上限超過時だけ履歴を要約</text>
<!-- コスト増加(右側) -->
<rect x="530" y="62" width="210" height="80" rx="6" fill="#f8fafc" stroke="#cbd5e1" stroke-width="1"/>
<text x="635" y="82" fill="#1e3a5f" font-size="12" font-weight="700" text-anchor="middle">コスト増加</text>
<text x="635" y="104" fill="#475569" font-size="10" text-anchor="middle">テキスト操作 → LLM 要約 → 緊急トリム</text>
<text x="635" y="124" fill="#94a3b8" font-size="9" text-anchor="middle">0 API · 0 API · 0 API · 1 API · 1 API</text>
<text x="635" y="104" fill="#475569" font-size="10" text-anchor="middle">構造整理 → 履歴要約 → エラー回復</text>
<text x="635" y="124" fill="#94a3b8" font-size="9" text-anchor="middle">0 API × 3 · 1 API · 最大 1 API 追加</text>
<!-- ===== 前処理パイプラインタイトル ===== -->
<rect x="20" y="146" width="720" height="24" rx="4" fill="#f1f5f9"/>
<text x="55" y="163" fill="#64748b" font-size="11" font-weight="600">前処理パイプライン実行順L3 → L1 → L2、各 LLM 呼び出し前に自動実行、0 API</text>
<text x="55" y="163" fill="#64748b" font-size="11" font-weight="600">前処理Step 1 → Step 2 → Step 3、各 LLM 呼び出し前、0 API</text>
<!-- L3: toolResultBudget -->
<!-- Step 1: tool_result_budget -->
<rect x="80" y="180" width="600" height="46" rx="7" fill="url(#pre)" stroke="#2563eb" stroke-width="1.5"/>
<text x="100" y="200" fill="#1e40af" font-size="12" font-weight="600">L3</text>
<text x="135" y="200" fill="#1e40af" font-size="13" font-weight="700">toolResultBudget</text>
<text x="260" y="200" fill="#1e40af" font-size="11">tool_result 合計 &gt; 200KB → 最大項目を退避</text>
<text x="100" y="200" fill="#1e40af" font-size="12" font-weight="600">Step 1</text>
<text x="155" y="200" fill="#1e40af" font-size="13" font-weight="700">tool_result_budget</text>
<text x="315" y="200" fill="#1e40af" font-size="11">合計 &gt; 200,000 文字 → 最大項目を保存</text>
<text x="650" y="200" fill="#1e40af" font-size="10" text-anchor="end">完全内容を保持</text>
<text x="135" y="218" fill="#2563eb" font-size="9">トリガー:毎ターン、microCompact が完全内容を置換する前に実行</text>
<text x="155" y="218" fill="#2563eb" font-size="9">毎ターン実行し、micro_compact より先に内容を保存</text>
<!-- 矢印 L3→L1 -->
<!-- Step 1 to Step 2 -->
<line x1="380" y1="226" x2="380" y2="238" stroke="#94a3b8" stroke-width="1" marker-end="url(#arrow-d)"/>
<!-- L1: snipCompact -->
<!-- Step 2: snip_compact -->
<rect x="80" y="240" width="600" height="46" rx="7" fill="url(#pre)" stroke="#2563eb" stroke-width="1.5"/>
<text x="100" y="260" fill="#1e40af" font-size="12" font-weight="600">L1</text>
<text x="135" y="260" fill="#1e40af" font-size="13" font-weight="700">snipCompact</text>
<text x="100" y="260" fill="#1e40af" font-size="12" font-weight="600">Step 2</text>
<text x="155" y="260" fill="#1e40af" font-size="13" font-weight="700">snip_compact</text>
<text x="260" y="260" fill="#1e40af" font-size="11">メッセージ &gt; 50 → 中間をトリム</text>
<text x="650" y="260" fill="#1e40af" font-size="10" text-anchor="end">先頭/末尾保持</text>
<text x="135" y="278" fill="#2563eb" font-size="9">トリガー:メッセージ数が閾値を超過</text>
<text x="155" y="278" fill="#2563eb" font-size="9">50 件を超えたら中間を省略し、ツールの組を保持</text>
<!-- 矢印 L1→L2 -->
<!-- Step 2 to Step 3 -->
<line x1="380" y1="286" x2="380" y2="298" stroke="#94a3b8" stroke-width="1" marker-end="url(#arrow-d)"/>
<!-- L2: microCompact -->
<!-- Step 3: micro_compact -->
<rect x="80" y="300" width="600" height="46" rx="7" fill="url(#pre)" stroke="#2563eb" stroke-width="1.5"/>
<text x="100" y="320" fill="#1e40af" font-size="12" font-weight="600">L2</text>
<text x="135" y="320" fill="#1e40af" font-size="13" font-weight="700">microCompact</text>
<text x="100" y="320" fill="#1e40af" font-size="12" font-weight="600">Step 3</text>
<text x="155" y="320" fill="#1e40af" font-size="13" font-weight="700">micro_compact</text>
<text x="260" y="320" fill="#1e40af" font-size="11">古い tool_result → プレースホルダー(最新 3 件保持)</text>
<text x="650" y="320" fill="#1e40af" font-size="10" text-anchor="end">旧結果を圧縮</text>
<text x="135" y="338" fill="#2563eb" font-size="9">トリガー:毎ターン、古い結果をテキストプレースホルダーに置換</text>
<text x="155" y="338" fill="#2563eb" font-size="9">毎ターン実行し、最新 3 件は完全に保持</text>
<!-- ===== 自動圧縮タイトル ===== -->
<rect x="20" y="358" width="720" height="24" rx="4" fill="#f1f5f9"/>
<text x="70" y="375" fill="#64748b" font-size="11" font-weight="600">自動圧縮判定前処理で不足時にトリガー、1 API 呼び出し)</text>
<!-- L4: autoCompact -->
<!-- Step 4: compact_history -->
<rect x="80" y="390" width="600" height="58" rx="7" fill="url(#auto)" stroke="#dc2626" stroke-width="2"/>
<text x="100" y="412" fill="#991b1b" font-size="12" font-weight="600">L4</text>
<text x="135" y="412" fill="#991b1b" font-size="13" font-weight="700">autoCompact</text>
<text x="260" y="412" fill="#991b1b" font-size="11">トークンが閾値超過 → LLM 全量要約</text>
<text x="100" y="412" fill="#991b1b" font-size="12" font-weight="600">Step 4</text>
<text x="155" y="412" fill="#991b1b" font-size="13" font-weight="700">compact_history</text>
<text x="305" y="412" fill="#991b1b" font-size="11">サイズが 50,000 超 → LLM 要約</text>
<text x="590" y="412" fill="#991b1b" font-size="10" text-anchor="end">1 API 呼び出し</text>
<text x="135" y="428" fill="#dc2626" font-size="9">閾値: contextWindow - maxOutputTokens - 13,000 · sessionMemoryCompact を先に試行、不足時のみ LLM 呼び出し</text>
<text x="135" y="442" fill="#dc2626" font-size="9">サーキットブレーカー:連続 3 回失敗後にリトライ停止</text>
<text x="155" y="428" fill="#dc2626" font-size="9">条件estimate_size(messages) &gt; CONTEXT_LIMIT</text>
<text x="155" y="442" fill="#dc2626" font-size="9">transcript 保存後、現在の履歴を 1 件の要約に置換</text>
<!-- ===== 緊急フォールバックタイトル ===== -->
<rect x="20" y="460" width="720" height="24" rx="4" fill="#f1f5f9"/>
<text x="55" y="477" fill="#64748b" font-size="11" font-weight="600">緊急フォールバックAPI が引き続き prompt_too_long を返す場合にトリガー</text>
<text x="55" y="477" fill="#64748b" font-size="11" font-weight="600">エラー回復API が prompt_too_long を返した場合、最大 1 回</text>
<!-- 緊急: reactiveCompact -->
<!-- Fallback: reactive_compact -->
<rect x="80" y="492" width="600" height="62" rx="7" fill="url(#emergency)" stroke="#c2410c" stroke-width="1.5"/>
<text x="100" y="512" fill="#9a3412" font-size="12" font-weight="600">緊急</text>
<text x="135" y="512" fill="#9a3412" font-size="13" font-weight="700">reactiveCompact</text>
<text x="135" y="528" fill="#9a3412" font-size="10">API が 413 / prompt_too_long を返す → バイト単位でトリム</text>
<text x="135" y="544" fill="#c2410c" font-size="9">最後の 5 件 + 要約を保持、autoCompact より積極的</text>
<text x="100" y="512" fill="#9a3412" font-size="12" font-weight="600">回復</text>
<text x="155" y="512" fill="#9a3412" font-size="13" font-weight="700">reactive_compact</text>
<text x="155" y="528" fill="#9a3412" font-size="10">古い履歴を要約し、最新 5 メッセージを保持</text>
<text x="155" y="544" fill="#c2410c" font-size="9">ツールの組を維持して 1 回だけリトライ</text>
</svg>

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB