Provider detection
FIM One uses LiteLLM as a universal adapter. The_resolve_litellm_model() function in core/model/openai_compatible.py maps the user’s LLM_BASE_URL + LLM_MODEL to a LiteLLM model identifier with a provider prefix. The prefix determines how LiteLLM routes the request — native API protocol (Anthropic Messages API, Gemini, etc.) or generic OpenAI-compatible /v1/chat/completions.
Resolution order:
- Explicit provider (from the
providerfield of a legacyModelConfigrow or an agent’s inline model config; models added under Admin → Models have no provider field, so for them resolution starts at step 2) — highest priority. If the provider matches a known domain in the URL, noapi_baseis returned (LiteLLM routes natively). Otherwise,api_baseis set to the relay URL. - Domain match against
KNOWN_DOMAINS— official API endpoints are recognized by hostname. - URL path hint against
PATH_PROVIDER_HINTS— common on relay platforms like UniAPI where/claudeor/anthropicin the path indicates the upstream protocol. - Fallback —
openai/prefix (generic OpenAI-compatible).
When the provider prefix is a native protocol (anthropic, gemini, etc.) and the URL is not the official endpoint, LiteLLM uses the native protocol but sends requests to the relay’s
api_base. This means provider-specific behaviors — including the Bedrock prefill issue described below — apply regardless of whether the request goes to the official API or through a relay.
tool_choice — 四种模式
tool_choice 参数通过 OpenAI 格式标准化。LiteLLM 在发送请求前将其转换为每个提供商的原生协议。
"auto" 和强制模式({"type":"function",...})之间的区别是 FIM One 中每个兼容性问题的关键。这两种模式由具有不同要求的完全不同的子系统使用。
tool_choice 的使用位置
两个子系统使用tool_choice,它们以根本不同的方式使用它。
ReAct 引擎 — tool_choice=“auto”
ReAct 循环需要模型在每次迭代中做出决定:调用工具或给出最终答案。只有"auto" 才有意义——模型可以自由选择生成 tool_calls 或文本内容。这与所有提供商、所有模型和所有模式(包括扩展思考)兼容。
ReAct 引擎在 abilities["tool_call"] = True 时使用原生函数调用(_run_native),否则回退到 JSON-in-content 模式(_run_json)。两种模式都使用 "auto"——区别在于工具是通过 tools 参数传递还是在系统提示中描述。详见 ReAct 引擎——双模式执行。
structured_llm_call——tool_choice=forced
一次性结构化提取(架构注释、DAG规划、计划分析)。强制模型调用特定的虚拟函数,从而保证输出结构化JSON。这是触发提供商特定错误的调用位置。structured_llm_call实现了三级降级链。这三个层级以代码命名,其编号与下文结构化输出的四个保证层级并不相同:
关键的设计差异在于:structured_llm_call的回退是运行时行为——它会动态尝试每个层级,并捕获异常以继续执行后续层级。ReAct引擎的模式选择则发生在构建时——它会在开始时检查一次_native_mode_active,并在整个循环中固定使用一种模式。这意味着structured_llm_call可以透明地从提供商特定的400错误中恢复,而ReAct依赖于在开始时正确选择模式。
结构化输出:四个保证层级
“结构化输出”是一个涵盖四种不同机制的术语。它们都会生成JSON,但提供的保证并不相同。区别在于约束存在于何处:是在解码器内部——它无法生成Schema禁止的token;还是在提示词中——它只能提出要求。
T1和T2背后的机制是受约束解码。提供商会将Schema编译成语法,并在每个解码步骤中屏蔽所有会导致输出无法根据Schema解析的token。必填字段不能被跳过,因为在该字段生成之前,用于闭合对象的token不会位于允许集合中。这与“模型被客气地要求后遵守了”是完全不同类型的保证,也正因如此,T1/T2在温度为1以及较小的模型上仍然成立,而提示词遵循并不能做到这一点。
T1和T2不可互换
它们通过不同的通道提供相同的保证,而通道在三个方面都很重要。 两者的轮次形态不同。 T1返回工具调用轮次;模型已经决定要采取行动。T2返回普通的助手消息;模型以某种结构给出了回答。当调用方需要一次提取而不是智能体循环时,T2会直接表达这一点,而不是为模型虚构一个供其“调用”的虚拟函数。 强制使用T1会与思考冲突。 要从T1获取经过架构约束的载荷,通常意味着强制指定选项,可以是required或命名函数。多家提供商会拒绝在扩展思考处于启用状态时强制指定工具选项。下方的表B记录了具体情况。T2不存在此类冲突:它是响应约束,而不是工具约束,因此它是唯一一条在启用思考时仍然有效的架构约束路径。对于采用推理模型作为标准的部署而言,这才是选择T2而非T1的实际理由,而不是风格偏好。
T1需要额外一轮T2不需要的架构连接工作。 虚拟函数需要名称、描述,以及决定模型是否可以拒绝调用它。
T2的成本
受约束解码并非免费,而且你已有的schema通常并不是它所接受的schema。- schema子集。 OpenAI的strict mode要求每个对象都设置
additionalProperties: false,并将每个属性都列入required;可选性通过与null组成联合类型来表示,而不是从required中省略。根节点必须是对象。属性总数和嵌套深度也存在上限。大多数手写schema在符合要求前都需要进行编辑。 - 语法编译。 携带新schema的首次请求需要承担提供商侧一次性的编译延迟。复用稳定的schema可以分摊这项开销;而每个请求都生成全新的schema则无法做到这一点。
- 新的失败面。 不愿回答的模型会返回拒答,而不是符合schema结构的对象,因此调用方需要为此增加一个分支。
没有任何层级能够保证的内容
每个层级都会约束形式,但没有任何层级能够约束真实性。T2响应可以完全符合schema且在事实上错误;即使没有一个值是正确的,受枚举约束的字段也会返回允许值中的一个,因为解码器的职责是让输出保持在语法范围内,而不是知道答案。Schema门控可以消除解析失败和字段形状错误,但不能免除对值所表达内容进行检查的必要性。FIM One 所处的位置
由此产生五个后果,这些是当前设计的实际限制。
- 链中没有可回退到的 schema 约束层级。 当 Level 1 失败时,下一层是
json_object,它只能保证文本可解析。不存在仍然强制要求字段的中间步骤。 - Level 1 的保证弱于其名称所暗示的程度。 未启用
strict时,原生函数调用属于 2024 年之前的非严格形式:模型通常会遵循 schema,但不会被阻止省略必填字段、编造键,或在声明为数字时返回字符串。 - 在
anthropic/路由上,Level 2 实际上并不是真正的 T3。 Anthropic Messages API 没有response_format,因此 LiteLLM 会通过注入 assistant prefill 来模拟 JSON mode。这是一种提示词层面的机制,使实际保证介于 T4 和 T3 之间,而不是达到 T3。下文记录的 Bedrock prefill 陷阱,就是这种模拟机制明显失败的表现;更隐蔽的代价在于,这种保证从未达到参数名称所暗示的程度。 - 结果不会在之后根据 schema 进行验证。
jsonschema不是依赖项。实际执行的任何检查都位于可选的parse_fn中,并且由每个调用位置自行决定,其严格程度各不相同。 - 失败会被吸收,而不是暴露出来。 几乎所有调用方都会传入
default_value,因此链耗尽后会返回一个看似合理的对象,而不是抛出异常。StructuredCallResult.level_used会记录生成该值的层级,但没有任何调用位置读取它;在default_value路径上,它还会为实际上什么都没生成的链报告plain_text。
structured_llm_call 会在每次调用完成后于 INFO 级别记录一行日志;该日志仅在数据通过 parse_fn 后才会输出,因此其中标示的是确实成功的层级:
WARNING 级别记录 level=none outcome=default_value。在一天的流量中检索这两行日志,是判断缺失的 T2 层级是否给特定部署带来影响的唯一方法,因为 default_value 设计会让症状表现为质量一般的答案,而不是错误。
每个层级的提供商支持情况
此表记录的是上游 API,而不是 FIM One 的代码路径。 本页中的其他表格都会列出实现相应行为的函数,而此表无法这样做,因为 FIM One 不使用任何提供商的 T2 功能,也不会对任何提供商设置
strict。此表的作用是确保实现 T2 的决策以实际可用的能力为起点。提供商的能力变化很快,同一系列中的部分模型可能会先于其他模型获得支持;依赖某一行之前,请重新查阅提供商自己的文档。
有三个模式值得单独说明,因为它们解释了表格的结构,而不只是重复表格内容。
T3 是通用的,T2 则不是。 FIM One 支持的每个提供商都提供
json_object,而大约一半的提供商提供 Schema 层级。因此,可移植的结构化输出路径必须建立在 T3 或更低层级之上,这就是 FIM One 采用当前链路的原因。添加 T2 意味着添加按模型划分的能力标志,而不是启用一个全局开关。
始终启用思考往往会关闭 T1 通道。 GLM、Kimi 的思考模型和 deepseek-reasoner 都会限制或拒绝强制工具选择,而 Anthropic 在思考处于启用状态时也会拒绝该选择。MiniMax 是一个反例。当通道关闭时,T2 是唯一剩下的 Schema 闸门选项,这也是缺失这一层级在中国模型部署中比在 OpenAI 部署中更重要的原因。
自托管会颠倒通常的排序。 约束解码是服务栈的属性,因此一个指令遵循能力远弱于前沿模型的本地 checkpoint 也可以使用它。最需要 Schema 闸门的模型,反而最有可能获得这一能力。
Bedrock预填陷阱
当为使用anthropic/前缀解析的模型传递response_format={"type":"json_object"}时,LiteLLM会在内部注入一条助手预填消息来模拟JSON模式。Anthropic Messages API没有原生的response_format参数,所以LiteLLM通过在助手内容前加一个开括号来近似实现:
role: "assistant"的对话——他们称之为”助手消息预填”并抛出错误:
- 模型使用
anthropic/前缀解析(通过域名匹配或URL路径提示)。 - 传递了
response_format={"type":"json_object"}(structured_llm_call中的json_mode代码路径)。 - 实际后端是AWS Bedrock(拒绝预填)。
json_mode_enabled标志消除了浪费的第2级调用。
修复方案:json_mode_enabled
每个模型的json_mode_enabled标志控制是否会尝试 Level 2(json_mode):
- 通过 DB 配置的模型:在管理员 → 模型 → 高级设置中切换。该标志存储在
ModelProviderModel.json_mode_enabled上(默认值为TRUE)。 - 通过 ENV 配置的模型:在环境中设置
LLM_JSON_MODE_ENABLED=false。 - 效果:禁用后,
abilities["json_mode"]返回False→不会传递response_format→不会进行预填充→Bedrock 可以正常工作。降级链变为native_fc → plain_text,完全跳过注定失败的json_mode调用。 - 跳过的代价:实际上,模型仍会返回有效的 JSON,因为系统提示词要求模型这样做,并且在现代模型上,
extract_json()能够可靠地解析自由格式的内容。失去的是保证,而不是输出:现在链路会在 T4 结束,此时除了提示词之外,没有任何机制约束结果。对于anthropic/路由来说,这种损失没有看起来那么大,因为模拟的 JSON 模式本来也不是解码器级别的保证。
思维模型 + 强制 tool_choice
多个提供商在启用扩展思维时拒绝强制tool_choice,理由是固定特定函数调用与模型先进行推理的自由度相矛盾:
structured_llm_call通过在原生FC级别传递reasoning_effort=None来自动解决冲突,这会关闭该次调用的思维功能(structured.py::_call_llm)。结构化输出需要模式合规性,而不是深度推理,因此在此处禁用思维既正确又更便宜。
当思维无法通过API关闭时,native_fc在每次结构化调用时都会以400失败,耗时约十秒后链条才会降级到json_mode。Kimi是常见情况:启用思维时仅支持auto,强制工具选择需要关闭思维,而Moonshot仅通过模型id暴露此选项(kimi-k2已关闭,kimi-k2.5和kimi-k2-thinking已启用)。FIM One没有翻转此选项的参数,因此补救措施是下面的tool_choice_enabled标志。
修复:tool_choice_enabled
一个针对每个模型的tool_choice_enabled 标志控制是否尝试 Level 1(native_fc):
- 数据库配置的模型:在 Admin → Models → Advanced → “Native Function Calling” 中切换。该标志存储在
ModelProviderModel.tool_choice_enabled上(默认为TRUE)。 - ENV 配置的模型:在环境中设置
LLM_TOOL_CHOICE_ENABLED=false。 - 效果:禁用时,
abilities["tool_choice"]返回False→ 降级链从 Level 2(json_mode)或 Level 3(plain_text)开始,完全跳过 native_fc。这消除了不兼容模型每次结构化调用约 10 秒的性能损失。 - ReAct 智能体不受影响:
tool_choice_enabled仅控制structured_llm_call中的强制工具选择。ReAct 引擎使用tool_choice="auto"(模型自由决定),无论此设置如何都适用于所有模型。
tool_choice_enabled 和 tool_call 是独立的能力标志。tool_call(对于 OpenAICompatibleLLM 始终为 True)控制工具是否被传递给模型 — 禁用它会破坏 ReAct 智能体。tool_choice 仅控制是否尝试强制工具选择以进行结构化输出提取。tool_choice="auto" 不受思考模式影响。ReAct 引擎专门使用 "auto",因此启用思考时智能体执行工作正常。
提供商迁移说明: 某些第三方中继会静默丢弃不支持的参数,如
reasoning_effort(drop_params=True),因此即使配置了思考也永远不会激活。迁移到正确支持思考的提供商(Bedrock、直接 Anthropic API)时,native_fc 中的 reasoning_effort=None 确保一致的行为。无需用户操作 — 结构化输出在所有提供商中的工作方式相同。提供商能力矩阵
本部分是每个提供商支持的功能以及FIM One如何处理这些功能的权威记录。每一行都命名了实现该行为的函数,因此此处的任何声明都可以根据代码进行验证。其他页面链接到此处而不是重复数据;当代码更改时,本部分也会随之更改。 一行描述的是提供商的协议,而不是单个模型。当同一系列中的模型存在差异时(DeepSeek聊天与推理器、Kimi启用思考与关闭思考),单元格会说明这一点。Table A: Protocol routing
How a configuredbase_url plus model becomes a LiteLLM call, and what happens when the first choice of interface is unavailable.
How GPT-5.x picks a protocol.
FIM_GPT5_RESPONSES_MODE selects it: native (the default) talks /v1/responses directly through litellm.aresponses, bridge uses LiteLLM’s chat-completions translation, and off forces plain chat completions. The native path exists because the bridge is lossy in the one place that matters: it discards the reasoning items, so a GPT-5.x agent re-derives its chain of thought on every tool round. Talking the protocol directly lets those items be replayed. A call that explicitly passes reasoning_effort=None, which is what structured_llm_call and the finish-signal probes do, stays on chat completions, because a call that wants no thinking has no reasoning state to preserve. The exception is models that cannot switch reasoning off (gpt-6.1-*, gpt-6-astra): their chat completions reject function tools at any reasoning_effort, so those calls stay on /v1/responses and run at the lowest effort, low. For the same reason off, or an endpoint without /v1/responses, leaves these models without tool calls.
Two properties of that native request are load-bearing and easy to get wrong:
store=falsekeeps the conversation stateless upstream, andinclude=["reasoning.encrypted_content"]asks for the encrypted payload to be returned. Without the include, the reasoning items arrive empty and replay silently becomes a no-op.- A replayed reasoning item must have its server-side
idstripped. Withstore=falsenothing is persisted upstream, so echoing the id back earnsItem with id 'rs_...' not found. Items are not persisted when 'store' is set to false. Theencrypted_contentblob carries the state on its own, so dropping the id costs nothing (sanitize_reasoning_item).
base_url in an agent’s inline model settings, does not go through LiteLLM at all (OpenAICompatibleLLM(untrusted_endpoint=True), _call_pinned). It must come with its own api_key: the platform’s keys are never used for it, and an empty key is refused. It is called as OpenAI-compatible chat completions at the URL as typed, by the OpenAI SDK on a dedicated HTTP client that refuses private, loopback, link-local and metadata addresses when it connects and does not follow redirects. The model name is sent as a field of the request and selects no route, provider or protocol; there is no path hint, no provider, no Responses route. When such an endpoint fails, the error names the kind of failure and the HTTP status, not the response body. Models on internal networks, or that need a provider’s native protocol, are added by an administrator under Admin → Models and selected by the agent.
Bedrock. Bedrock-hosted Claude follows the row it resolves to, not the fact that Bedrock is hosting it. Reached through an anthropic/-routed relay it inherits Anthropic protocol behaviour, including LiteLLM’s json-mode assistant prefill, which newer Bedrock versions reject. Reached through an OpenAI-compatible gateway it resolves as openai/, no prefill is injected, and json_mode_enabled can stay on.
表 B:冲突与解决方案
FIM One 发出四个tool_choice 状态中的三个:来自 ReAct 循环的 auto(react.py::_run_native)、来自结构化输出的命名函数(structured.py::_call_llm)以及当完成信号答案重放工具有效载荷时的 none。没有调用站点发出 required;该列记录提供商对非 auto 工具选择的约束,该约束同样适用于 required 和命名函数。
Table C: Thinking protocol
LLM_REASONING_EFFORT accepts low, medium and high; any other value is read as unset (deps.py::_reasoning_effort). What FIM One then puts on the wire is per-provider, and that is what this table records. The replay column is the return value of reasoning_replay_policy, which is a small closed set of four states rather than a per-provider list.
unsupported and informational_only produce the same bytes on the wire: both strip reasoning_content and signature from outgoing history. They differ in intent, so a model that clearly does reason but lands in unsupported is a gap in the fragment table rather than a live bug.
Relay/proxy gotchas
Third-party gateways fail in ways a direct provider does not, and most of those failures are silent. Each row below pairs the symptom with its mechanism and with what FIM One already does about it.Support boundary. FIM One guarantees the behaviour documented on this page for first-party endpoints: OpenAI’s own API, Anthropic, Google, and any vendor serving its own models directly. Third-party relays are supported on a best-effort basis and are not covered by that guarantee, because what a relay does to a request is outside our control and frequently outside its own documentation. A relay can drop a parameter, rewrite history, strip a cache breakpoint, or answer a protocol it only partially implements, and in most of those cases it returns a
200 rather than an error.This is a statement about what we promise, not a restriction on what runs. FIM One does not maintain an allowlist of approved hosts, and nothing here is gated on a domain. Capability is decided by what an endpoint actually does: a missing route answers 404 and is remembered, an ignored include yields empty reasoning items and the replay becomes a no-op, and a rejected request falls back for that call. Probing the endpoint is more accurate than inferring its capabilities from its hostname, and it is the only approach that keeps working for Azure OpenAI, enterprise gateways, and self-hosted proxies that implement the protocol correctly.If a relay misbehaves in a way the fallbacks do not catch, pin the protocol yourself with FIM_GPT5_RESPONSES_MODE (bridge or off) or the per-model tool_choice_enabled and json_mode_enabled toggles, and reproduce against the first-party endpoint before filing it as a FIM One bug.推荐的按模型配置
tool_choice_enabled和json_mode_enabled都可以在管理员→模型→高级设置中按模型切换。默认值都是TRUE,对大多数提供商都是正确的;仅在看到错误或浪费延迟时进行调整。哪些提供商需要调整已在上表B中记录,操作员填写的按模型视图位于模型管理。
环境变量级别覆盖适用于通过环境变量配置的所有模型(不是管理员UI):
Reasoning effort and thinking configuration
FIM One exposes two env vars for controlling extended thinking / reasoning (the reasoning tier has its own pair,REASONING_LLM_EFFORT and REASONING_LLM_BUDGET, falling back to these). They apply to the ENV-configured General model and to the Reasoning slot; the Fast model never gets reasoning, and General and Fast models from an active Model Group run without it:
Two behaviours follow automatically once thinking is on, and neither needs user configuration:
- Temperature is handled for you. On an
anthropic/route with thinking active,_build_request_kwargssendstemperature1.0 for Claude 4.5 and older, which is what Bedrock demands, and removestemperaturefor adaptive-thinking models (4.6 and newer). Models that reject sampling parameters outright (Opus 4.7 and 4.8, Fable 5, Mythos 5) havetemperatureremoved from the request entirely, thinking or not. Do not setLLM_TEMPERATURE=1by hand for this. - GPT-5.x keeps tools and reasoning together where it can. FIM One talks
/v1/responsesdirectly for GPT-5.x, because that is the only surface where the two combine. An endpoint with no/v1/responsesroute (404) falls back to chat completions and the verdict is cached per endpoint and model; a 400 falls back for that call only. On that path a request carryingtoolssends an explicitreasoning_effortofnone. Omitting the field is not equivalent, since the server default is notnone.
结构化输出的防御性解析
即使 native_fc 正常工作,结构化输出管道也包含一个防御性解析层,用于处理来自任何提供商或兼容性层的边界情况。 DAG 规划器的_dict_to_steps 解析器处理三个常见的边界情况:
-
单个对象而非数组。 某些模型返回
{"steps": {"id": "1", "task": "..."}}(单个步骤对象)而不是{"steps": [{"id": "1", "task": "..."}]}(数组)。解析器通过检查id或task键来检测这种情况,并将对象包装在列表中。 -
双重编码的 JSON 字符串。 当结构化输出降级到 json_mode(缺乏模式强制)时,某些提供商将
steps值作为 JSON 字符串而非原生数组返回 — 例如{"steps": "[{\"id\": \"1\", ...}]"}。这个字符串可能还包含字面换行符(来自模型的格式化),会破坏标准的json.loads。解析器使用extract_json_value()(包含_repair_json_strings)来处理:- JSON 字符串值内的字面换行符
- 无效的转义序列(常见于 LaTeX 或代码内容)
- 来自兼容性层的其他序列化问题
-
缺少
steps包装器。 模型可能返回单个步骤作为顶级对象,而没有steps包装键。解析器在根级别检测id和task,并相应地进行包装。
在正常操作下,native_fc 返回正确结构化的工具调用参数,这些边界情况不会出现。防御性解析器作为安全网存在,用于自定义
BaseLLM 子类、异常的提供商行为,或结构化输出降级到 json_mode 或 plain_text 的回退场景。提示词缓存(跨提供商)
FIM One 通过cache_control 断点实现 Anthropic 的显式提示词缓存,同时通过提示词部分注册表从其他所有提供商的自动前缀缓存中受益。目标是实现一条单一的提示词组装路径,在所有提供商中工作,而无需按调用的提示词形状差异。
架构
fim_one.core.prompt 模块公开三个基础元素:
PromptSection— 一个命名片段,包含静态content: str或动态content: CallablePromptRegistry— 一个记忆化存储(静态片段渲染一次,动态片段每次调用重新渲染)DYNAMIC_BOUNDARY— 一个哨兵标记,注册表在最后一个静态片段和第一个动态片段之间插入,以便调用者可以在缓存断点处分割渲染的提示词
- 静态前缀(~95% 的提示词)— 身份、核心指南、工具描述
- 动态后缀 — 当前日期时间、每个请求的语言指令、交接上下文
能力检测
fim_one.core.prompt.caching.is_cache_capable(model_id) 当模型 id 包含以下任何内容时返回 True:claude、anthropic、bedrock/anthropic、vertex_ai/claude。这些提供商接收两个 role="system" 消息,第一个(静态)消息带有 cache_control: {"type": "ephemeral"}。
所有其他提供商接收一个单一的连接系统消息,没有 cache_control 字段——这是必要的,因为非 Anthropic 端点要么拒绝该字段,要么静默丢弃它,通过某些中继发送它会导致 400 unknown parameter 错误。
跨提供商覆盖情况
对于支持自动前缀缓存的所有提供商,
PromptRegistry 都能「免费」带来收益——通过确保静态部分在每次调用之间保持字节内容一致(当前日期时间位于动态后缀中,而非前缀中),所有支持自动缓存的提供商都能匹配哈希并命中缓存。因此,即使不考虑 Anthropic 专属的 cache_control,Registry 也能带来基础性的无模型收益。
Observability
Everychat/* response’s done_payload now includes:
TurnProfiler emits a structured log line per turn: turn_cache conv=<id> turn=<n> model=claude-sonnet-4-6 read_tokens=1067 create_tokens=0 saved_input_tokens=961 (~90%). This also functions as a relay honesty probe — if you route through an API relay, compare actual billed input vs read_tokens to detect whether the relay strips cache_control or keeps the 0.10× discount.
No dollar estimate is returned at the LLM layer — pricing and relay markup are applied above, so the LLM layer only returns objective token counts.
多轮缓存 ROI
在 Claude 4 ReAct 轮次上测量,使用默认智能体提示词:
一个包含 10 个工具的 10 次迭代 ReAct 运行,在第一次之后的每一轮可节省约 8,640 个输入 token(9 次缓存命中 × 1067 token × 90%)。Anthropic 对第一次调用的缓存写入收费 1.25 倍,因此损益平衡点在第二次调用——单次查询不会受益。
推理重放策略(无模型正确性)
扩展思考/推理块在不同提供商之间的行为不同。统一的序列化策略会破坏协议契约和自动前缀缓存。fim_one.core.prompt.reasoning.reasoning_replay_policy(model_id) 返回四个值之一,并在 OpenAICompatibleLLM._build_request_kwargs() 中控制 ChatMessage.to_openai_dict(replay_policy=...) 的行为。
Four policies
anthropic_thinking— Claude family (includinganthropic/,bedrock/anthropic,vertex_ai/claude). Thinking blocks MUST be replayed withsignatureattached; Anthropic rejects subsequent turns if the signature is missing or altered.informational_only— models that emit CoT but do NOT expect replay: DeepSeek reasoning mode (deepseek-reasoneron V3.2, and the olderdeepseek-r1and R1-Distill ids the fragment table still matches), Qwen QwQ, Gemini flash-thinking, OpenAI o1 / o3 / o4. Their documentation explicitly says “do not sendreasoning_contentback in message history”. Sending it anyway:- Violates the provider contract (may start rejecting in future versions)
- Silently invalidates their automatic prefix cache — message bytes mutate on every turn, breaking the hash
openai_responses— GPT-5.x and later, matched on thegpt-5andgpt-6fragments. Its reasoning state is not text but a sequence of opaque items carrying encrypted payloads, and only/v1/responseshas a slot for them. On that protocol the items are replayed verbatim, which is what keeps the model’s chain of thought alive across tool rounds. The readable summary is still dropped from outgoing requests, so on the chat-completions fallback this behaves exactly likeinformational_only. Checked before the informational fragments, whose genericreasoningentry would otherwise swallow proxy-tagged GPT-5 ids.unsupported— the catch-all: models with no reasoning capability (GPT-4o, Gemini 1.5, Mistral, Llama), and reasoning models whose id matches no fragment (GLM, MiniMax, Kimi, Doubao). No field should be replayed either way, so this policy puts the same bytes on the wire asinformational_only. It is also the safe default for unknown model ids.
reasoning_content and the opaque reasoning_items are independent fields on ChatMessage. to_openai_dict() never serialises the items at all, so they are structurally incapable of leaking onto a chat-completions request, whatever the policy says.
执行
所有策略评估都在一个地方进行(_build_request_kwargs)。ChatMessage.to_openai_dict(replay_policy=None) 保留了 A3 宽松的默认设置,以便不协调的调用者不会回退。跨提供商测试矩阵位于 tests/test_reasoning_replay_policy.py 中,反向断言证明非 Anthropic 请求不会泄露 reasoning_content。
对于用户
特性和错误行为都是自动的 — 您无需配置任何内容。工作流影响:- 如果您在同一对话中在 Claude 和 DeepSeek 智能体之间切换,历史记录会完整保存思考块;在下一轮中,传出消息形状会根据当前模型进行调整。
- 如果您使用代理 / 自定义
BaseLLM子类,请确保其模型 id 是可识别的(包含其中一个片段),否则默认的unsupported策略将适用 — 这是安全的,但意味着异常代理后的 Claude 可能会丢失思考重放。将模型 id 片段添加到_CACHE_CAPABLE_MODEL_FRAGMENTS(在core/prompt/caching.py中)和/或推理策略查找。
Troubleshooting
“This model does not support assistant message prefill” Bedrock + json_mode. Two fixes: (1) setLLM_JSON_MODE_ENABLED=false or disable JSON Mode in the admin model settings; or (2) if your Bedrock provider offers an OpenAI-compatible /v1/chat/completions endpoint, switch to that — FIM One resolves it as openai/ and the prefill injection never occurs.
“Thinking may not be enabled when tool_choice forces tool use” / “tool_choice ‘specified’ is incompatible with thinking enabled”
For Anthropic models, structured_llm_call disables thinking for native_fc calls automatically. Where thinking cannot be turned off through the API, such as kimi-k2.5 and kimi-k2-thinking or deepseek-reasoner, disable “Native Function Calling” in the model’s Advanced settings, or set LLM_TOOL_CHOICE_ENABLED=false globally. The degradation chain will skip native_fc and extract structured output via json_mode or plain_text instead. Check Table B of the Provider Capability Matrix before assuming a thinking model has this problem; MiniMax does not.
“DAG pipeline failed: LLM ‘steps’ is not an array”
The LLM returned the steps field as a string or single object instead of an array. This typically means structured output fell through to json_mode (which lacks schema enforcement). Check the log for structured_llm_call: level=xxx — if it shows json_mode instead of native_fc, native_fc is failing silently. If using a custom BaseLLM subclass, verify it accepts the reasoning_effort kwarg.
ReAct falls back to JSON mode unexpectedly
Check that the model’s abilities["tool_call"] is True. This is always True for OpenAICompatibleLLM, but a custom BaseLLM subclass might override it.
structured_llm_call exhausts all levels and raises StructuredOutputError
The model failed to produce parseable JSON at any level. This is rare with modern models. Check: (1) the schema is valid JSON Schema, (2) the model has enough max_tokens to produce the full response, (3) the system prompt is not contradicting the schema instructions. The DAG planner and analyzer both provide default_value fallbacks, so this error only propagates from call sites that explicitly omit defaults.