litellm - ✅(Solved) Fix feat(advisor): Anthropic Claude Code /advisor rollout [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#25516Fetched 2026-04-11 06:13:36
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×2cross-referenced ×1

Anthropic's Advisor Strategy is now live in Claude Code (/advisor toggle). It pairs a fast executor model (Sonnet/Haiku) with a high-intelligence advisor (Opus) mid-generation — all inside a single /v1/messages request. LiteLLM currently breaks this when used as a proxy (anthropics/claude-code#46105).

How it works (API level):

  • Request: {"type": "advisor_20260301", "name": "advisor", "model": "claude-opus-4-6"} in tools array + beta header anthropic-beta: advisor-tool-2026-03-01
  • Response: assistant content contains server_tool_use (name: "advisor") + advisor_tool_result blocks
  • Multi-turn: must round-trip these blocks verbatim — omitting them causes a 400

Provider support:

  • Anthropic direct ✅ — runs inside Anthropic infra natively
  • Vertex AI ⚠️ — likely supported, needs verification
  • Bedrock ❌ natively, but LiteLLM will implement the orchestration loop so it works transparently

Error Message

  • Return clear error if Vertex rejects the advisor tool (feature not yet live there)

Root Cause

Anthropic's Advisor Strategy is now live in Claude Code (/advisor toggle). It pairs a fast executor model (Sonnet/Haiku) with a high-intelligence advisor (Opus) mid-generation — all inside a single /v1/messages request. LiteLLM currently breaks this when used as a proxy (anthropics/claude-code#46105).

How it works (API level):

  • Request: {"type": "advisor_20260301", "name": "advisor", "model": "claude-opus-4-6"} in tools array + beta header anthropic-beta: advisor-tool-2026-03-01
  • Response: assistant content contains server_tool_use (name: "advisor") + advisor_tool_result blocks
  • Multi-turn: must round-trip these blocks verbatim — omitting them causes a 400

Provider support:

  • Anthropic direct ✅ — runs inside Anthropic infra natively
  • Vertex AI ⚠️ — likely supported, needs verification
  • Bedrock ❌ natively, but LiteLLM will implement the orchestration loop so it works transparently

Fix Action

Fixed

PR fix notes

PR #25525: feat(anthropic): support advisor_20260301 tool type

Description (problem / solution / changelog)

Relevant issues

Fixes #25516

Pre-Submission checklist

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

CI (LiteLLM team)

  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🆕 New Feature / 🐛 Bug Fix

Changes

Adds support for Anthropic's advisor_20260301 tool. Previously LiteLLM raised a ValueError on unknown tool types and stripped the beta header. This also adds auto-strip of stale advisor_tool_result blocks to prevent 400s on follow-up turns.

Files changed:

  • litellm/types/llms/anthropic.pyAnthropicAdvisorTool TypedDict + ADVISOR_TOOL_2026_03_01 enum value
  • litellm/llms/anthropic/chat/transformation.py — handle advisor_20260301 in _map_tool_helper(); auto-inject beta header; auto-strip advisor blocks when tool is absent
  • litellm/llms/anthropic/experimental_pass_through/messages/transformation.py — same auto-inject + auto-strip for /v1/messages path
  • litellm/llms/anthropic/common_utils.pystrip_advisor_blocks_from_messages() helper
  • litellm/anthropic_beta_headers_config.json — register advisor-tool-2026-03-01 so the beta headers manager forwards it (was silently dropped)
  • docs/my-website/docs/providers/anthropic_advisor_tool.md — new doc page

Auto-strip behavior: When the advisor tool is not in tools, LiteLLM strips server_tool_use(name=advisor) and advisor_tool_result blocks from message history before forwarding. This prevents the Anthropic 400 that happens when a caller removes the advisor tool for cost control but forgets to clean history.

Live test results (both paths, both modes):

/v1/messages non-streaming:

[server_tool_use] name=advisor, id=srvtoolu_016tba5RDoFRrti7ycatWiLV
[advisor_tool_result] tool_use_id=srvtoolu_016tba5RDoFRrti7ycatWiLV
[text] Here is an efficient Python primality check...
usage: 2223 in / 635 out

/v1/messages streaming:

[server_tool_use] name=advisor, id=srvtoolu_01HS2LKg3iGsCL3kRtZLoYbV
[advisor_tool_result] tool_use_id=srvtoolu_01HS2LKg3iGsCL3kRtZLoYbV
[text] Here is an efficient Python function to check if a number is prime...

10 unit tests in tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py.

Changed files

  • docs/my-website/docs/completion/anthropic_advisor_tool.md (added, +422/-0)
  • docs/my-website/sidebars.js (modified, +2/-0)
  • litellm/anthropic_beta_headers_config.json (modified, +6/-0)
  • litellm/llms/anthropic/chat/transformation.py (modified, +58/-21)
  • litellm/llms/anthropic/common_utils.py (modified, +52/-4)
  • litellm/llms/anthropic/experimental_pass_through/messages/transformation.py (modified, +29/-3)
  • litellm/types/llms/anthropic.py (modified, +15/-0)
  • tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py (modified, +204/-2)
RAW_BUFFERClick to expand / collapse

Overview

Anthropic's Advisor Strategy is now live in Claude Code (/advisor toggle). It pairs a fast executor model (Sonnet/Haiku) with a high-intelligence advisor (Opus) mid-generation — all inside a single /v1/messages request. LiteLLM currently breaks this when used as a proxy (anthropics/claude-code#46105).

How it works (API level):

  • Request: {"type": "advisor_20260301", "name": "advisor", "model": "claude-opus-4-6"} in tools array + beta header anthropic-beta: advisor-tool-2026-03-01
  • Response: assistant content contains server_tool_use (name: "advisor") + advisor_tool_result blocks
  • Multi-turn: must round-trip these blocks verbatim — omitting them causes a 400

Provider support:

  • Anthropic direct ✅ — runs inside Anthropic infra natively
  • Vertex AI ⚠️ — likely supported, needs verification
  • Bedrock ❌ natively, but LiteLLM will implement the orchestration loop so it works transparently

P0 — Anthropic direct — ✅ done in #25525

  • Forward anthropic-beta: advisor-tool-2026-03-01 header from client to upstream
  • Pass advisor_20260301 tool type through unchanged — don't strip/reject it
  • Preserve server_tool_use (name: "advisor") in response — don't convert to OpenAI tool_call format
  • Preserve advisor_tool_result in response
  • Round-trip both blocks verbatim in multi-turn history
  • Auto-strip advisor_tool_result from history when advisor tool is absent from tools on a follow-up turn (prevents 400)
  • Add ANTHROPIC_ADVISOR_TOOL_TYPE constant — no more hardcoded strings
  • Doc page: completion/anthropic_advisor_tool.md with examples for both /chat/completions and /messages, streaming, multi-turn, AI gateway, recommended system prompts
  • Parse usage.iterations[] from response and expose it; add iterations field to Usage type
  • Attribute advisor tokens to Opus pricing in spend tracking

P0 — Vertex AI — next PR

  • Verify Vertex accepts anthropic-beta: advisor-tool-2026-03-01 header
  • Confirm Anthropic transformation fixes carry through to Vertex path
  • Test end-to-end with claude-sonnet-4-6 on Vertex endpoint
  • Return clear error if Vertex rejects the advisor tool (feature not yet live there)

P0 — Bedrock Invoke + Converse (LiteLLM implements the loop) — next PR

Bedrock can't run the advisor server-side, but LiteLLM will implement the orchestration so the user-facing API is identical.

  • Detect advisor_20260301 tool in request routed to Bedrock
  • Strip advisor tool from outgoing Bedrock request
  • When executor responds with advisor tool_call → intercept; run separate LiteLLM completion to the advisor model with full conversation transcript
  • Inject advisor response as synthetic advisor_tool_result block → resume executor loop
  • Streaming: pause stream → emit server_tool_use + advisor_tool_result blocks → resume
  • Multi-turn: strip synthetic advisor blocks from history before sending to Bedrock; re-inject as text context
  • Track advisor sub-call tokens under advisor model pricing; populate synthetic usage.iterations[]
  • Don't crash on server_tool_use / advisor_tool_result in input history during Bedrock message transformation

P1 — usage.iterations[] — next PR

  • Parse usage.iterations[] from Anthropic response
  • Add iterations field to Usage type so callers can see per-iteration token counts and identify advisor sub-inferences

P1 — Internal advisor for all other non-native providers

  • Reuse Bedrock orchestration as a provider-agnostic layer (OpenAI, Groq, Mistral, etc.)
  • Expose advisor_max_uses config to cap calls per request

P1 — Advisor system prompt injection (optional proxy helper)

Automatically inject Anthropic's recommended timing/weight prompts when advisor tool is present.

  • Timing block: call advisor BEFORE substantive work; orientation (reading files) is fine first
  • Advice weight block: give advice serious weight; surface conflicts in follow-up advisor call
  • Optional conciseness instruction (~35–45% token reduction)
  • advisor_conversation_max_uses config: auto-remove advisor tool + strip history blocks when cap reached

Related

extent analysis

TL;DR

To fix the issue with LiteLLM breaking Anthropic's Advisor Strategy, implement the necessary changes for each provider, including forwarding the anthropic-beta header, preserving specific blocks in responses, and handling multi-turn requests.

Guidance

  • For Anthropic direct, ensure that the anthropic-beta: advisor-tool-2026-03-01 header is forwarded from the client to upstream and that advisor_20260301 tool type is passed through unchanged.
  • For Vertex AI, verify that it accepts the anthropic-beta header and test end-to-end with the claude-sonnet-4-6 model.
  • For Bedrock, implement the orchestration loop to handle the advisor tool, including detecting the tool, stripping it from outgoing requests, and injecting advisor responses as synthetic blocks.
  • Parse usage.iterations[] from Anthropic responses and add an iterations field to the Usage type to track advisor sub-call tokens.

Example

No code snippet is provided as the issue description does not include specific code examples that can be used to illustrate the fix.

Notes

The fix involves multiple steps and requires careful handling of different providers and request types. It is essential to test each provider thoroughly to ensure that the advisor tool works as expected.

Recommendation

Apply the workaround by implementing the necessary changes for each provider, as described in the guidance section. This approach allows for a more controlled rollout and testing of the advisor tool with different providers.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING