Skip to content

[Bug]: ## ## 问题描述 当使用上下文窗口大小小于 64,000 tokens 的模型时,即使在 config.yaml 中设置了 model.context_length,仍然会收到错误: #8430

@fangbb-coder

Description

@fangbb-coder

Bug Description

错误信息提示可以通过设置 model.context_length 来覆盖,但实际上这个设置被忽略了。

复现步骤

  1. 在 config.yaml 中设置:
    model:
      default: Qwen3-235B-A22B
      provider: custom
      base_url: https://api.scnet.cn/api/llm/v1
      api_mode: chat_completions
      context_length: 32768
  2. 启动 Hermes Agent
  3. 尝试发送消息,会收到上下文窗口大小错误

期望行为

当用户在 config.yaml 中明确设置了 model.context_length 时,应该尊重用户的设置,绕过最小长度检查。

实际行为

即使设置了 model.context_length,仍然会检查这个值是否小于 64,000 tokens,并触发错误。

解决方案

修改 run_agent.py 文件中的上下文长度检查逻辑,在用户明确设置了 context_length 时跳过最小长度检查:

# Skip minimum context length check if user explicitly set context_length in config
if _ctx and _ctx < MINIMUM_CONTEXT_LENGTH and self._config_context_length is None:
    raise ValueError(
        f"Model {self.model} has a context window of {_ctx:,} tokens, "
        f"which is below the minimum {MINIMUM_CONTEXT_LENGTH:,} required "
        f"by Hermes Agent.  Choose a model with at least "
        f"{MINIMUM_CONTEXT_LENGTH // 1000}K context, or set "
        f"model.context_length in config.yaml to override."
    )

环境信息

  • Hermes Agent 版本:最新版本
  • 操作系统:Linux
  • 模型:Qwen3-235B-A22B (上下文窗口大小:32,768 tokens)

Steps to Reproduce

Model Qwen3-235B-A22B 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.

错误信息提示可以通过设置 `model.context_length` 来覆盖,但实际上这个设置被忽略了。

## 复现步骤
1. 在 config.yaml 中设置:
   ```yaml
   model:
     default: Qwen3-235B-A22B
     provider: custom
     base_url: https://api.scnet.cn/api/llm/v1
     api_mode: chat_completions
     context_length: 32768
  1. 启动 Hermes Agent
  2. 尝试发送消息,会收到上下文窗口大小错误

Expected Behavior

当用户在 config.yaml 中明确设置了 model.context_length 时,应该尊重用户的设置,绕过最小长度检查。

Actual Behavior

即使设置了 model.context_length ,仍然会检查这个值是否小于 64,000 tokens,并触发错误

Affected Component

Gateway (Telegram/Discord/Slack/WhatsApp)

Messaging Platform (if gateway-related)

No response

Operating System

Ubuntu 24.04.4 LTS (Noble Numbat)

Python Version

Python 3.12.3

Hermes Version

v2026.4.8-461-g4eecaf06

Relevant Logs / Traceback

- - Hermes Agent 版本:最新版本
- 操作系统:Linux
- 模型:Qwen3-235B-A22B (上下文窗口大小:32,768 tokens)
-

Root Cause Analysis (optional)

No response

Proposed Fix (optional)

修改 run_agent.py 文件中的上下文长度检查逻辑,在用户明确设置了 context_length 时跳过最小长度检查:

# Skip minimum context length check if user explicitly set context_length 
in config
if _ctx and _ctx < MINIMUM_CONTEXT_LENGTH and self._config_context_length 
is None:
    raise ValueError(
        f"Model {self.model} has a context window of {_ctx:,} tokens, "
        f"which is below the minimum {MINIMUM_CONTEXT_LENGTH:,} required "
        f"by Hermes Agent.  Choose a model with at least "
        f"{MINIMUM_CONTEXT_LENGTH // 1000}K context, or set "
        f"model.context_length in config.yaml to override."
 

Are you willing to submit a PR for this?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions