Skip to content

mega - #47

Merged
maiphucgiang merged 7 commits into
mainfrom
dev
Sep 26, 2026
Merged

mega#47
maiphucgiang merged 7 commits into
mainfrom
dev

Conversation

@maiphucgiang

@maiphucgiang maiphucgiang commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Summary by Sourcery

Improve cross-protocol reasoning compatibility and Responses tool handling while preserving history, namespaces, and upstream request boundaries.

New Features:

  • Add shared reasoning-control and readable reasoning-history support across Messages and Responses protocols.
  • Support Responses multi-agent tools with namespace-aware, reversible Chat aliases and exact tool-choice mapping.

Bug Fixes:

  • Prevent encrypted or malformed reasoning history from leaking into visible content or reaching upstream services.
  • Preserve assistant reasoning, text, and tool calls together across buffered and realtime continuations.
  • Exclude gateway-only metadata from upstream requests and request-size calculations.

Enhancements:

  • Normalize account-specific reasoning defaults and capability checks during routing and failover.
  • Sanitize encrypted schema markers while preserving schema names and literal instance data.

Documentation:

  • Document reasoning compatibility, tool namespaces, encrypted-history handling, and gateway metadata size accounting.

Tests:

  • Add comprehensive protocol, routing, reasoning, tool-identity, streaming, schema-sanitization, and request-budget coverage.

ItQianChen and others added 5 commits September 26, 2026 20:33
- 基于 (namespace, name) 建立 ToolRegistry 双向映射,解决同名工具冲突并保持未声明命名空间的普通工具原名
- 修复反向映射逻辑,移除硬编码前缀猜测,支持命名空间内包含双下划线名称的工具正确还原
- 同步转换输入历史中的 function_call 与 tool_choice 为上游对应函数名
- 递归清理工具参数 Schema 中的 'encrypted' 客户端私有标记,提取 agent_message 中的 encrypted_content
- 在发往上游前统一清除 _tool_registry 等内部私有元数据
- 统一全量修改文件行尾为 LF,杜绝无关格式差异
- 新增单元测试与覆盖非流式、缓冲流式及实时流式接口级回归测试
fix(responses): 支持 Codex 多智能体协议与工具身份双向映射
@sourcery-ai

sourcery-ai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The 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 routing

sequenceDiagram
    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
Loading

Sequence diagram for Responses namespaced tool conversion

sequenceDiagram
    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
Loading

Flow diagram for readable reasoning normalization

flowchart 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"]
Loading

File-Level Changes

Change Details Files
Centralize reasoning-control validation, effort mapping, readable-history extraction, and account-specific default resolution across protocols.
  • Add shared parsing for Anthropic thinking, Responses reasoning, and explicit effort controls.
  • Preserve readable reasoning as assistant reasoning_content while rejecting encrypted or malformed history.
  • Resolve implicit reasoning effort after account selection and re-resolve it during failover.
  • Update capability checks and document supported mappings and limitations.
app/reasoning.py
app/adapters/anthropic_adapter.py
app/adapters/chat_input.py
app/adapters/responses_adapter.py
app/model_capabilities.py
converter.py
docs/advanced.md
docs/advanced.zh-CN.md
docs/clients.md
docs/clients.zh-CN.md
tests/test_reasoning_requests.py
Add Responses multi-agent tool namespace support with reversible identity mapping between protocol names and upstream Chat function names.
  • Collect tools from top-level and additional_tools entries, including nested namespaces.
  • Allocate collision-safe upstream names and retain registry metadata for response reconstruction.
  • Map historical function calls and exact tool choices using (namespace, name) identities.
  • Restore namespaces in streamed and non-streamed function_call output while keeping retired tools non-selectable.
app/adapters/responses_adapter.py
converter.py
tests/test_responses_adapter.py
tests/test_responses_multiagent.py
Sanitize Responses tool schemas and support additional multi-agent input content without leaking internal conversion metadata upstream.
  • Remove boolean encrypted markers only from schema positions while preserving property names and literal instance data.
  • Convert agent_message and encrypted_content inputs into Chat-compatible user content.
  • Strip internal registry fields before forwarding upstream requests.
app/adapters/responses_adapter.py
converter.py
tests/test_responses_adapter.py
tests/test_responses_multiagent.py
Expand regression coverage across reasoning, routing, streaming, tool continuation, namespace collisions, schema cleanup, and validation boundaries.
  • Exercise all protocols and stream modes, including account defaults and failover.
  • Verify reasoning remains separate from visible content and tool calls remain in one assistant turn.
  • Cover malformed controls, opaque reasoning, invalid identities, retired tools, and upstream metadata isolation.
tests/test_reasoning_requests.py
tests/test_responses_adapter.py
tests/test_responses_multiagent.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-26T17:16:30.954014Z 1cfd839 New commits
🔒 Security Review ✅ Completed 2026-09-26T16:20:26.001666Z 4489437 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +87 to +88
if registry.upstream_to_identity:
chat["_tool_registry"] = registry.to_dict()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@maiphucgiang
maiphucgiang merged commit a88e597 into main Sep 26, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants