Skip to content

feat: Add Anthropic advisor functionality and tests#12095

Draft
TDFSE wants to merge 4 commits intoRooCodeInc:mainfrom
TDFSE:add-anthropic-advisor-tool
Draft

feat: Add Anthropic advisor functionality and tests#12095
TDFSE wants to merge 4 commits intoRooCodeInc:mainfrom
TDFSE:add-anthropic-advisor-tool

Conversation

@TDFSE
Copy link
Copy Markdown

@TDFSE TDFSE commented Apr 10, 2026

Related GitHub Issue

Closes: #12094

Roo Code Task Context (Optional)

Description

Adds UI controls and API-layer support for Anthropic's Advisor Tool (beta advisor-tool-2026-03-01), which allows a Claude executor model to consult Claude Opus 4.6 mid-generation for strategic guidance — within a single /v1/messages request.

How it works:

  • A new supportsAdvisorTool capability flag is added to the ModelInfo Zod schema (packages/types/src/model.ts) and set on the three currently supported executor models: claude-haiku-4-5-20251001, claude-sonnet-4-6, and claude-opus-4-6.
  • Three new optional fields are added to anthropicSchema in packages/types/src/provider-settings.ts: anthropicAdvisorEnabled, anthropicAdvisorModel, and anthropicAdvisorMaxUses. ProviderSettings derives from the Zod schema via z.infer<> — no manual interface edits required.
  • The settings UI (webview-ui/src/components/settings/providers/Anthropic.tsx) renders a new sub-section in the Advanced area, gated by modelInfo?.supportsAdvisorTool. When enabled, a model dropdown (currently claude-opus-4-6 only) and a max uses number input are shown. Uses i18n strings via webview-ui/src/i18n/locales/en/settings.json.
  • The API handler (src/api/providers/anthropic.ts) pushes "advisor-tool-2026-03-01" onto the betas array and appends an advisor_20260301 tool definition to the tools array when anthropicAdvisorEnabled is true. max_uses defaults to 3 and is always included in the tool definition when the feature is enabled; set via anthropicAdvisorMaxUses in settings.

Design choices / reviewer notes:

  • The advisor tool is appended after regular tools in the array. Anthropic's API accepts it in any position; appending is the least disruptive approach.
  • advisor_20260301 is not yet in the official @anthropic-ai/sdk TypeScript types. A type cast (as unknown as Anthropic.Tool) is used to avoid a type error while keeping the runtime object correct.
  • ⚠️ Known gap: advisor_tool_use / advisor_tool_result content blocks that Anthropic inserts into assistant turns will be stripped by filterNonAnthropicBlocks() before the next request, because VALID_ANTHROPIC_BLOCK_TYPES (src/api/transform/anthropic-filter.ts) does not include those types. This PR does not add them to the allowlist. The practical impact depends on whether Anthropic requires those blocks in subsequent turns for correct continuation — reviewers should verify this with the Anthropic API docs before merging.
  • The entire feature is opt-in (disabled by default) and purely additive — no existing behavior changes when anthropicAdvisorEnabled is falsy.

Files changed:

File Change
packages/types/src/model.ts Added supportsAdvisorTool: z.boolean().optional() to modelInfoSchema
packages/types/src/provider-settings.ts Added anthropicAdvisorEnabled, anthropicAdvisorModel, anthropicAdvisorMaxUses to anthropicSchema
packages/types/src/providers/anthropic.ts Set supportsAdvisorTool: true on claude-haiku-4-5-20251001, claude-sonnet-4-6, claude-opus-4-6
src/api/providers/anthropic.ts Injects advisor-tool-2026-03-01 beta header and advisor tool definition when enabled
webview-ui/src/components/settings/providers/Anthropic.tsx Added Advisor Tool section (checkbox, model dropdown, max uses input) in Advanced area
webview-ui/src/i18n/locales/en/settings.json Added 4 i18n keys: anthropicAdvisorToolLabel, anthropicAdvisorModelLabel, anthropicAdvisorMaxUsesLabel, anthropicAdvisorMaxUsesPlaceholder
src/api/providers/__tests__/anthropic.spec.ts Added advisor tool feature describe block with 6 unit tests

Test Procedure

Unit tests covering the API handler are in src/api/providers/__tests__/anthropic.spec.ts under the advisor tool feature describe block. Run verified locally.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Before:
image

After:
image

Documentation Updates

Does this PR necessitate updates to user-facing documentation?

  • No documentation updates are required.
  • Yes, documentation updates are required. (Please describe what needs to be updated or link to a PR in the docs repository).

Additional Notes

  • The Advisor Tool is an Anthropic beta feature (advisor-tool-2026-03-01). The API shape may change before GA. The implementation is intentionally minimal and additive.
  • max_uses defaults to 3 when not configured. This controls the maximum number of advisor consultations per API request, not per Roo-Code task — a long agentic task with many API calls will invoke the advisor up to max_uses times per call.
  • Adding future supported executor models requires only setting supportsAdvisorTool: true in the model info map — no UI changes needed.

Interactively review PR in Roo Code Cloud

@TDFSE
Copy link
Copy Markdown
Author

TDFSE commented Apr 10, 2026

Working on resolving the known gap - want to get the call/result of the advisor to display in chat. Then will add translations/fix failing checks.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. Enhancement New feature or request labels Apr 10, 2026
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 11, 2026
@TDFSE
Copy link
Copy Markdown
Author

TDFSE commented Apr 11, 2026

image Added the responses. It tends to repeat the "Roo says" before/after - working to fix.

@TDFSE TDFSE changed the title Add advisor functionality and tests feat: Add Anthropic advisor functionality and tests Apr 11, 2026
@TDFSE TDFSE marked this pull request as draft April 11, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Add Anthropic Advisor Tool support for Claude executor models

1 participant