Skip to content

fix(run_agent): honor model.context_length override for sub-64K models - #11097

Closed
c0nSpIc0uS7uRk3r wants to merge 1 commit into
NousResearch:mainfrom
c0nSpIc0uS7uRk3r:pr/fix-context-length-override
Closed

fix(run_agent): honor model.context_length override for sub-64K models#11097
c0nSpIc0uS7uRk3r wants to merge 1 commit into
NousResearch:mainfrom
c0nSpIc0uS7uRk3r:pr/fix-context-length-override

Conversation

@c0nSpIc0uS7uRk3r

Copy link
Copy Markdown

Summary

Commit c8aff74 ("prevent agent from stopping mid-task") added a MINIMUM_CONTEXT_LENGTH=64K guard in AIAgent.__init__ that rejects agent initialization for any model whose native context window is smaller than 64K. The raised ValueError explicitly documents an escape hatch:

"or set model.context_length in config.yaml to override"

But the guard fires unconditionally — it never checks whether the operator actually set model.context_length in config.yaml. The promised escape hatch is cosmetic.

Fix

Add and _config_context_length is None to the gate condition. _config_context_length is already a local variable in the same __init__ method, populated from the config.yaml value, so no additional plumbing is needed.

Behavior change

  • Default (operator has not set model.context_length): unchanged — guard still fires, agent still refuses to start against sub-64K models.
  • Override (operator explicitly sets model.context_length in config.yaml, accepting sub-64K risk): agent now starts, matching what the error message already promises.

Repro

  1. In config.yaml:
    model:
      context_length: 32000
  2. Run hermes chat -q "hello" -Q against a model with a 32K native context (e.g. Qwen 3.5 35B-A3B).
  3. Before: ValueError: Model ... has a context window of 32,000 tokens, which is below the minimum 65,536...
  4. After: Agent starts normally, runs to completion.

Related

Addresses Bug 1 from #11096 (combined issue covering three v0.9.0 rough edges).

Commit c8aff74 ("prevent agent from stopping mid-task") added a
MINIMUM_CONTEXT_LENGTH=64K guard that rejects agent init for any model
whose native context window is smaller. The ValueError it raises
documents an escape hatch:

    "or set model.context_length in config.yaml to override"

But the guard fires unconditionally — it never checks whether the
operator set `model.context_length` in config.yaml. The promised
escape hatch is cosmetic.

Fix: add `and _config_context_length is None` to the gate condition.
`_config_context_length` is already a local variable in the same
`__init__` method, populated from the config.yaml value.

Effect: operators running against models with sub-64K native context
(e.g. Qwen 3.5 35B-A3B at 32K) can now explicitly opt in to the
smaller window via `model.context_length: 32000` in config.yaml,
matching the behavior the existing error message already promises.
Default behavior for operators who don't set the override is unchanged.

Repro:
  1. In config.yaml: `model.context_length: 32000`
  2. Run `hermes chat -q "hello" -Q` against a 32K model
  3. Before: ValueError at init. After: runs normally.
@vivganes

Copy link
Copy Markdown
Contributor

This is an important fix. Can we get this out in the next release? my hermes is bricked until then since i run a local model with less context window. The error message asks to set model.context_length but that does not work at all. This fixes it.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint area/config Config system, migrations, profiles labels Apr 25, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #8962 — same fix: honor model.context_length config override below 64K minimum. Also related to #9142 (same fix, different PR). Addresses Bug 1 from #11096.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the PR. Closing — this is working as intended, not a bug.

The 64K context-window floor is deliberate: Hermes' tool schemas + system prompt consume a large fixed prefix, and sub-64K windows aren't reliable for agentic tool-calling. We don't want anyone running below 64K, so there is intentionally no escape hatch to override the floor with a smaller value.

The real defect here was the error message — it advertised "or set model.context_length in config.yaml to override", which falsely implied a sub-64K override existed and generated a cluster of well-meaning PRs (this one included) trying to wire it up. We've corrected the message in #53569 so it no longer promises an override that was never meant to exist.

Note: model.context_length is still honored for the legitimate case where a local server under-reports its true window — but the declared value must itself be ≥64K. It is not a way to run below the floor.

Appreciate the clean, minimal diff — the reasoning just points the other way on this one.

@teknium1 teknium1 closed this Jun 27, 2026
teknium1 added a commit that referenced this pull request Jun 27, 2026
…age (#53569)

The error raised when a model's context window is below the 64K minimum
advertised "or set model.context_length in config.yaml to override" — but
the guard intentionally has no sub-64K escape hatch. Sub-64K models are
rejected by design (tool schemas + system prompt need the headroom).

The misleading clause invited a cluster of dup PRs (#11097, #11110, #8962,
#9142, #37548) all trying to wire an override that we don't want. Reword to
state the real options: pick a >=64K model, or — if your local server
under-reports its true window — declare the real value (which must itself
be >=64K). Guard behavior is unchanged.
pai-scaffolde pushed a commit to pai-scaffolde/hermes-agent that referenced this pull request Jun 28, 2026
…age (NousResearch#53569)

The error raised when a model's context window is below the 64K minimum
advertised "or set model.context_length in config.yaml to override" — but
the guard intentionally has no sub-64K escape hatch. Sub-64K models are
rejected by design (tool schemas + system prompt need the headroom).

The misleading clause invited a cluster of dup PRs (NousResearch#11097, NousResearch#11110, NousResearch#8962,
NousResearch#9142, NousResearch#37548) all trying to wire an override that we don't want. Reword to
state the real options: pick a >=64K model, or — if your local server
under-reports its true window — declare the real value (which must itself
be >=64K). Guard behavior is unchanged.
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…age (NousResearch#53569)

The error raised when a model's context window is below the 64K minimum
advertised "or set model.context_length in config.yaml to override" — but
the guard intentionally has no sub-64K escape hatch. Sub-64K models are
rejected by design (tool schemas + system prompt need the headroom).

The misleading clause invited a cluster of dup PRs (NousResearch#11097, NousResearch#11110, NousResearch#8962,
NousResearch#9142, NousResearch#37548) all trying to wire an override that we don't want. Reword to
state the real options: pick a >=64K model, or — if your local server
under-reports its true window — declare the real value (which must itself
be >=64K). Guard behavior is unchanged.
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
…age (NousResearch#53569)

The error raised when a model's context window is below the 64K minimum
advertised "or set model.context_length in config.yaml to override" — but
the guard intentionally has no sub-64K escape hatch. Sub-64K models are
rejected by design (tool schemas + system prompt need the headroom).

The misleading clause invited a cluster of dup PRs (NousResearch#11097, NousResearch#11110, NousResearch#8962,
NousResearch#9142, NousResearch#37548) all trying to wire an override that we don't want. Reword to
state the real options: pick a >=64K model, or — if your local server
under-reports its true window — declare the real value (which must itself
be >=64K). Guard behavior is unchanged.
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…age (NousResearch#53569)

The error raised when a model's context window is below the 64K minimum
advertised "or set model.context_length in config.yaml to override" — but
the guard intentionally has no sub-64K escape hatch. Sub-64K models are
rejected by design (tool schemas + system prompt need the headroom).

The misleading clause invited a cluster of dup PRs (NousResearch#11097, NousResearch#11110, NousResearch#8962,
NousResearch#9142, NousResearch#37548) all trying to wire an override that we don't want. Reword to
state the real options: pick a >=64K model, or — if your local server
under-reports its true window — declare the real value (which must itself
be >=64K). Guard behavior is unchanged.
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…age (NousResearch#53569)

The error raised when a model's context window is below the 64K minimum
advertised "or set model.context_length in config.yaml to override" — but
the guard intentionally has no sub-64K escape hatch. Sub-64K models are
rejected by design (tool schemas + system prompt need the headroom).

The misleading clause invited a cluster of dup PRs (NousResearch#11097, NousResearch#11110, NousResearch#8962,
NousResearch#9142, NousResearch#37548) all trying to wire an override that we don't want. Reword to
state the real options: pick a >=64K model, or — if your local server
under-reports its true window — declare the real value (which must itself
be >=64K). Guard behavior is unchanged.
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…age (NousResearch#53569)

The error raised when a model's context window is below the 64K minimum
advertised "or set model.context_length in config.yaml to override" — but
the guard intentionally has no sub-64K escape hatch. Sub-64K models are
rejected by design (tool schemas + system prompt need the headroom).

The misleading clause invited a cluster of dup PRs (NousResearch#11097, NousResearch#11110, NousResearch#8962,
NousResearch#9142, NousResearch#37548) all trying to wire an override that we don't want. Reword to
state the real options: pick a >=64K model, or — if your local server
under-reports its true window — declare the real value (which must itself
be >=64K). Guard behavior is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants