Skip to content

桥接兼容性规划

并非每个上游 Provider 都支持 OpenAI Responses API 的所有功能。GodeX 必须在任何请求发送之前决定:哪些功能是原生支持的,哪些可以降级到相近的替代方案,哪些必须静默忽略,哪些是硬性阻塞。兼容性子系统以确定性的方式做出这些决策,并为每个决策记录诊断信息,让运维人员完全了解某个请求为何被塑造成特定的形式。

概览

概念类型用途
ProviderCapabilities接口声明 Provider 支持的功能(参数、工具、格式、推理)
CompatibilityPlan接口持有单个请求的所有决策
CompatibilityDecision接口一条决策:动作、原因、有效值
CompatibilityDiagnostic接口可观测记录:代码、严重程度、路径、消息、元数据
planBridgeCompatibility函数入口点;评估参数和响应格式
planTools函数评估工具声明和 tool_choice
planOutputContract函数评估 JSON Schema 输出约束

决策动作

每个兼容性决策精确解析为以下四种动作之一:

动作含义诊断严重程度
supported功能原生支持;原样转发--(不产生诊断)
degraded功能映射到相近替代方案;行为可能不同warn
ignored功能被静默丢弃;请求继续执行但不包含该功能warn
rejected功能为硬性阻塞;请求被中止并抛出 BridgeErrorerror

能力域

Provider 通过 ProviderCapabilities 接口声明其能力:

字段类型示例
参数parameters.supportedSet<string>streamtemperaturetop_pmax_output_tokensreasoningsafety_identifieruser
工具tools.supportedSet<string>functionmcpshellapply_patchcustom
工具降级tools.degradedMap<string, string>mcp -> function
工具选择toolChoice.supportedSet<string>autorequiredfunction
响应格式responseFormats.supportedSet<string>textjson_objectjson_schema
推理reasoning.effort"none" / "boolean" / "native"是否以及如何转发推理力度
流式streaming.usagebooleanSSE 流是否包含 usage 数据

兼容性规划流程

工具兼容性

planTools 函数根据 Provider 的 ToolPlanningProfile 评估每个工具声明:

工具选择解析

请求值Provider 支持结果
autoautosupported
requiredrequiredsupported
requiredauto降级为 auto
required均不支持rejected(错误)
具名函数/自定义匹配声明 + Provider 类型supported 或 degraded
具名函数/自定义无匹配声明rejected(错误)

响应格式降级

当 Provider 不原生支持 json_schema 但支持 json_object 时,输出契约会被降级。一条合成指令会被注入到系统消息中,包含原始 JSON Schema、验证规则以及 GodeX 将验证输出的说明:

降级路径Provider response_format合成指令后验证
json_schemajson_object{ type: "json_object" }Schema 名称、描述和完整 JSON Schemastrict 时启用 requiresValidJson: true

推理力度模式

各 Provider 处理推理力度的方式不同。reasoning.effort 能力决定映射方式:

能力模式行为
native直接转发 reasoning_effort(如 lowmediumhigh
boolean映射为 thinking.type"none" 变为 "disabled",其他变为 "enabled"
none推理力度被静默忽略;不转发任何参数

诊断代码

每个非 supported 的决策会产生一个带机器可读代码的诊断:

代码触发条件
bridge.param.ignoredGodeX 自有参数(metadata、conversation、background)或不支持的工具类型
bridge.param.degraded功能被降级(json_schema 降为 json_object、tool_choice required 降为 auto)
bridge.param.unsupported硬性拒绝不支持的功能
bridge.tool.compatibility工具声明非原生支持(动作视具体决策而定)

CompatibilityPlan 结构

交叉引用

  • 架构概览:兼容性规划在完整请求生命周期中的位置
  • 请求构建:兼容性决策如何在请求构建过程中被消费
  • 响应重建:响应后验证如何使用输出契约

参考