wiwjxx

请叫我红领巾
管理成员
2022/05/11
2,950
87
12
38
金币
60,159金币
问题描述

症状:

• OpenClaw 使用 Kimi Coding (k2p5) 时无法执行工具调用
• Bot 返回工具调用作为纯文本 XML,而不是执行工具
• 相同配置下 Minimax 等其他 provider 正常

根本原因:
OpenClaw 2026.3.7+ 引入了一个回归 bug(commit 909f26a):

• 将 compat: { requiresOpenAiAnthropicToolPayload: true } 添加到 kimi-coding 模型配置
• 将 provider capabilities 设置为 OpenAI 格式
• 但 kimi-coding 的 API 期望 Anthropic 原生格式

GitHub Issues:

• #40552 (https://github.com/openclaw/openclaw/issues/40552) - Bug 报告
• #40648 (https://github.com/openclaw/openclaw/pull/40648) - 修复 PR(未合并)

───

解决方案

修复步骤

1. SSH 登录服务器

代码:
ssh <用户名>@<服务器地址>

2. 修复 models.json(删除 compat 字段)

Python:
# 创建修复脚本
cat > /tmp/fix_models.py << 'EOF'
import json

# 模型配置文件路径(通常在 ~/.openclaw/agents/main/agent/models.json)
models_path = "<你的主目录>/.openclaw/agents/main/agent/models.json"

with open(models_path, "r") as f:
    data = json.load(f)

# 删除 compat 字段
if "compat" in data["providers"]["kimi-coding"]["models"][0]:
    del data["providers"]["kimi-coding"]["models"][0]["compat"]

with open(models_path, "w") as f:
    json.dump(data, f, indent=2)

print("Fixed models.json!")
EOF

python3 /tmp/fix_models.py

3. 修复 provider capabilities(关键步骤)

Python:
# 找到 OpenClaw 安装目录下的 compact 文件
# 通常在 ~/.npm-global/lib/node_modules/openclaw/dist/ 或类似路径

cat > /tmp/fix_provider.py << 'EOF'
import re

# OpenClaw 主程序文件路径
file_path = "<OpenClaw安装目录>/lib/node_modules/openclaw/dist/compact-xxx.js"

with open(file_path, "r") as f:
    content = f.read()

# 替换 kimi-coding 配置
old_config = '''"kimi-coding": {
\t\tanthropicToolSchemaMode: "openai-functions",
\t\tanthropicToolChoiceMode: "openai-string-modes",
\t\tpreserveAnthropicThinkingSignatures: false
\t}'''

new_config = '''"kimi-coding": {
\t\tproviderFamily: "anthropic"
\t}'''

if old_config in content:
    content = content.replace(old_config, new_config)
    with open(file_path, "w") as f:
        f.write(content)
    print("Fixed provider capabilities!")
else:
    print("Pattern not found, check file manually")
EOF

python3 /tmp/fix_provider.py
4. 重启 Gateway 服务
代码:
# 使用 systemd 重启
systemctl --user restart openclaw-gateway

# 或使用 launchctl (macOS)
# launchctl stop ai.openclaw.gateway
# launchctl start ai.openclaw.gateway

5. 验证修复

代码:
# 检查 provider 配置是否已修改
grep -A2 '"kimi-coding":' <OpenClaw安装目录>/lib/node_modules/openclaw/dist/compact-*.js

# 应该输出:
# "kimi-coding": {
#   providerFamily: "anthropic"
#  },

# 检查服务状态
systemctl --user status openclaw-gateway

───

技术细节

错误配置(修复前):

代码:
"kimi-coding": {
    anthropicToolSchemaMode: "openai-functions",
    anthropicToolChoiceMode: "openai-string-modes",
    preserveAnthropicThinkingSignatures: false
}

正确配置(修复后):

代码:
"kimi-coding": {
    providerFamily: "anthropic"
}

影响:

• requiresOpenAiAnthropicToolPayload: true 会触发工具格式转换
• 工具从 Anthropic 原生格式 (name + input_schema) 被转为 OpenAI 格式
• kimi-coding 的 anthropic-messages API 不识别这种格式,导致工具调用失效

───

注意事项

文件路径说明:
代码:
| 文件           | 默认位置                                                   |
| ------------ | ------------------------------------------------------ |
| models.json  | ~/.openclaw/agents/main/agent/models.json              |
| OpenClaw 主程序 | ~/.npm-global/lib/node_modules/openclaw/dist/          |
| 日志           | journalctl --user -u openclaw-gateway 或 /tmp/openclaw/ |

如果你使用:

• nvm: 路径可能是 ~/.nvm/versions/node/v22.x.x/lib/node_modules/...
• pnpm: 路径可能是 ~/.local/share/pnpm/global/...
• bun: 路径可能是 ~/.bun/install/global/...

───

临时解决方案

如果不想修改源码,可以:

1. 降级到 2026.3.6(bug 引入之前):npm install -g openclaw@2026.3.6
2. 改用 minimax/qwen 等其他 provider

等官方 PR #40648 合并后再升级。