快速结论:在 LiteLLM 中通过 mistral/…(以及 codestral、vertex_ai 上的 Mistral 模型)发起带命名 tool_choice 的请求时,对象形式的强制工具选择会被静默丢弃,模型不会调用指定工具。优先确认你的 tool_choice 是否为对象形式,并升级到包含 #39737 修复的版本。
适用环境:Issue 中确认的复现环境为 LiteLLM 1.101.0(提交 c8635ecc67bb6db47525a48374ad6009bf28801f),并报告在 v1.106.2 及当时 main 分支仍存在;使用 Mistral 官方 API(含 api.eu.mistral.ai)。Issue 未提供操作系统、Python、CUDA 或显卡信息。
最快修复方案:升级到已合并 PR #39737 的 LiteLLM 版本,使 MistralConfig.map_openai_params 能传递对象形式的 tool_choice。Issue 中未给出具体版本号,请以发布说明或当前 main 为准。
注意事项:该问题只影响对象形式,枚举值(none、auto、any、required)不受影响。由于参数被静默跳过,无论 drop_params 如何设置都不会报错或告警,因此不能依赖日志发现此问题。若同一模型组混用 openai/… 与 mistral/… 部署,修复前路由命中不同部署时行为会不一致。
问题场景
用户通过 LiteLLM Proxy 的 /v1/chat/completions 调用 mistral-large(底层为 mistral/mistral-large-latest),请求中携带一个 get_weather 工具,并用 "tool_choice": {"type": "function", "function": {"name": "get_weather"}} 强制模型调用该工具。期望返回被强制的工具调用,实际返回普通文本回答,finish_reason 为 stop 且消息中无 tool_calls。相同请求直接发往 https://api.mistral.ai/v1/chat/completions 则返回 finish_reason: "tool_calls",说明问题出在网关侧。
报错原文
[Bug]: mistral drops a named tool_choice, so the pinned tool is never called
# openai 'tool_choice' object param not supported by Mistral API
MistralConfig.map_openai_params only maps tool_choice when it is a str
原因分析
根因位于 MistralConfig.map_openai_params:该映射只在 tool_choice 为字符串(枚举形式)时才处理,对象形式被直接跳过,且不抛错、不打告警。因此请求到达 Mistral 时只带 tools 而没有 tool_choice,模型自行决定是否调用工具。Issue 中同时指出 _map_tool_choice 内“不支持对象参数”的注释已过时:Mistral API 实际上支持命名形式,第三方模型(如 deepseek-v4-1-flash-1017)经 Mistral 接口调用时同样生效。由于 codestral 和 vertex_ai 上的 Mistral 模型复用同一参数映射,三处均受影响。
环境排查
- 确认 LiteLLM 版本:1.101.0 可复现,v1.106.2 仍存在;查看是否已包含 #39737 的合并。
- 确认调用路径:使用的模型前缀是
mistral/、codestral还是在vertex_ai上的 Mistral 模型。 - 确认请求体中
tool_choice的类型:对象形式受影响,字符串枚举不受影响。 - 确认是否混用多个提供商部署同一模型组(如
openai/…与mistral/…),以排除路由差异导致的偶发表现。 - Issue 未提供操作系统、Python、CUDA、PyTorch 或显卡版本,这些项不作为必要条件排查。
解决步骤
- 先将同一请求体直接发往 Mistral 官方 API 验证:若返回
finish_reason: "tool_calls"且包含指定工具调用,说明请求构造正确,问题在 LiteLLM 侧。 - 检查当前 LiteLLM 版本及对应代码,确认
MistralConfig.map_openai_params是否仍只处理字符串形式的tool_choice。 - 升级到包含 PR #39737 的 LiteLLM 版本(该 PR 已 rebase 到当时 main 并解决冲突,随后合并)。
- 可优先尝试:重启代理后重新发送原请求,不要通过设置
drop_params规避,因为该问题不会因drop_params取值不同而改变。
验证方法
重发原请求:若返回 200、finish_reason 为 tool_calls,且消息中包含名为 get_weather 的工具调用,与直连 Mistral API 的响应结构一致,则问题已解决。同时可核对日志中发往 Mistral 的请求确实携带了对象形式的 tool_choice。
参考来源
AI 工具推荐
想把多个 AI 模型放在一个入口?
GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。
推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。
这个方案解决了吗?
可以继续搜索完整报错,或查看同一工具的其他排查指南。


