mega - #47
mega#47
Conversation
- 基于 (namespace, name) 建立 ToolRegistry 双向映射,解决同名工具冲突并保持未声明命名空间的普通工具原名 - 修复反向映射逻辑,移除硬编码前缀猜测,支持命名空间内包含双下划线名称的工具正确还原 - 同步转换输入历史中的 function_call 与 tool_choice 为上游对应函数名 - 递归清理工具参数 Schema 中的 'encrypted' 客户端私有标记,提取 agent_message 中的 encrypted_content - 在发往上游前统一清除 _tool_registry 等内部私有元数据 - 统一全量修改文件行尾为 LF,杜绝无关格式差异 - 新增单元测试与覆盖非流式、缓冲流式及实时流式接口级回归测试
fix(responses): 支持 Codex 多智能体协议与工具身份双向映射
Reviewer's GuideThe PR introduces shared reasoning compatibility and account-aware effort resolution, while substantially extending Responses conversion with namespace-aware multi-agent tools, reversible tool identity mapping, schema sanitization, and comprehensive protocol/streaming regression tests. Sequence diagram for account-aware reasoning request routingsequenceDiagram
participant Client
participant Adapter
participant Router
participant Account
participant ChatUpstream
Client->>Adapter: responses_request_to_chat(body)
Adapter->>Adapter: map_reasoning_controls(body, chat, protocol)
Adapter->>Router: _route_chat(payload, body)
Router->>Account: resolve_reasoning_effort(effort, mode, model)
Account-->>Router: selected effort
Router->>ChatUpstream: reasoning_effort and normalized request
ChatUpstream-->>Client: reasoning-aware response
Sequence diagram for Responses namespaced tool conversionsequenceDiagram
participant Client
participant ResponsesAdapter
participant ToolRegistry
participant ChatUpstream
participant ResponsesStream
Client->>ResponsesAdapter: responses_request_to_chat(body)
ResponsesAdapter->>ToolRegistry: _build_tool_registry_and_chat_tools(raw_tools)
ToolRegistry->>ToolRegistry: register(namespace, name)
ToolRegistry-->>ResponsesAdapter: chat_tools and identity mapping
ResponsesAdapter->>ChatUpstream: mapped function names and _tool_registry
ChatUpstream-->>ResponsesStream: tool call delta
ResponsesStream->>ToolRegistry: get_identity(upstream_name)
ToolRegistry-->>ResponsesStream: namespace and original name
ResponsesStream-->>Client: Responses function_call
Flow diagram for readable reasoning normalizationflowchart LR
Input["Protocol input"] --> Extract["extract_reasoning_text"]
Extract -->|readable thinking or reasoning| History["assistant reasoning_content"]
Extract -->|redacted or encrypted-only| Reject["400 validation error"]
History --> Chat["Chat upstream"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. This changes reasoning controls, historical tool handling, namespace identity mapping, routing, and streamed tool-call reconstruction across multiple protocols. If an identity or routing conversion is wrong, the gateway could invoke the wrong external tool or send an unintended request, and reverting would not undo those side effects.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4489437d15
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if registry.upstream_to_identity: | ||
| chat["_tool_registry"] = registry.to_dict() |
There was a problem hiding this comment.
Exclude the internal tool registry from size accounting
When a Responses request containing tools is near max_request_bytes, adding _tool_registry duplicates every tool identity before _prepare_chat_body measures the body, so an otherwise valid request can receive a local 413. This metadata is never sent upstream—the streaming and non-streaming paths strip underscore-prefixed keys—so size validation should omit it or run against the actual upstream body.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dc245d1a36
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if namespace is None: | ||
| upstream_name = name | ||
| else: | ||
| base = f"{namespace}__{name}" |
There was a problem hiding this comment.
Encode namespace aliases as valid Chat function names
For nested namespaces, current_ns is joined with . and this line produces aliases such as parent.child__tool; sufficiently long namespace/name pairs can also exceed the Chat function-name limit. These declarations are accepted locally but the generated name is forwarded as a Chat tool name, whose allowed characters are letters, digits, _, and - with a 64-character maximum, so the upstream request is rejected instead of executing the tool. Encode or hash namespace identities into a bounded valid alias while retaining the registry mapping.
Useful? React with 👍 / 👎.
Summary by Sourcery
Improve cross-protocol reasoning compatibility and Responses tool handling while preserving history, namespaces, and upstream request boundaries.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: