Skip to content

fix(moonshot): enforce temperature=1 for all Kimi K2 / thinking models#87

Open
ChenglongWang wants to merge 1 commit into
devfrom
fix/moonshot-kimi-temperature-enforce
Open

fix(moonshot): enforce temperature=1 for all Kimi K2 / thinking models#87
ChenglongWang wants to merge 1 commit into
devfrom
fix/moonshot-kimi-temperature-enforce

Conversation

@ChenglongWang
Copy link
Copy Markdown
Contributor

Summary

Fixes the runtime error:

Error calling LLM: litellm.BadRequestError: MoonshotException -
invalid temperature: only 1 is allowed for this model

Root cause: Moonshot enforces temperature=1 on the entire Kimi K2 family (kimi-k2, kimi-k2-turbo, kimi-k2.5, kimi-k2.5-turbo, future k2.x...) and on thinking / reasoning preview models (kimi-thinking-preview, kimi-k2-thinking, ...). The registry only matched the literal substring kimi-k2.5, so every other affected variant let the caller's 0.7 through and got a 400 back.

Changes

  • mira_engine/providers/registry.py — broaden Moonshot model_overrides from ("kimi-k2.5", ...) to two prefixes that cover the whole family:
    • kimi-k2 — matches kimi-k2, kimi-k2-turbo, kimi-k2.5, kimi-k2.5-turbo, future k2.6+
    • kimi-thinking — matches kimi-thinking-preview and similar reasoning previews
  • mira_engine/providers/litellm_provider.py — defensive runtime fallback: if the API still rejects the request with an only 1 is allowed / must be 1 style error, retry once with temperature=1.0. Guards against future Moonshot variants we haven't registered overrides for yet. No infinite-retry risk — we don't retry if temperature is already 1.0.
  • tests/providers/test_litellm_provider.py — 8 new tests:
    • K2 family + thinking models get clamped to 1.0
    • moonshot-v1-* pass-through preserved (caller temperature kept)
    • Error-message recognition (3 wording variants) and negative cases
    • One retry path on rejection → success
    • No-retry-loop when temperature is already 1.0

Test plan

  • pytest tests/providers/test_litellm_provider.py — 9/9 ✅
  • pytest tests/providers/ tests/test_model_routing.py — 244/244 ✅
  • Manual: hit a Kimi K2 / thinking model from the agent with default temperature, confirm no 400.

Moonshot rejects any temperature other than 1 for the entire Kimi K2
family (kimi-k2, kimi-k2-turbo, kimi-k2.5, kimi-k2.5-turbo, ...) and
the thinking/reasoning preview models, but the registry only matched
the literal string "kimi-k2.5", so other variants returned:

  litellm.BadRequestError: MoonshotException - invalid temperature:
  only 1 is allowed for this model

Fix in two layers:

1. Broaden the Moonshot model_overrides patterns to "kimi-k2" and
   "kimi-thinking" so all current and future K2 / thinking variants
   are clamped to temperature=1.0 before the request leaves the client.

2. Add a runtime fallback in LiteLLMProvider.chat(): if the provider
   still rejects the request with an "only 1 is allowed" / "must be 1"
   style error, retry once with temperature=1.0 instead of surfacing
   the error to the user. Guards against future Moonshot releases we
   haven't registered overrides for yet.

Tests cover override matching for the K2 / thinking family, the
moonshot-v1-* pass-through, error-message detection, the single retry
path, and the no-infinite-loop guard.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant