我把codex接入了mimo token plan,但是codex不能完整独立完成任务
-
我把codex接入了mimo token plan,但是codex不能完整完成任务,总是输出以下似乎是调用工具的内容后截断。大佬们,求个解决方案。
<tool_call>
function_calls>
<tool_call>
{"name": "exec_command", "arguments": {"cmd": "& "E:\ai-toolkit\venv\Scripts\python.exe" -c "\ncontent = open(r'E:\laya\backend_simple.py', 'r', encoding='utf-8').read()\n# Replace capture_screen method with fallback\nold = ''' def capture_screen(self, region=None):\n if region is None:\n monitor = self.sct.monitors[1]\n region = {\"top\": monitor[\"top\"], \"left\": monitor[\"left\"],\n \"width\": monitor[\"width\"], \"height\": monitor[\"height\"]}\n screenshot = self.sct.grab(region)\n return Image.frombytes(\"RGB\", screenshot.size, screenshot.rgb)'''\nnew = ''' def capture_screen(self, region=None):\n try:\n if region is None:\n monitor = self.sct.monitors[1]\n region = {\"top\": monitor[\"top\"], \"left\": monitor[\"left\"],\n \"width\": monitor[\"width\"], \"height\": monitor[\"height\"]}\n screenshot = self.sct.grab(region)\n return Image.frombytes(\"RGB\", screenshot.size, screenshot.rgb)\n except Exception as e:\n print(f\"[mss截图失败: {e}, 改用PIL.ImageGrab]\")\n from PIL import ImageGrab\n img = ImageGrab.grab()\n return img'''\nif old in content:\n content = content.replace(old, new)\n open(r'E:\laya\backend_simple.py', 'w', encoding='utf-8').write(content)\n print('capture_screen updated with PIL fallback')\nelse:\n print('pattern not found, need manual fix')\n # Show current capture_screen\n import re\n m = re.search(r'def capture_screen.?return.', content, re.DOTALL)\n if m:\n print(m.group()[:500])\n" 2>&1", "workdir": "E:\laya"}}
</tool_call>
</function> -
现象很清楚:模型把工具调用以文本吐出来了——
<tool_call>/function_calls原样进了正文,而不是走 OpenAI 的结构化tool_calls字段。Codex 只认choices[].message.tool_calls,看到正文里的文本就当普通回答,再撞上max_output_tokens就被截断。不是 Codex 坏了。先做 30 秒判定,直接打你那个 mimo 网关:
curl -s https://<你的网关>/v1/chat/completions \ -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \ -d '{"model":"<model>","messages":[{"role":"user","content":"列出当前目录"}], "tools":[{"type":"function","function":{"name":"exec_command", "parameters":{"type":"object","properties":{"cmd":{"type":"string"}},"required":["cmd"]}}}]}'看返回:
message.tool_calls是结构化数组 → 网关支持,问题在 Codex 配置;- 正文里出现
<tool_call>→ 网关没做 tool 解析,把tools参数吞了。多数「token plan」中转只透传 chat,不支持函数调用,模型只能自己编文本格式。
对应三条修法:
- 网关侧(最可能):换/加支持 function-call 翻译的网关——LiteLLM proxy、new-api 打开「函数调用/工具解析」,或 vLLM 起
--enable-auto-tool-choice --tool-call-parser <对应parser>。纯透传网关无解,换模型也救不了。 - Codex 配置侧:
~/.codex/config.toml的 provider 段加wire_api = "chat"(第三方 OpenAI 兼容端点基本只有 chat completions、没有 Responses API,协议走错也会退化成文本);model_context_window/model_max_output_tokens必须按该模型真实值填,填大填小都会在工具调用中途断。 - 模型侧:agentic 工具调用要专门对齐过的模型;mimo 这类偏对话的,就算网关翻译了,多步工具成功率也低。换 Qwen3-Coder / GLM / Kimi K2 / DeepSeek 这类 function-call 训练充分的,或直接用 Codex 官方支持的模型。
验证闭环:先用上面的 curl 确认拿到结构化
tool_calls,再在 Codex 里跑一个只读单步(让它读一个文件),确认工具真被执行,再放量跑长任务。另:你贴的那串
& "E:\...python.exe" -c ...是 PowerShell 转义写法,跟截断无关,别往那个方向排查。 -
API 都需要有兼容接口才能正常的接入。mimo token plan 用的是open ai 或 Claude 兼用模式接口吗?
-
API 都需要有兼容接口才能正常的接入。mimo token plan 用的是open ai 或 Claude 兼用模式接口吗?
@williamlouis 确实不支持,但是可以用hermes给它改的兼容,(具体怎么改,你看老特视频。)我已经改的兼容,现在就是工具调用这块老有问题。
-
是不是 兼容了 决定权在 模型本身。
如果你的修正无效,就不要纠结了。
换模型。用mimo token plan 自己开发的编辑器。二选一吧。
你花费再多的精力搞这个mimo token plan 也不会感谢你。