docs(tickets): complete anthropic assistant burst bundling
This commit is contained in:
parent
fdb181e825
commit
072c1bfbc7
1
TODO.md
1
TODO.md
|
|
@ -13,7 +13,6 @@
|
|||
- Exchange / Turn / Call セマンティクス整理 → [tickets/exchange-turn-call-semantics.md](tickets/exchange-turn-call-semantics.md)
|
||||
- llm-worker のエラー耐性
|
||||
- ストリーム途中失敗時の継続 → [tickets/llm-worker-stream-continuation.md](tickets/llm-worker-stream-continuation.md)
|
||||
- llm-worker: Anthropic projection で assistant ターン内ブロックを 1 message に束ねる → [tickets/anthropic-assistant-burst-bundling.md](tickets/anthropic-assistant-burst-bundling.md)
|
||||
- ネイティブ GUI クライアント MVP → [tickets/native-gui-mvp.md](tickets/native-gui-mvp.md)
|
||||
- E2E テストハーネス(`tests/e2e/`、opt-in) → [tickets/e2e-harness.md](tickets/e2e-harness.md)
|
||||
- TUI 拡充
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
# Anthropic projection: assistant ターン内ブロックを 1 message に束ねる
|
||||
|
||||
## 背景
|
||||
|
||||
`crates/llm-worker/src/llm_client/scheme/anthropic/request.rs` の `convert_items_to_messages` は、Worker が 1 ターンで生成する `[Reasoning, assistant_message, ToolCall]` の連列を、Anthropic wire 上で **複数の隣接した assistant message** に分割している。
|
||||
|
||||
具体的には:
|
||||
- `Item::Reasoning` を `pending_assistant` に push
|
||||
- 次の `Item::Message { Role::Assistant }` が到来すると `pending_assistant` を flush し、自分自身は別 message として messages に直 push
|
||||
- 続く `Item::ToolCall` は再び `pending_assistant` に積まれ、turn 末で flush され 3 つ目の assistant message に
|
||||
|
||||
結果として 1 turn が `assistant[Thinking] / assistant[text] / assistant[tool_use]` の 3 message に展開される。
|
||||
|
||||
Anthropic Messages API は user/assistant の交互を要求し、同一論理 turn 内の thinking/text/tool_use は **1 つの assistant message の `content` 配列** に並べる仕様。新世代 Claude (Opus 4.5+/Sonnet 4.6+) で thinking signature を round-trip する際、隣接 assistant message に分かれていると signature の文脈が崩れて 400 になる懸念がある(reasoning-history-persist のレビュー指摘)。
|
||||
|
||||
なお、本バグは reasoning-history-persist で導入されたものではなく、`assistant_message` + `tool_call` の組合せで以前から存在していた pre-existing な分割。Reasoning が同じ flush 経路を継承した形。
|
||||
|
||||
## 要件
|
||||
|
||||
- 同一論理ターンに属する `Item::Reasoning` / `Item::Message(Assistant)` / `Item::ToolCall` を、Anthropic wire 上の **1 つの assistant message の `content` 配列** に束ねる
|
||||
- 順序は arrival 順 (= history 順)。Anthropic 仕様の典型は thinking → text → tool_use
|
||||
- user / system role の `Item::Message` や `Item::ToolResult` を境界として assistant burst を区切る
|
||||
- 既存の breakpoint (cache_control) 計算が壊れないこと: 各 item のオリジン index → (msg_idx, part_idx) マッピングは flush_pending 経由で記録されているので、Item::Message(Assistant) も pending を経由するように揃えれば自然に追従する
|
||||
- Single-text 専用の `AnthropicContent::Text` shorthand は assistant burst 内 1 part のみのときに限定して維持するか、簡潔さのために常に `Parts` 形式に統一するかは実装時に判断
|
||||
- 既存テスト群(`completed_turn`, `single_text_message_uses_text_shorthand_without_breakpoint`, `breakpoint_on_tool_result_head` 等)の意図を逸脱しないよう更新
|
||||
|
||||
## スコープ外
|
||||
|
||||
- モデル世代別の thinking keep/strip デフォルト分岐(reasoning-history-persist のフォローアップ候補と同じ扱い)
|
||||
- `clear_thinking_20251015` context-edit
|
||||
- prune.rs の reasoning aware 化
|
||||
|
||||
## レビュー状態
|
||||
|
||||
- `19badfe fix: bundle anthropic assistant bursts` を review 済み。結果は `tickets/anthropic-assistant-burst-bundling.review.md`。
|
||||
- 判断: approve / merge 可。
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
# Review: Anthropic assistant burst bundling
|
||||
|
||||
## 対象
|
||||
|
||||
- Ticket: `tickets/anthropic-assistant-burst-bundling.md`
|
||||
- Branch: `anthropic-assistant-burst-bundling`
|
||||
- Reviewed commit: `19badfe fix: bundle anthropic assistant bursts`
|
||||
|
||||
## 確認内容
|
||||
|
||||
- `Item::Reasoning` / `Item::Message(Role::Assistant)` / `Item::ToolCall` が pending assistant parts に積まれ、user/system message または tool result まで 1 つの Anthropic `assistant` message として flush される。
|
||||
- parts の順序は history arrival 順を維持している。
|
||||
- `Item::ToolResult` は pending assistant を先に flush してから user message の `tool_result` part として扱われ、assistant burst の境界になっている。
|
||||
- user/system message も pending assistant / pending user を flush してから user message として出力され、assistant burst の境界になっている。
|
||||
- breakpoint / `cache_control` の item index → `(msg_idx, part_idx)` mapping は pending parts に origin item index を持たせる既存構造で維持されている。assistant text item も pending 経由になったため、assistant burst 内の text part に marker を付けられる。
|
||||
- user/system の single-text shorthand は breakpoint が無い場合に維持されている。assistant 側は burst flush によって `Parts` に統一されるが、ticket の許容範囲内。
|
||||
- protocol / scope / history persistence / prompt context processing には触れていない。
|
||||
|
||||
## 追加テスト
|
||||
|
||||
- `assistant_burst_bundles_reasoning_text_and_tool_call`
|
||||
- `tool_result_and_user_messages_bound_assistant_bursts`
|
||||
- `assistant_message_breakpoint_maps_to_text_part_inside_burst`
|
||||
|
||||
## 検証
|
||||
|
||||
- `cargo test -p llm-worker` passed
|
||||
- `cargo fmt --check` failed due existing unrelated rustfmt diffs outside this ticket's changed file.
|
||||
- `cargo fmt -p llm-worker --check` failed due existing unrelated rustfmt diffs in other llm-worker files; `crates/llm-worker/src/llm_client/scheme/anthropic/request.rs` was not reported.
|
||||
- `git diff --check` passed.
|
||||
|
||||
## 判断
|
||||
|
||||
Approve.
|
||||
|
||||
Ticket の要件通り、Anthropic wire 上の隣接 assistant message 分割を解消し、thinking / text / tool_use を 1 assistant message の content parts に束ねている。変更は projection とそのテストに限定されており、既存設計を歪める追加抽象や範囲外の reasoning policy 変更は入っていない。
|
||||
Loading…
Reference in New Issue
Block a user