From aeb06bf4ef62fe69216a972825303edd3c33f04d Mon Sep 17 00:00:00 2001 From: Jim Dawdy Date: Wed, 13 May 2026 20:08:11 -0500 Subject: [PATCH] fix(agents): apply MiMo reasoning_content fallback wrapper for unowned proxy providers --- src/agents/pi-embedded-runner/extra-params.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/agents/pi-embedded-runner/extra-params.ts b/src/agents/pi-embedded-runner/extra-params.ts index 773813a6372..8f7ff82a309 100644 --- a/src/agents/pi-embedded-runner/extra-params.ts +++ b/src/agents/pi-embedded-runner/extra-params.ts @@ -752,6 +752,17 @@ function applyPostPluginStreamWrappers( shouldPatchModel: isDeepSeekV4OpenAICompatibleModel, }); + // MiMo reasoning models use the same DeepSeek-style reasoning_content wire + // format. When MiMo is reached through an unowned proxy/custom provider + // (e.g. `xiaomi-orbit` pointed at token-plan-*.xiaomimimo.com), the bundled + // xiaomi plugin's wrapStreamFn does not fire, so apply the shared wrapper + // here as a fallback so multi-turn tool calls succeed. + ctx.agent.streamFn = createDeepSeekV4OpenAICompatibleThinkingWrapper({ + baseStreamFn: ctx.agent.streamFn, + thinkingLevel: ctx.thinkingLevel, + shouldPatchModel: isMiMoReasoningOpenAICompatibleModel, + }); + // Guard Google-family payloads against invalid negative thinking budgets // emitted by upstream model-ID heuristics for Gemini 3.1 variants. ctx.agent.streamFn = createGoogleThinkingPayloadWrapper(ctx.agent.streamFn, ctx.thinkingLevel); @@ -831,6 +842,22 @@ function isDeepSeekV4OpenAICompatibleModel(model: Parameters[0]): bool ); } +const MIMO_REASONING_OPENAI_COMPATIBLE_MODEL_IDS = new Set([ + "mimo-v2-pro", + "mimo-v2-omni", + "mimo-v2.5", + "mimo-v2.5-pro", +]); + +function isMiMoReasoningOpenAICompatibleModel(model: Parameters[0]): boolean { + const normalizedModelId = normalizeDeepSeekV4CandidateId(model.id); + return ( + model.api === "openai-completions" && + normalizedModelId !== undefined && + MIMO_REASONING_OPENAI_COMPATIBLE_MODEL_IDS.has(normalizedModelId) + ); +} + /** * Apply extra params (like temperature) to an agent's streamFn. * Also applies verified provider-specific request wrappers, such as OpenRouter attribution.