Uh oh!
There was an error while loading. Please reload this page.
[FEATURE] Add Anthropic Advanced Tool Use beta support - #7390
[FEATURE] Add Anthropic Advanced Tool Use beta support#7390theslyprofessor wants to merge 1 commit into
Conversation
Adds support for Anthropic's Advanced Tool Use beta features via feature flag. Features enabled by this beta: - Tool Search Tool: On-demand tool discovery (85% token reduction) - Programmatic Tool Calling: Code-based tool orchestration - Tool Use Examples: Example-based learning for better accuracy Usage: export OPENCODE_ADVANCED_TOOL_USE=true opencode When enabled, adds 'advanced-tool-use-2025-11-20' to the anthropic-beta header. When disabled, OpenCode behaves exactly as before. This is the foundation for implementing: 1. defer_loading config for MCP tools 2. Code execution sandbox for tool orchestration 3. input_examples for tool schemas Related: - Issue anomalyco#4713 - Anthropic docs: https://www.anthropic.com/engineering/advanced-tool-use Tested: - Typecheck passes - No breaking changes - Feature flag defaults to off
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
There was a problem hiding this comment.
Pull request overview
This PR adds support for Anthropic's Advanced Tool Use beta features through a feature flag OPENCODE_ADVANCED_TOOL_USE. When enabled, it includes the advanced-tool-use-2025-11-20 beta header in Anthropic API requests, providing foundation for future token reduction features.
Key Changes:
- Adds
OPENCODE_ADVANCED_TOOL_USEenvironment variable support - Refactors hardcoded beta headers into a dynamic array
- Conditionally includes advanced tool use beta based on feature flag
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const CUSTOM_LOADERS: Record<string, CustomLoader> = { | ||
| async anthropic() { | ||
| // Add advanced tool use beta if feature flag is enabled | ||
| const advancedToolUseEnabled = Env.all()["OPENCODE_ADVANCED_TOOL_USE"] === "true" |
There was a problem hiding this comment.
The feature flag should be defined in the Flag namespace (flag/flag.ts) using the truthy() helper function, consistent with other feature flags in the codebase. This approach provides a centralized location for all flags, makes them easier to discover, and follows the established pattern used by flags like OPENCODE_ENABLE_EXPERIMENTAL_MODELS, OPENCODE_DISABLE_CLAUDE_CODE, etc.
| constadvancedToolUseEnabled=Env.all()["OPENCODE_ADVANCED_TOOL_USE"]==="true" | |
| constadvancedToolUseEnabled=Flag.truthy("OPENCODE_ADVANCED_TOOL_USE") |
| "fine-grained-tool-streaming-2025-05-14", | ||
| ] | ||
| // Add advanced tool use beta if enabled |
There was a problem hiding this comment.
This comment is redundant with the comment on line 76. Consider removing one of them to reduce duplication.
| // Add advanced tool use beta if enabled |
f1ae801 to
08fa7f7CompareClosing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Summary
Adds support for Anthropic's Advanced Tool Use beta features via feature flag.
Closes#4713
Motivation
OpenCode currently loads all MCP tool definitions upfront. For power users with multiple MCP servers, this creates high token costs (50K-100K+ tokens before any work begins).
Anthropic released beta features specifically designed to address this:
This PR adds the foundation for these capabilities.
Changes
Beta Header Support
Added
OPENCODE_ADVANCED_TOOL_USEfeature flag that enables theadvanced-tool-use-2025-11-20beta:Usage
export OPENCODE_ADVANCED_TOOL_USE=true opencodeBreaking Changes
None. Feature flag defaults to
false. Without the flag, OpenCode behaves exactly as before.Testing
Next Steps
This PR lays the foundation for:
defer_loadingconfig for MCP toolsinput_examplesin tool schemasI can implement these in follow-up PRs if this approach is approved.
References
Author Notes
I'm a power user running OpenCode with 9+ MCP servers. This feature would save me 50K-70K tokens per session. Happy to implement the full feature set if this foundation is accepted.
Thanks for reviewing! 🚀