fix: add Kimi K3 1M context window to DEFAULT_CONTEXT_LENGTHS

Kimi K3 ships with a 1M-token context window (verified against
platform.kimi.ai/docs/overview) but was falling through to the generic
'kimi': 262144 catch-all. Added 'kimi-k3': 1_000_000 before the catch-all
so longest-key-first substring matching resolves K3 to 1M while older
Kimi models still hit the 256K default.

Added matching test_kimi_k3_context_1m test covering native,
vendor-prefixed (kimi/, moonshotai/), and older model fallback.
This commit is contained in:
datachainsystems 2026-07-20 00:11:41 +03:00 committed by Teknium
parent 77aa026ca6
commit 54c39c0301
2 changed files with 29 additions and 1 deletions

View file

@ -319,7 +319,10 @@ DEFAULT_CONTEXT_LENGTHS = {
"grok-3": 131072, # grok-3, grok-3-mini, grok-3-fast, grok-3-mini-fast
"grok-2": 131072, # grok-2, grok-2-1212, grok-2-latest
"grok": 131072, # catch-all (grok-beta, unknown grok-*)
# Kimi
# Kimi — K3 ships with a 1M context window (verified: platform.kimi.ai/docs/overview).
# Longest-key-first substring matching ensures "kimi-k3" resolves to 1M
# while older/unknown Kimi models still hit the generic 256K fallback.
"kimi-k3": 1_000_000,
"kimi": 262144,
# Upstage Solar — api.upstage.ai/v1/models does not return context_length,
# so these fallbacks keep token budgeting / compression from probing down

View file

@ -332,6 +332,31 @@ class TestDefaultContextLengths:
assert get_model_context_length("glm-5") == 202752
assert get_model_context_length("glm-5.1") == 202752
def test_kimi_k3_context_1m(self):
"""Kimi K3 must resolve to 1M, not the generic Kimi fallback of 256K.
Context window verified against platform.kimi.ai/docs/overview
(2026-07). Kimi K3 is the current flagship model with a 1M-token
context window.
"""
from agent.model_metadata import get_model_context_length
from unittest.mock import patch as mock_patch
assert DEFAULT_CONTEXT_LENGTHS["kimi-k3"] == 1_000_000
assert DEFAULT_CONTEXT_LENGTHS["kimi"] == 262144
with mock_patch("agent.model_metadata.fetch_model_metadata", return_value={}), \
mock_patch("agent.model_metadata.fetch_endpoint_model_metadata", return_value={}), \
mock_patch("agent.model_metadata.get_cached_context_length", return_value=None):
# Kimi K3 (1M) must NOT fall through to the generic 256K entry
assert get_model_context_length("kimi-k3") == 1_000_000
# Vendor-prefixed forms (kimi provider, openrouter)
assert get_model_context_length("kimi/kimi-k3") == 1_000_000
assert get_model_context_length("moonshotai/kimi-k3") == 1_000_000
# Older/unknown Kimi models still resolve to 256K fallback
assert get_model_context_length("kimi-k2.6") == 262144
assert get_model_context_length("kimi-k2") == 262144
def test_openrouter_live_metadata_beats_hardcoded_catchall(self):
"""OpenRouter-routed slugs resolve via the live OR catalog before the
hardcoded family catch-all.