Skip to content

fix: 支持 Anthropic Messages API 中的 web_search 工具@ - #7

Open
yukaidi1220 wants to merge 1 commit into
XxxXTeam:mainfrom
yukaidi1220:feat/anthropic-web-search
Open

fix: 支持 Anthropic Messages API 中的 web_search 工具@#7
yukaidi1220 wants to merge 1 commit into
XxxXTeam:mainfrom
yukaidi1220:feat/anthropic-web-search

Conversation

@yukaidi1220

Copy link
Copy Markdown

问题

通过 Anthropic Messages API (/v1/messages) 请求时,传入 web_search_20260209 等内置搜索工具不会生效。原因是在 anthropic_to_openai() 转换过程中,所有 tools 都被当作普通 function tool 处理,web_search_* 类型的 Anthropic server tool 被错误地转换成了一个名为 web_search 的函数调用,而不是触发联网搜索模式。

修复

anthropic_to_openai() 的 tools 转换逻辑中,识别 typeweb_search_ 开头的 Anthropic server tool(包括 web_search_20250305web_search_20260209web_search_20260318),将其转换为 web_search: true 标志,而非 function tool。

这样 resolve_networking() 会正确设置 is_networking = True,GLM 上游请求将启用联网搜索。

测试

请求示例:

{
  "model": "glm-5.2",
  "messages": [{"role": "user", "content": "今天天气怎么样"}],
  "tools": [{"type": "web_search_20260209", "name": "web_search"}],
  "stream": true
}

修复前:搜索工具被当作普通 function,联网不生效。
修复后:web_search: true 被正确传递,GLM 启用联网模式返回实时信息。

@
feat: support Anthropic web_search server tools

Map Anthropic web_search_20250305/20260209/20260318 tool types to OpenAI web_search tool
@
@leeon666

leeon666 commented Jun 22, 2026

Copy link
Copy Markdown

I need to stop calling the open tool. Let me use WebFetch to get the upload API section.
I need to stop calling the open tool. Let me use WebFetch to get the upload API section.
佬你遇到这种问题了吗,没办法干活,一直死循环,只能看文件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants