-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(anthropic): advanced tool use #10812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(anthropic): advanced tool use #10812
Conversation
…ool_search_tool_regex, tool_search_tool_bm25) + new tool parameters (defer_loading, input_examples, allowed_callers)
|
@lgrammel I'd really appreciate it if you could review this PR. |
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
…ed-tool-use-features
| canCache: true, | ||
| }); | ||
|
|
||
| const advancedToolFeatures = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The strict property from function tools is no longer being passed through to the Anthropic tool definition. This breaks the structured output feature when strict is set on a tool.
View Details
📝 Patch Details
diff --git a/packages/anthropic/src/anthropic-prepare-tools.ts b/packages/anthropic/src/anthropic-prepare-tools.ts
index ddf852bef..d5c8a47f4 100644
--- a/packages/anthropic/src/anthropic-prepare-tools.ts
+++ b/packages/anthropic/src/anthropic-prepare-tools.ts
@@ -68,6 +68,9 @@ export async function prepareTools({
input_schema: tool.inputSchema,
cache_control: cacheControl,
...advancedToolFeatures,
+ ...(supportsStructuredOutput === true && tool.strict != null
+ ? { strict: tool.strict }
+ : {}),
});
break;
}
Analysis
Missing strict property passthrough in Anthropic tool preparation
What fails: The prepareTools() function in packages/anthropic/src/anthropic-prepare-tools.ts does not pass through the strict property from function tools to the Anthropic tool definition, breaking structured output feature when strict is set.
How to reproduce:
cd packages/anthropic
pnpm test:node -- src/anthropic-prepare-tools.test.tsThe test "should include strict when supportsStructuredOutput is true and strict is true" would fail with:
- Expected: "strict": true
+ Received: (property missing)
What was happening: When refactoring to use getAnthropicAdvancedToolUseFeaturesSupport(), the handling of the strict property was removed. The function only extracted defer_loading, allowed_callers, and input_examples from advancedToolFeatures, but never checked tool.strict.
What should happen: When supportsStructuredOutput is true AND tool.strict is defined, the strict property should be included in the output tool definition, matching the pattern used by other providers (Deepseek, Mistral, OpenAI).
Fix applied: Added conditional spread to include strict property:
...(supportsStructuredOutput === true && tool.strict != null
? { strict: tool.strict }
: {}),This matches the established pattern across the codebase and ensures structured output mode works correctly with Anthropic models.
Verification: All 177 tests in the anthropic package now pass, including the 3 strict mode tests in anthropic-prepare-tools.test.ts.
…ed-tool-use-features
|
@ussef083 thanks. i will see if i can get this shipped today. please do not make any more changes to this branch |
|
I prefer to add individual features (tool example, one search tool, the other search tool, etc) as individual pull requests to more thoroughly test and document them. |
|
thank you very much , if there is an task i can do, I'm here. |
| ...(supportsStructuredOutput === true && tool.strict != null | ||
| ? { strict: tool.strict } | ||
| : {}), | ||
| ...advancedToolFeatures, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't this make all tool follow same defer_loading property ? if we gonna go this way then how could we have mix of tools with some being defered and some (could be most used or critical ones) not defered ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no since advancedToolFeatures returns only the properties specified by the user , as example if defer_loading is not specified, so it won't be there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would still be specified in provider options right, and that make it applied to all tools then. I mean how could you have mix of tools with some having defer_loading set to true and some with false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops sorry, providerMetadata is tool property, I missed that, this works then
Background
Anthropic recently introduced new advanced built-in tools and capabilities:
https://www.anthropic.com/engineering/advanced-tool-use
Summary
Manual Verification
Tasks
Future Work
Related Issues