fix(responses): 支持 Codex 官方多智能体 v2 协作协议与子任务明文提取 - #44
Closed
ItQianChen wants to merge 1 commit into
Closed
ItQianChen wants to merge 1 commit into
ItQianChen wants to merge 1 commit into
Conversation
- 支持递归解包 `namespace` 命名空间工具,解决直连时 `spawn_agent` 等协作工具被静默丢弃的问题 - 支持提取 `agent_message` 中的 `encrypted_content`,解决子智能体任务 Payload 为空及结果回传丢失问题 - 清理工具参数中的 `"encrypted": true` 私有属性,保证转发给上游的 JSON Schema 格式纯净 - 在 `ResponsesStreamConverter` 中建立双向命名空间映射,回传工具调用时补齐 `namespace: "collaboration"` - 新增多智能体消息提取与工具解包的单元测试用例
There was a problem hiding this comment.
Sorry @ItQianChen, your pull request is larger than the review limit of 500,000 diff characters
Owner
|
感谢补充 Codex 多智能体兼容支持。但是这个 PR 目前存在大量行尾差异及工具身份映射问题,请基于上游最新 main 新建独立功能分支,完成以下调整后重新提交新PR:
新 PR 请附相关测试结果,并确保说明与实际实现一致。当前 PR 先关闭。 |
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. 背景与问题 (Background)
在 Codex 官方客户端通过
/v1/responses接口调用多智能体协作(Multi-Agent v2)时,存在两个核心协议层兼容问题:spawn_agent,send_message,followup_task,wait_agent等)打包在type: "namespace"类型的collaboration命名空间中。原有的_convert_tools_for_chat仅处理type: "function"的顶层工具,导致所有协作工具被静默丢弃,模型在执行时报“协作工具未暴露”。NEW_TASK)以及回传结果(FINAL_ANSWER)时,会将正文挂载在agent_message的encrypted_content属性中(内容为明文)。原有内容提取函数_extract_content仅支持input_text/text/output_text,导致任务正文被丢弃,子智能体收到空 Payload 并陷入“我是谁、查什么”的身份迷航。2. 主要改动 (Key Changes)
app/adapters/responses_adapter.py的_convert_tools_for_chat中增加对type: "namespace"的递归提取与去重,拍平为标准 Chat Completionsfunction工具。_build_tool_namespace_map,在ResponsesStreamConverter中建立双向命名空间映射;当模型输出spawn_agent等调用时,在function_call事件中准确补回"namespace": "collaboration",满足 Codex 客户端识别需求。encrypted_content正文提取:_extract_content中增加对type: "encrypted_content"的提取分支,读取encrypted_content属性并将文本无缝拼接回任务正文中。parameters.properties中的"encrypted": true客户端专用标记,输出标准的 JSON Schema,避免严格校验的下游模型网关报错。converter.py的流式与非流式调用中,发往后端请求体时自动剔除用于内部映射的临时元数据键_tool_namespaces。3. 验证与测试 (Verification)
tests/test_responses_adapter.py中新增test_encrypted_content_and_namespace_tools测试用例,覆盖namespace工具展开、agent_message提取及namespace事件还原。pytest tests/test_responses_adapter.py)。agent_message+encrypted_content构造请求打向/v1/responses,后端模型成功读取正文并正常响应(HTTP 200 OK)。4. 兼容性 (Compatibility)