工具调用(tool call)问题总结:text-injection 跨平台兼容性
现存相关 Issue
| # | 标题 |
|---|---|
| #26 | 除了kimi其他的工具调用都失败了 |
| #38 | openclaw 使用,不调用工具! |
| #48 | 看来逆向api只能用来聊天,工具调用确实是无法使用的 |
| #68 | 能适配一下openclaw、Qclaw吗?tool call异常 |
| #70 | 调用问题(多频繁调用封号) |
| #95 | 可以兼容一下Workbuddy平台的toolcall吗 |
| #96 | 如何能解决 openclaw 的Tool Call失败问题 |
当前工具调用方案
逆向 API 不支持 OpenAI 原生 tools 参数。Chat2API 使用 text-injection + 正则解析:
- 请求阶段:promptInjectionService 检测 client → 注入工具格式提示到 system prompt → 删除 tools 参数
- 响应阶段:streamToolHandler / applyToolCallsToResponse 从模型输出文本中解析工具调用 → 重建 tool_calls delta
关键代码:
- signatures.ts — 已知 client 定义(Cline/CherryStudio/ClaudeCode/KiloCode/CodexCLI/VSCodeAgent + unknown)
- clientDetector.ts — 从消息内容检测 client
- promptInjectionService.ts — 注入决策(auto/always/never + client 检测)
- tools.ts — toolsToSystemPrompt() 生成 bracket 格式提示
- toolParser/index.ts — 6+ 种 JSON 容错解析
三类平台表现
| 类型 | 代表 | 已知 client | 提示注入者 | 解析者 | 结果 |
|---|---|---|---|---|---|
| 自注入提示 | Cline/CherryStudio/ClaudeCode | ✅ | 平台自己 | 平台自己 | 🟡 依赖于模型遵循平台格式 |
| OpenAI tools 参数 | OpenClaw/Qclaw/Workbuddy | ❌ | Chat2API | Chat2API | 🔴 模型不一定遵循注入格式 |
| 手动使用 | ChatBox 等 | ❌ | 手动/Chat2API | Chat2API | 🟡 手动补充提示可改善 |
核心问题
text-injection 的可靠性完全依赖模型遵循文本格式指令,因 provider/model 而异(#26:Kimi 能工作,其他不行)。
三个断裂点:
- 注入阶段 — unknown client 走 auto 模式,注入的 bracket 提示可能和平台自己的 system prompt 冲突
- 模型输出阶段 — 模型不一定遵循格式(#26 截图:GLM 输出解释文本而非工具调用)
- 解析阶段 — 依赖模型输出闭合的 [/function_calls] 标签,漏掉或格式错误 → 工具调用丢失
可能的改进方向
- 增加 OpenClaw/Qclaw/Workbuddy 到已知 client 列表
- 分析 Kimi (#26) 为什么比其他 provider 好
- 各 adapter 统一工具调用格式(当前混用 bracket/XML/DeepSeek 特殊格式)
- 增强格式容错解析
好麻烦,不想当AI监工,想放假。。。。五一后再修吧
好麻烦,不想当AI监工,想放假。。。。五一后再修吧 大佬快更啊~~~
Available Tools
You can invoke the following developer tools. Call a tool only when it is required and follow the JSON schema exactly when providing arguments.
{{tools}}
Tool Call Protocol
When you decide to call a tool, you MUST respond with NOTHING except a single [function_calls] block exactly like the template below:
[function_calls] [call:tool_name]{"argument": "value"}[/call] [/function_calls]
CRITICAL RULES:
- EVERY tool call MUST start with [call:tool_name] and end with [/call]
- Use the EXACT tool name from the Available Tools list above, case-sensitive, no modifications
- The content between [call:...] and [/call] MUST be a raw JSON object on ONE LINE - NO LINE BREAKS
- Do NOT wrap JSON in ```json blocks
- Do NOT output any other text, explanation, or reasoning before or after the [function_calls] block
- If you need to call multiple tools, put them all inside the same [function_calls] block
- JSON arguments MUST be compact, all on one line, NO pretty printing, NO newlines
- Do NOT use
, <tool_calling>, <function_calls>, or any XML tags. ONLY use the bracket format shown above.
{{format}}
已收到您的邮件!
这个问题值得高度关注。 如果能解决 tool call 问题。这个项目就很值钱了
I saw this while looking at custom model/provider setup issues: "工具调用(tool call)问题总结:text-injection 跨平台兼容性".
If it helps your testing, CloudGPU exposes a hosted OpenAI-compatible endpoint that can route to GPT, Claude, Gemini, DeepSeek, Kimi and GLM behind one API key.
Base URL: https://gpuapis.com/api/v1 Setup guide: https://gpuapis.com/use-cases/chatbox-api/
I can share a small test key/credit and a cURL request if you want to verify it in your current client before doing any integration work.