Skip to content

fix(agent): respect model.context_length config#37548

Open
vivganes wants to merge 1 commit into
NousResearch:mainfrom
vivganes:patch-fix-8430
Open

fix(agent): respect model.context_length config#37548
vivganes wants to merge 1 commit into
NousResearch:mainfrom
vivganes:patch-fix-8430

Conversation

@vivganes

@vivganes vivganes commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR fixes #8430 in a exhaustive way, introducing proper context length checking in case the user has provided a model.context_length config.

Related Issue

#8430

Fixes #8430

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  1. Show the existing error message only when context_length is None
  2. Show a new actionable error message if the model's context is less than the context_length value set in the config.

How to Test

  1. Run hermes agent with any model with context < 64000
  2. Set model.context_length in config to be less than 64000
  3. Send a 'hi' to hermes and see if you get a response

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate -- The existing PRs are not as exhaustive (adding a new error message and check) as this
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform:

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide
  • I've updated tool descriptions/schemas if I changed tool behavior — N/A

@rodriguez46p-ui

Copy link
Copy Markdown

Hermes CI triage

CI is currently failing for this PR in two places:

  1. tests/agent/test_agent_init.py::{test_init_agent_rejects_model_below_user_config_override,test_init_agent_rejects_model_below_minimum_without_override} fail because the lightweight SimpleNamespace test double is missing agent._is_direct_openai_url. Add it in make_agent() alongside _is_azure_openai_url.

  2. tests/run_agent/test_plugin_context_engine_init.py::test_plugin_engine_update_model_args now raises for openrouter/auto when detected context length is 0. The previous guard was if _ctx and _ctx < MINIMUM_CONTEXT_LENGTH, so unknown/undetectable context (0) did not fail startup. The new minimum check should likely preserve that behavior, e.g. only enforce when _ctx is truthy/known:

if _config_context_length is not None and _ctx and _ctx < _config_context_length:
    ...
if _config_context_length is None and _ctx and _ctx < MINIMUM_CONTEXT_LENGTH:
    ...

Also small style nit: if( should be if ( / preferably no extra parens, and the raise ValueError(...) closing paren is over-indented.

Evidence: failing jobs test (2) and test (3) in workflow run 26838174166.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder labels Jun 2, 2026
@liuhao1024

Copy link
Copy Markdown
Contributor

The split logic removes the _ctx and guard that the original code relied on to skip the check when context length is unknown (0).

Original code (line 1476 on main):

_ctx = getattr(agent.context_compressor, "context_length", 0)
if _ctx and _ctx < MINIMUM_CONTEXT_LENGTH:

The _ctx and short-circuit means: "if the compressor couldn't determine context length (0), skip the check entirely."

PR code:

if(_config_context_length is not None and _ctx < _config_context_length):

When _ctx is 0 (unknown) and model.context_length is configured (e.g., 60000), this evaluates to True and 0 < 60000 → True, raising a spurious ValueError. The same problem applies to the second condition: 0 < MINIMUM_CONTEXT_LENGTH would also be True.

Suggested fix — restore the _ctx truthiness check on both branches:

if _ctx and _config_context_length is not None and _ctx < _config_context_length:
    raise ValueError(...)
if _ctx and _config_context_length is None and _ctx < MINIMUM_CONTEXT_LENGTH:
    raise ValueError(...)

This preserves the original "skip when unknown" behavior while adding the user-configured override path. A test for the _ctx == 0 case would also be valuable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

4 participants