Skip to content

fix: add Kimi K3 1M context window to DEFAULT_CONTEXT_LENGTHS - #67685

Closed
datachainsystems wants to merge 1 commit into
NousResearch:mainfrom
datachainsystems:fix/kimi-k3-1m-context
Closed

datachainsystems wants to merge 1 commit into
NousResearch:mainfrom
datachainsystems:fix/kimi-k3-1m-context

Conversation

@datachainsystems

Copy link
Copy Markdown

Summary

Kimi K3 ships with a 1M-token context window (verified: platform.kimi.ai/docs/overview) but was falling through to the generic "kimi": 262144 catch-all in DEFAULT_CONTEXT_LENGTHS.

Change

  • Added "kimi-k3": 1_000_000 before the "kimi": 262144 catch-all in agent/model_metadata.py
  • Longest-key-first substring matching ensures K3 resolves to 1M while older/unknown Kimi models still hit the 256K default
  • Added test_kimi_k3_context_1m covering native, vendor-prefixed (kimi/, moonshotai/), and older model (kimi-k2.6, kimi-k2) fallback verification

Verification

tests/agent/test_model_metadata.py::TestDefaultContextLengths::test_kimi_k3_context_1m PASSED
tests/agent/test_model_metadata.py - 122/122 passed, 0 failed

Pattern

Same longest-key-first approach used by DeepSeek V4 (#...), GLM-5.2 (#...), and others.

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.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/kimi Kimi / Moonshot P3 Low — cosmetic, nice to have needs-decision Awaiting maintainer decision before any implementation sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Jul 19, 2026
@alt-glitch

Copy link
Copy Markdown

This was generated by AI during triage.

Related to open #67115. Both address Kimi K3 context sizing, but this PR changes the global default fallback while #67115 keeps the repair scoped to canonical Kimi Coding endpoints; please choose the intended contract.

@datachainsystems

Copy link
Copy Markdown
Author

Thanks for the triage. I reviewed #67115 and believe #67685 is the correct approach — here's why:

#67115 fixes _endpoint_scoped_context_length which only triggers for api.kimi.com/coding endpoints. But the default base_url in the kimi-coding plugin is https://api.moonshot.ai/v1 — where most users access Kimi K3. That path would still fall through to 262K.

#67685 fixes DEFAULT_CONTEXT_LENGTHS globally — the same mechanism used by DeepSeek V4, GLM-5.2, Qwen3.6, and every other model family. The model's context window is a property of the model, not the provider. Kimi K3 has 1M context regardless of which endpoint you reach it through.

The endpoint-scoped path already handles the bare k3 slug specifically for api.kimi.com/coding. The DEFAULT_CONTEXT_LENGTHS entry handles the public-facing kimi-k3 slug for all endpoints. These are complementary, not competing — both should land.

If there's a concern about legacy Moonshot keys that don't serve K3 returning 1M for kimi-k3: those keys wouldn't expose a kimi-k3 model in the first place, so the fallback is never reached for them.

teknium1 added a commit that referenced this pull request Jul 20, 2026
…aces

Follow-up widening for salvaged PRs #67115, #67685, #67620:

- _PROVIDER_MODELS: add kimi-k3 atop kimi-coding / moonshot / opencode-go
  curated lists (kimi-coding-cn covered by cherry-picked #67620)
- setup.py _DEFAULT_PROVIDER_MODELS: kimi-k3 for kimi-coding(-cn) + opencode-go
- model_metadata: align DEFAULT_CONTEXT_LENGTHS kimi-k3 entry to 1,048,576
  (matches endpoint-scoped override, models.dev, and OpenRouter live metadata)
- anthropic_adapter: classify the bare Coding Plan slug 'k3' (and k3.x/k3-*)
  as Kimi family so adaptive thinking applies on proxied endpoints
- moonshot_schema: is_moonshot_model matches bare 'k3' so tool-schema
  sanitization runs on the chat-completions path
- contributor mappings for githubespresso407, datachainsystems, Punyko8

Tests: 582 passed across 11 targeted files; hermetic E2E verifies picker
order (kimi-k3 first), no dupes, and 1M context resolution.
@teknium1

Copy link
Copy Markdown
Collaborator

Merged via PR #68108 — your commit was cherry-picked onto current main with your authorship preserved in git log. Thanks for the fix! The salvage also widened the rollout to the remaining Kimi-direct catalog surfaces (curated picker lists, setup defaults, and bare-slug family classification).

@teknium1 teknium1 closed this Jul 20, 2026
randlee pushed a commit to randlee/hermes-agent that referenced this pull request Aug 11, 2026
…aces

Follow-up widening for salvaged PRs NousResearch#67115, NousResearch#67685, NousResearch#67620:

- _PROVIDER_MODELS: add kimi-k3 atop kimi-coding / moonshot / opencode-go
  curated lists (kimi-coding-cn covered by cherry-picked NousResearch#67620)
- setup.py _DEFAULT_PROVIDER_MODELS: kimi-k3 for kimi-coding(-cn) + opencode-go
- model_metadata: align DEFAULT_CONTEXT_LENGTHS kimi-k3 entry to 1,048,576
  (matches endpoint-scoped override, models.dev, and OpenRouter live metadata)
- anthropic_adapter: classify the bare Coding Plan slug 'k3' (and k3.x/k3-*)
  as Kimi family so adaptive thinking applies on proxied endpoints
- moonshot_schema: is_moonshot_model matches bare 'k3' so tool-schema
  sanitization runs on the chat-completions path
- contributor mappings for githubespresso407, datachainsystems, Punyko8

Tests: 582 passed across 11 targeted files; hermetic E2E verifies picker
order (kimi-k3 first), no dupes, and 1M context resolution.
prmartinow pushed a commit to prmartinow/hermes-agent that referenced this pull request Aug 26, 2026
…aces

Follow-up widening for salvaged PRs NousResearch#67115, NousResearch#67685, NousResearch#67620:

- _PROVIDER_MODELS: add kimi-k3 atop kimi-coding / moonshot / opencode-go
  curated lists (kimi-coding-cn covered by cherry-picked NousResearch#67620)
- setup.py _DEFAULT_PROVIDER_MODELS: kimi-k3 for kimi-coding(-cn) + opencode-go
- model_metadata: align DEFAULT_CONTEXT_LENGTHS kimi-k3 entry to 1,048,576
  (matches endpoint-scoped override, models.dev, and OpenRouter live metadata)
- anthropic_adapter: classify the bare Coding Plan slug 'k3' (and k3.x/k3-*)
  as Kimi family so adaptive thinking applies on proxied endpoints
- moonshot_schema: is_moonshot_model matches bare 'k3' so tool-schema
  sanitization runs on the chat-completions path
- contributor mappings for githubespresso407, datachainsystems, Punyko8

Tests: 582 passed across 11 targeted files; hermetic E2E verifies picker
order (kimi-k3 first), no dupes, and 1M context resolution.
melon-xf added a commit to melon-xf/hermes-agent that referenced this pull request Sep 3, 2026
…aces

Follow-up widening for salvaged PRs NousResearch#67115, NousResearch#67685, NousResearch#67620:

- _PROVIDER_MODELS: add kimi-k3 atop kimi-coding / moonshot / opencode-go
  curated lists (kimi-coding-cn covered by cherry-picked NousResearch#67620)
- setup.py _DEFAULT_PROVIDER_MODELS: kimi-k3 for kimi-coding(-cn) + opencode-go
- model_metadata: align DEFAULT_CONTEXT_LENGTHS kimi-k3 entry to 1,048,576
  (matches endpoint-scoped override, models.dev, and OpenRouter live metadata)
- anthropic_adapter: classify the bare Coding Plan slug 'k3' (and k3.x/k3-*)
  as Kimi family so adaptive thinking applies on proxied endpoints
- moonshot_schema: is_moonshot_model matches bare 'k3' so tool-schema
  sanitization runs on the chat-completions path
- contributor mappings for githubespresso407, datachainsystems, Punyko8

Tests: 582 passed across 11 targeted files; hermetic E2E verifies picker
order (kimi-k3 first), no dupes, and 1M context resolution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint needs-decision Awaiting maintainer decision before any implementation P3 Low — cosmetic, nice to have provider/kimi Kimi / Moonshot sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants