-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: add XML tool calling support as provider setting #11973
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?
Changes from all commits
a397886
1ce143a
4269390
c0877f3
8a6d111
116061a
1977f54
fe27805
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -75,10 +75,15 @@ export class AnthropicVertexHandler extends BaseProvider implements SingleComple | |||||||||||||||||||||||||||||||
| // Filter out non-Anthropic blocks (reasoning, thoughtSignature, etc.) before sending to the API | ||||||||||||||||||||||||||||||||
| const sanitizedMessages = filterNonAnthropicBlocks(messages) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const nativeToolParams = { | ||||||||||||||||||||||||||||||||
| tools: convertOpenAIToolsToAnthropic(metadata?.tools ?? []), | ||||||||||||||||||||||||||||||||
| tool_choice: convertOpenAIToolChoiceToAnthropic(metadata?.tool_choice, metadata?.parallelToolCalls), | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| // When useXmlToolCalling is enabled, omit native tool definitions from the API request. | ||||||||||||||||||||||||||||||||
| // The model will rely on XML tool documentation in the system prompt instead, | ||||||||||||||||||||||||||||||||
| // and output tool calls as raw XML text parsed by TagMatcher. | ||||||||||||||||||||||||||||||||
| const nativeToolParams = metadata?.useXmlToolCalling | ||||||||||||||||||||||||||||||||
| ? {} | ||||||||||||||||||||||||||||||||
| : { | ||||||||||||||||||||||||||||||||
| tools: convertOpenAIToolsToAnthropic(metadata?.tools ?? []), | ||||||||||||||||||||||||||||||||
| tool_choice: convertOpenAIToolChoiceToAnthropic(metadata?.tool_choice, metadata?.parallelToolCalls), | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+78
to
+86
|
||||||||||||||||||||||||||||||||
| // When useXmlToolCalling is enabled, omit native tool definitions from the API request. | |
| // The model will rely on XML tool documentation in the system prompt instead, | |
| // and output tool calls as raw XML text parsed by TagMatcher. | |
| const nativeToolParams = metadata?.useXmlToolCalling | |
| ? {} | |
| : { | |
| tools: convertOpenAIToolsToAnthropic(metadata?.tools ?? []), | |
| tool_choice: convertOpenAIToolChoiceToAnthropic(metadata?.tool_choice, metadata?.parallelToolCalls), | |
| } | |
| // Always send native tool definitions to the API request so that tool calling | |
| // continues to work even when XML-based tool documentation is used elsewhere. | |
| const nativeToolParams = { | |
| tools: convertOpenAIToolsToAnthropic(metadata?.tools ?? []), | |
| tool_choice: convertOpenAIToolChoiceToAnthropic(metadata?.tool_choice, metadata?.parallelToolCalls), | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -75,10 +75,15 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa | |||||||||||||||||||||||||||||||||
| betas.push("context-1m-2025-08-07") | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const nativeToolParams = { | ||||||||||||||||||||||||||||||||||
| tools: convertOpenAIToolsToAnthropic(metadata?.tools ?? []), | ||||||||||||||||||||||||||||||||||
| tool_choice: convertOpenAIToolChoiceToAnthropic(metadata?.tool_choice, metadata?.parallelToolCalls), | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| // When useXmlToolCalling is enabled, omit native tool definitions from the API request. | ||||||||||||||||||||||||||||||||||
| // The model will rely on XML tool documentation in the system prompt instead, | ||||||||||||||||||||||||||||||||||
| // and output tool calls as raw XML text parsed by TagMatcher. | ||||||||||||||||||||||||||||||||||
| const nativeToolParams = metadata?.useXmlToolCalling | ||||||||||||||||||||||||||||||||||
| ? {} | ||||||||||||||||||||||||||||||||||
| : { | ||||||||||||||||||||||||||||||||||
| tools: convertOpenAIToolsToAnthropic(metadata?.tools ?? []), | ||||||||||||||||||||||||||||||||||
| tool_choice: convertOpenAIToolChoiceToAnthropic(metadata?.tool_choice, metadata?.parallelToolCalls), | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+78
to
+86
|
||||||||||||||||||||||||||||||||||
| // When useXmlToolCalling is enabled, omit native tool definitions from the API request. | |
| // The model will rely on XML tool documentation in the system prompt instead, | |
| // and output tool calls as raw XML text parsed by TagMatcher. | |
| const nativeToolParams = metadata?.useXmlToolCalling | |
| ? {} | |
| : { | |
| tools: convertOpenAIToolsToAnthropic(metadata?.tools ?? []), | |
| tool_choice: convertOpenAIToolChoiceToAnthropic(metadata?.tool_choice, metadata?.parallelToolCalls), | |
| } | |
| // Always send native tool definitions for Anthropic so that tool_use blocks are produced. | |
| // The useXmlToolCalling flag is currently ignored here because the rest of the codebase | |
| // expects native tool_use events and does not support XML-based tool calling. | |
| const nativeToolParams = { | |
| tools: convertOpenAIToolsToAnthropic(metadata?.tools ?? []), | |
| tool_choice: convertOpenAIToolChoiceToAnthropic(metadata?.tool_choice, metadata?.parallelToolCalls), | |
| } |
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 doc comment claims XML tool calls are parsed by TagMatcher in
presentAssistantMessage(), butpresentAssistantMessagecurrently treats missingtool_use.idas an invalid legacy/XML tool call and rejects it, and tools generally requirenativeArgs. Please update this comment to reflect the actual execution/parsing flow, or add the missing XML parsing implementation and adjust this description accordingly.