hermes - 💡(How to fix) Fix [Bug]: discord-kimi-context-bug-issue

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Error Traceback (from gateway.log)

ValueError: Model kimi-k2.6 has a context window of 32,768 tokens, which is below the minimum 64,000 required by Hermes Agent. Choose a model with at least 64K context, or set model.context_length in config.yaml to override.

Full traceback:

File ".../gateway/run.py", line 6744, in _handle_message_with_agent agent_result = await self._run_agent(...) File ".../gateway/run.py", line 14596, in _run_agent response = _executor_task.result() File ".../gateway/run.py", line 13849, in run_sync agent = AIAgent(...) File ".../run_agent.py", line 2103, in init raise ValueError(...)

Root Cause

When using Kimi Coding (kimi-k2.6 via api.kimi.com/coding) as the main model, the Discord gateway receives messages but fails to respond because AIAgent.__init__ raises a ValueError during agent initialization.

Fix Action

Fix / Workaround

  • Context length is detected as 32,768 tokens (incorrect)
  • AIAgent.__init__ crashes with ValueError
  • Gateway silently fails to respond — inbound messages are processed but agent dies before generating a reply
  • User must manually set model.context_length: 262144 in config.yaml as a workaround
This bug makes the Discord gateway completely non-functional for Kimi Coding users without the manual workaround. Since the gateway appears "online" (Discord shows the bot as connected), users may not realize messages are failing silently until they check `gateway.log`.

## Workaround (for users hitting this now)

Code Example

### Error Traceback (from `gateway.log`)


ValueError: Model kimi-k2.6 has a context window of 32,768 tokens, which is below the minimum 64,000 required by Hermes Agent.  Choose a model with at least 64K context, or set model.context_length in config.yaml to override.


Full traceback:

  File ".../gateway/run.py", line 6744, in _handle_message_with_agent
    agent_result = await self._run_agent(...)
  File ".../gateway/run.py", line 14596, in _run_agent
    response = _executor_task.result()
  File ".../gateway/run.py", line 13849, in run_sync
    agent = AIAgent(...)
  File ".../run_agent.py", line 2103, in __init__
    raise ValueError(...)

---

This bug makes the Discord gateway completely non-functional for Kimi Coding users without the manual workaround. Since the gateway appears "online" (Discord shows the bot as connected), users may not realize messages are failing silently until they check `gateway.log`.

Related: The `DISCORD_ALLOWED_CHANNELS` filtering can compound confusion — users may think the issue is channel permissions when it's actually the context length crash.

---

{
  "id": "kimi-for-coding",
  "object": "model",
  "context_length": 262144
}

---

hermes config set model.context_length 262144
hermes gateway restart
RAW_BUFFERClick to expand / collapse

Bug Description

When using Kimi Coding (kimi-k2.6 via api.kimi.com/coding) as the main model, the Discord gateway receives messages but fails to respond because AIAgent.__init__ raises a ValueError during agent initialization.

The error claims the model has a 32,768 token context window, which is below Hermes' 64,000 minimum. However, the actual kimi-k2.6 / kimi-for-coding model supports 262,144 tokens. The incorrect 32K value appears to come from stale/fallback metadata (possibly OpenRouter) rather than the live Kimi Coding endpoint.

Steps to Reproduce

  1. Set main provider to Kimi Coding (api.kimi.com/coding)
  2. Set model to kimi-k2.6 (or let it resolve to kimi-for-coding)
  3. Start gateway: hermes gateway run
  4. Send any message to the Discord bot
  5. Message appears in log as inbound message, but bot never replies
  6. gateway.log shows ValueError on every incoming message

Expected Behavior

  • Kimi Coding models should correctly report their context length (262,144 tokens for kimi-for-coding / kimi-k2.6)
  • Discord gateway should spawn agents successfully and reply to messages
  • No manual model.context_length override should be needed

Actual Behavior

  • Context length is detected as 32,768 tokens (incorrect)
  • AIAgent.__init__ crashes with ValueError
  • Gateway silently fails to respond — inbound messages are processed but agent dies before generating a reply
  • User must manually set model.context_length: 262144 in config.yaml as a workaround

Affected Component

Gateway (Telegram/Discord/Slack/WhatsApp), Agent Core (conversation loop, context compression, memory)

Messaging Platform (if gateway-related)

Discord

Debug Report

### Error Traceback (from `gateway.log`)


ValueError: Model kimi-k2.6 has a context window of 32,768 tokens, which is below the minimum 64,000 required by Hermes Agent.  Choose a model with at least 64K context, or set model.context_length in config.yaml to override.


Full traceback:

  File ".../gateway/run.py", line 6744, in _handle_message_with_agent
    agent_result = await self._run_agent(...)
  File ".../gateway/run.py", line 14596, in _run_agent
    response = _executor_task.result()
  File ".../gateway/run.py", line 13849, in run_sync
    agent = AIAgent(...)
  File ".../run_agent.py", line 2103, in __init__
    raise ValueError(...)

Operating System

Ubuntu 24.04 (Linux 6.8.0-110-generic)

Python Version

3.11.15

Hermes Version

latest main (as of 2026-05-12)

Additional Logs / Traceback (optional)

This bug makes the Discord gateway completely non-functional for Kimi Coding users without the manual workaround. Since the gateway appears "online" (Discord shows the bot as connected), users may not realize messages are failing silently until they check `gateway.log`.

Related: The `DISCORD_ALLOWED_CHANNELS` filtering can compound confusion — users may think the issue is channel permissions when it's actually the context length crash.

Root Cause Analysis (optional)

The context length detection likely falls through to stale metadata. Kimi Coding's live /coding/v1/models endpoint reports:

{
  "id": "kimi-for-coding",
  "object": "model",
  "context_length": 262144
}

But the public slug kimi-k2.6 may resolve through OpenRouter or another fallback path that reports 32,768. The validation in run_agent.py line ~2103 uses this incorrect value and rejects the model.

Proposed Fix (optional)

Option A (preferred): Update the Kimi Coding provider adapter to query the live /coding/v1/models endpoint and use the returned context_length directly, bypassing stale cached metadata.

Option B: Add a hardcoded context length map for known Kimi models (kimi-for-coding → 262144, kimi-k2.6 → 262144) in the Kimi provider adapter, similar to how other providers handle model aliases.

Option C: Lower the minimum context threshold or make it provider-aware, though this is less ideal since it masks real capacity issues.

Workaround (for users hitting this now)

hermes config set model.context_length 262144
hermes gateway restart

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING