fix(responses): 支持 Codex 多智能体协议与工具身份双向映射 - #45
Merged
maiphucgiang merged 1 commit intoSep 26, 2026
Merged
Conversation
- 基于 (namespace, name) 建立 ToolRegistry 双向映射,解决同名工具冲突并保持未声明命名空间的普通工具原名 - 修复反向映射逻辑,移除硬编码前缀猜测,支持命名空间内包含双下划线名称的工具正确还原 - 同步转换输入历史中的 function_call 与 tool_choice 为上游对应函数名 - 递归清理工具参数 Schema 中的 'encrypted' 客户端私有标记,提取 agent_message 中的 encrypted_content - 在发往上游前统一清除 _tool_registry 等内部私有元数据 - 统一全量修改文件行尾为 LF,杜绝无关格式差异 - 新增单元测试与覆盖非流式、缓冲流式及实时流式接口级回归测试
Reviewer's GuideAdds end-to-end Codex multi-agent support for /v1/responses by mapping namespaced tool identities losslessly across Responses and Chat formats, preserving agent payloads, sanitizing schemas, stripping internal metadata upstream, and validating behavior across all response modes. Sequence diagram for Codex multi-agent Responses tool mappingsequenceDiagram
participant Codex
participant ResponsesAdapter
participant UpstreamChat
participant StreamConverter
Codex->>ResponsesAdapter: responses_request_to_chat(body)
ResponsesAdapter->>ResponsesAdapter: _collect_raw_tools(tools)
ResponsesAdapter->>ResponsesAdapter: _build_tool_registry_and_chat_tools(raw_tools)
ResponsesAdapter->>ResponsesAdapter: _convert_input_items(items, tool_registry)
ResponsesAdapter->>UpstreamChat: Chat request with mapped function names
UpstreamChat-->>StreamConverter: function_call using upstream name
StreamConverter->>StreamConverter: _fc_item(...)
StreamConverter->>ResponsesAdapter: Responses function_call with namespace and original name
ResponsesAdapter-->>Codex: /v1/responses output
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. If the registry maps a namespaced or historical tool call incorrectly, the upstream model can invoke the wrong function, and that function may perform an external side effect before the change is reverted. Reverting stops future misrouting but cannot undo tool actions already executed.
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.
描述 (Description)
1. 背景与目标
在 Codex 官方客户端通过
/v1/responses接口调用多智能体协作时,解决协作工具丢失、子智能体 Payload 丢失以及工具身份错位问题。本次调整基于上游最新main建立全新分支,根据 PR #44 的评审意见完成调整。2. 主要改进 (Key Changes)
(namespace, name)的双向工具身份映射 (ToolRegistry):collaboration__spawn_agent不会被擅自修改);{namespace}__{name},若发生名称冲突通过安全索引自愈;不同命名空间下的同名工具(如ns1.search与ns2.search)各自分配唯一名称;__的硬编码切分与前缀猜测,工具名包含双下划线时(如custom_ns.exec__command)能够精确还原身份;function_call与tool_choice;_tool_registry)。agent_message中挂载在encrypted_content属性下的明文文本;"encrypted": true客户端标记。tests/test_responses_multiagent.py,经由/v1/responses路由全面覆盖非流式、缓冲流式与实时流式,验证不同命名空间同名工具隔离、普通工具防篡改、含__工具名还原及内部元数据纯净度。3. 验证结果