feat: support Anthropic web search (server_tool_use) translation#241
Open
jackylam0812 wants to merge 1 commit intoericc-ch:masterfrom
Open
feat: support Anthropic web search (server_tool_use) translation#241jackylam0812 wants to merge 1 commit intoericc-ch:masterfrom
jackylam0812 wants to merge 1 commit intoericc-ch:masterfrom
Conversation
Add support for Anthropic's server-side tool types (web_search) that are used by Claude Code and other Anthropic API clients. Changes: - anthropic-types.ts: Add AnthropicServerTool, AnthropicServerToolUseBlock, AnthropicServerToolResultBlock, AnthropicWebSearchToolResultBlock types - non-stream-translation.ts: Filter server tools from OpenAI tool translation, handle server_tool_use/result blocks in message conversion, export hasWebSearchTool helper - handler.ts: Add web search proxy logic — when Anthropic client requests web_search server tool, detect search intent and perform proxy search via gpt-4o, returning synthetic server_tool_use/web_search_tool_result blocks This fixes compatibility with Claude Code's WebSearch feature when using copilot-api as the API backend. The proxy approach works in non-streaming mode by delegating actual web search to a web-capable Copilot model. Closes ericc-ch#241
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using copilot-api with Claude Code or other Anthropic API clients that enable web search, the server-side tool types (
server_tool_use,server_tool_result,web_search_tool_result) are not recognized. This causes:translateAnthropicToolsToOpenAIto crash when encountering server tools (noinput_schema)handleUserMessageto silently dropserver_tool_result/web_search_tool_resultblockshandleAssistantMessageto silently dropserver_tool_useblocksSolution
Type definitions (
anthropic-types.ts)AnthropicServerTool,AnthropicServerToolUseBlock,AnthropicServerToolResultBlock,AnthropicWebSearchToolResultBlocktypesAnthropicUserContentBlockandAnthropicAssistantContentBlockunionsMessage translation (
non-stream-translation.ts)translateAnthropicToolsToOpenAI: Filter out server tools (they have noinput_schema) instead of crashinghandleUserMessage: Convertserver_tool_result/web_search_tool_resultblocks into user text messages with search contexthandleAssistantMessage: Convertserver_tool_useblocks into text annotationshasWebSearchToolhelper for handler useWeb search proxy (
handler.ts)gpt-4oCopilot requestserver_tool_use+web_search_tool_resultblocksLimitations
Testing
Tested with Claude Code + copilot-api v0.7.0: