{"record":{"id":"9b0d6cc61c16180a","repo":"NousResearch/hermes-agent","slug":"model-agent-model-has-a-context-window-of-ctx","errorCode":null,"errorMessage":"Model {agent.model} has a context window of {_ctx:,} tokens, which is below the minimum {MINIMUM_CONTEXT_LENGTH:,} required by Hermes Agent.  Choose a model with at least {MINIMUM_CONTEXT_LENGTH // 1000}K context.  If your server reports a window smaller than the model's true window, set model.context_length in config.yaml to the real value (this must be at least {MINIMUM_CONTEXT_LENGTH // 1000}K).","messagePattern":"Model (.+?) has a context window of (.+?) tokens, which is below the minimum (.+?) required by Hermes Agent\\.  Choose a model with at least (.+?)K context\\.  If your server reports a window smaller than the model's true window, set model\\.context_length in config\\.yaml to the real value \\(this must be at least (.+?)K\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/agent_init.py","lineNumber":2653,"sourceCode":"    agent.codex_app_server_auto_compaction = codex_app_server_auto_compaction\n    agent.codex_responses_native_compaction = codex_responses_native_compaction\n    agent.codex_responses_compact_threshold = codex_responses_compact_threshold\n    agent.max_compression_attempts = compression_max_attempts\n    agent.compression_idle_compact_after_seconds = (\n        compression_idle_compact_after_seconds\n    )\n\n    # Reject models whose context window is below the minimum required\n    # for reliable tool-calling workflows (64K tokens).\n    _ctx = getattr(agent.context_compressor, \"context_length\", 0)\n    _allow_lmstudio_explicit_below_floor = (\n        str(getattr(agent, \"provider\", \"\") or \"\").strip().lower() == \"lmstudio\"\n        and isinstance(agent._config_context_length, int)\n        and not isinstance(agent._config_context_length, bool)\n        and agent._config_context_length > 0\n    )\n    if _ctx and _ctx < MINIMUM_CONTEXT_LENGTH and not _allow_lmstudio_explicit_below_floor:\n        raise ValueError(\n            f\"Model {agent.model} has a context window of {_ctx:,} tokens, \"\n            f\"which is below the minimum {MINIMUM_CONTEXT_LENGTH:,} required \"\n            f\"by Hermes Agent.  Choose a model with at least \"\n            f\"{MINIMUM_CONTEXT_LENGTH // 1000}K context.  If your server \"\n            f\"reports a window smaller than the model's true window, set \"\n            f\"model.context_length in config.yaml to the real value \"\n            f\"(this must be at least {MINIMUM_CONTEXT_LENGTH // 1000}K).\"\n        )\n\n    # Nous Hermes 3/4 are chat models, not tool-call-tuned. The interactive\n    # CLI already warns via cli.py show_banner() (richer output + /model hint),\n    # so skip platform==\"cli\" here to avoid emitting the warning twice per\n    # startup. (Gateway/TUI/cron construct with quiet_mode=True and are already\n    # gated off by the `not agent.quiet_mode` check above; this guard's active\n    # job is the CLI dedup, and it leaves the door open for any non-quiet\n    # non-CLI surface to still surface the warning.)\n    if not agent.quiet_mode and (agent.platform or \"cli\") != \"cli\":\n        try:","sourceCodeStart":2635,"sourceCodeEnd":2671,"githubUrl":"https://github.com/NousResearch/hermes-agent/blob/c896c09c42910c584c4c7d2325b58c14713ea42c/agent/agent_init.py#L2635-L2671","documentation":"Hermes requires at least MINIMUM_CONTEXT_LENGTH (64K) tokens of context for reliable tool-calling workflows; this ValueError fires at init when context_compressor.context_length is positive but below that floor. One documented escape hatch: provider 'lmstudio' with an explicit positive integer model.context_length in config.yaml is allowed below the floor.","triggerScenarios":"The provider/model catalog (or server-reported value) resolves a context length < 65536 for the chosen model, and either the provider is not lmstudio, or it is lmstudio but model.context_length is missing, zero, or a bool — so _allow_lmstudio_explicit_below_floor is False.","commonSituations":"Pointing hermes at a small local model (8K/32K Ollama or LM Studio quant); a server under-reporting the model's true window; a stale catalog entry with a low context length; model.context_length accidentally set to 0.","solutions":["Switch to a model with at least 64K context via `hermes model`","If the server under-reports the true window, set model.context_length in config.yaml to the real value — the below-floor override is honored only for provider lmstudio with an explicit positive integer","Fix the local server's reported context so the resolved value is accurate","Remove/repair any model.context_length that coerces to 0 or False"],"exampleFix":"# config.yaml — before (provider: lmstudio, server reports 8K)\nmodel:\n  name: my-local-model\n\n# after (explicit override of the server's under-report)\nmodel:\n  name: my-local-model\n  context_length: 131072","handlingStrategy":"validation","validationCode":"from agent.constants import MINIMUM_CONTEXT_LENGTH  # 65536\n\ndef context_ok(resolved_context: int, provider: str, config_ctx) -> bool:\n    if not resolved_context or resolved_context >= MINIMUM_CONTEXT_LENGTH:\n        return True\n    return (\n        provider.strip().lower() == \"lmstudio\"\n        and isinstance(config_ctx, int)\n        and not isinstance(config_ctx, bool)\n        and config_ctx > 0\n    )\n\nassert context_ok(resolved_ctx, provider, config_ctx), \"model context below 64K floor\"","typeGuard":null,"tryCatchPattern":"try:\n    agent = AIAgent(...)\nexcept ValueError as e:\n    if \"context window\" in str(e) and \"below the minimum\" in str(e):\n        suggest_model_with_64k()  # or set model.context_length for lmstudio\n    else:\n        raise","preventionTips":["Check the model's advertised context length before selecting it in `hermes model`","For LM Studio models whose server under-reports, always set model.context_length explicitly","Avoid legacy sub-64K models for tool-calling workflows"],"tags":["config","model","context-window","validation"],"backgroundTag":null,"analyzedSha":"c896c09c42910c584c4c7d2325b58c14713ea42c","analyzedAt":"2026-08-14T17:18:01.089Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}