feat(proxy): add tool schema rectifier for non-OpenAI provider compatibility#1810
feat(proxy): add tool schema rectifier for non-OpenAI provider compatibility#1810wejack639 wants to merge 2 commits into
Conversation
…ibility Fix Codex CLI (Responses API) failing with DashScope/Bailian and similar providers due to two incompatible tool schema patterns: 1. Non-function tool types (e.g. web_search, code_interpreter) that are OpenAI-specific built-in tools - now filtered out before forwarding 2. Missing 'required' field in tool parameters - some providers (notably DashScope) require this field even when empty - now auto-patched Root cause: Codex CLI v0.117+ sends ~188 tools via Responses API, of which ~48 have no 'required' field and 1 is a 'web_search' type. This causes DashScope to return InvalidParameter errors. Includes 9 unit tests covering all edge cases.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 66595235e5
ℹ️ 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".
| let tool_rectify_result = | ||
| super::tool_schema_rectifier::rectify_tool_schema(&mut filtered_body); |
There was a problem hiding this comment.
Gate tool schema rectifier to non-OpenAI providers
This rectifier is invoked for every forwarded request, so OpenAI-hosted tool types are removed even when the upstream provider actually supports them. Because rectify_tool_schema drops any tool whose type is not "function", requests that intentionally use built-ins like web_search/code_interpreter will silently lose those capabilities when routed through providers that should accept them. The rectification should be conditional on provider/API-format compatibility constraints (for example, DashScope-like targets) instead of global.
Useful? React with 👍 / 👎.
| tools.retain(|tool| { | ||
| let tool_type = tool.get("type").and_then(|v| v.as_str()).unwrap_or(""); | ||
| tool_type == "function" | ||
| }); |
There was a problem hiding this comment.
Preserve typeless Anthropic tools during schema filtering
The filter keeps only tools with type == "function", which deletes valid Anthropic-style tool definitions that do not carry a type field (name + input_schema). In this codebase, Anthropic tools are explicitly represented in that typeless shape (for example in providers/transform.rs tests), so forwarding default anthropic requests through this logic strips all tools and breaks tool calling. Restrict this pruning to OpenAI/Responses-shaped requests or detect Anthropic schema before filtering.
Useful? React with 👍 / 👎.
…and preserve typeless tools Address Codex Review P1 feedback on PR farion1231#1810: 1. Gate rectifier to Codex adapter + non-OpenAI providers only: - Only apply tool schema rectification when adapter is Codex and base_url is not api.openai.com - OpenAI natively supports web_search/code_interpreter built-in tools - Claude/Gemini adapters use their own formats, not applicable 2. Preserve Anthropic-style typeless tools: - Tools without a 'type' field (using name + input_schema) are now retained instead of being incorrectly filtered out - Only tools with an explicit non-function type are removed 3. Add 2 new unit tests: - test_preserve_anthropic_typeless_tools: verify Anthropic tools survive - test_mixed_openai_and_typeless_tools: mixed format scenario
Problem
When using Codex CLI (v0.117+) with CC Switch proxying to DashScope/Bailian, requests fail with:
Root Cause
Codex CLI sends ~188 tools via the OpenAI Responses API. Two patterns are incompatible with DashScope and similar providers:
web_search,code_interpreter) - these are OpenAI-specific built-in tools that third-party providers don't recognizerequiredfield in toolparameters- DashScope requires this field to be present even when empty ([]), but ~48 of Codex's tools omit it (all-optional-param tools)Solution
Add a Tool Schema Rectifier that runs in the proxy
forward()pipeline (afterfilter_private_params_with_whitelist):type != "function""required": []into any tool parameters missing the fieldThis follows the same pattern as existing rectifiers (
thinking_rectifier,thinking_budget_rectifier).Testing
cargo test -- tool_schema_rectifiercodex exec 'say hello'works through CC Switch -> DashScope after this fixFiles Changed
src-tauri/src/proxy/tool_schema_rectifier.rssrc-tauri/src/proxy/mod.rssrc-tauri/src/proxy/forwarder.rs