增强 Codex CLI / Responses API 工具调用兼容性#532
Open
mariotong wants to merge 5 commits into
Open
Conversation
Author
|
只能在codex中使用吗,接到hermes里貌似不起效果 |
|
我安装了后再codex cli里面用也没效果,写入不了文件。 |
|
我发现只有 grok-4.20-0309-super可以读到目录 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

背景
这组改动主要是为了提升 grok2api 在 OpenAI Responses API 兼容模式下对 Codex CLI 的支持。Codex CLI 会依赖
/v1/models?client_version=...获取更丰富的模型目录,也会通过 Responses API 的 streaming 事件、function_call、function_call_output、多轮工具调用来完成本地文件读取、搜索、编辑、长进程交互等任务。在实际接入时发现,如果上游模型没有稳定输出结构化 tool call,Codex 容易出现以下问题:
/v1/models?client_version=codex_cli_rs缺少 Codex 需要的模型 catalog 字段。主要改动
1. 增加 Codex 专用模型 catalog
/v1/models仍返回 OpenAI 兼容的object=list格式;client_version参数时,返回 Codex CLI 需要的模型 catalog 字段,例如:slug/display_namebase_instructionsapply_patch_tool_typetruncation_policycontext_windowsupports_parallel_tool_calls这样 Codex CLI 可以正常识别和选择 grok2api 暴露的模型。
2. 强化 Responses API 的工具调用兼容
exec_command、write_stdin、apply_patch做更明确的提示约束;3. 增加 Codex 本地文件操作兜底
新增
app/products/openai/_codex_tools.py,集中处理 Codex 相关兼容逻辑:pwd、列目录、桌面文件列表等基础本地操作;读取 sample.txt 内容;搜索包含 alpha 的文件,合成为rg -n -- alpha .;apply_patch;把 sample.txt 里的 alpha 改成 beta,合成为最小apply_patch;4. 改善 apply_patch 失败后的行为
5. 增加测试覆盖
新增
tests/test_codex_tools.py,覆盖:本地验证
已执行:
结果:
另外用 Codex CLI 通过 grok2api 做了端到端验证,覆盖本地文件读取、搜索和编辑:
读取 sample.txt 内容并告诉我-> 正确执行sed -n '1,200p' sample.txt;搜索当前目录下包含 alpha 的文件-> 正确执行rg -n -- alpha .;把 sample.txt 里的 alpha 改成 beta-> 正确触发文件更新,最终文件内容从alpha变成beta。兼容性说明
/v1/models返回格式保持不变;client_version时启用;exec_command/write_stdin/apply_patch等 Codex 风格工具时触发;