Skip to content

fix: handle nested function tool names#73

Open
bigwolftime wants to merge 1 commit into
ZhiYi-R:mainfrom
bigwolftime:fix-tools-name-empty
Open

fix: handle nested function tool names#73
bigwolftime wants to merge 1 commit into
ZhiYi-R:mainfrom
bigwolftime:fix-tools-name-empty

Conversation

@bigwolftime

Copy link
Copy Markdown

背景

在 Codex -> sub2api -> Moon Bridge -> DeepSeek 的调用链路中,DeepSeek 返回 400:

Invalid 'tools[73].function.name': empty string. Expected a string with minimum length 1

排查发现,Moon Bridge 在处理 OpenAI Responses 请求里的 tools 时,只读取了 Responses 风格的顶层字段:

{
  "type": "function",
  "name": "get_weather",
  "parameters": {}
}

但实际链路里可能会收到 Chat Completions 风格的嵌套 function 工具定义:

{
  "type": "function",
  "function": {
    "name": "get_weather",
    "description": "Get the weather",
    "parameters": {}
  }
}

由于原 DTO 没有 function 字段,转换到 CoreTool 时 Name 会变成空字符串,随后 Anthropic adapter 会把这个空工具名继续转发给 DeepSeek,最终触发上游 400。

修改内容

  • 为 OpenAI Tool DTO 增加 function 嵌套结构支持。
  • 在 OpenAI adapter 转换工具前,兼容 Chat Completions 风格的 tool.function:
    • function.name -> tool.Name
    • function.description -> tool.Description
    • function.parameters -> tool.Parameters
    • function.strict -> tool.Strict
  • 在 OpenAI tool flatten/dedup 阶段过滤空名称工具,避免非法 CoreTool 进入后续流程。
  • 在 Anthropic provider adapter 发起上游请求前再次过滤空名称工具,作为防御性兜底。
  • 补充单元测试覆盖:
    • 嵌套 function.name 能正确转换为 CoreTool name。
    • 空名称工具会在 OpenAI adapter 阶段被过滤。
    • Anthropic adapter 不会发送空名称工具给上游。

影响范围

该修改主要提升 OpenAI Responses 入站兼容性,允许 Moon Bridge 接收 Chat Completions 风格的嵌套 function tool 定义。

对原有顶层 name / description / parameters 的 Responses 风格工具定义保持兼容;如果工具名称为空,会被过滤,不再传递给 Anthropic/DeepSeek 上游。

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.

1 participant