The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent_init): the 64K context floor judges the window Ollama serves, not the GGUF metadata
kshitijk4poor3de7140bcd67
diff --git a/agent/agent_init.py b/agent/agent_init.pyindex 7fa654fb07d..a76cb4b0079 100644--- a/agent/agent_init.py+++ b/agent/agent_init.py@@ -1912,6 +1912,11 @@ def _enforce_minimum_context(agent):# Reject windows below the 64K floor needed for reliable tool-calling; an explicit# positive model.context_length on LM Studio is allowed below the floor._ctx = getattr(agent.context_compressor, "context_length", 0)+ # An Ollama server serves num_ctx, not the GGUF's advertised window: a Modelfile or+ # model.ollama_num_ctx at 64K+ is a usable window even when the metadata says 40K (#100437).+ _served = getattr(agent, "_ollama_num_ctx", None)+ if isinstance(_served, int) and not isinstance(_served, bool) and _served > 0:+ _ctx = max(_ctx or 0, _served)_allow_lmstudio_explicit_below_floor = (str(agent.provider or "").strip().lower() == "lmstudio"and isinstance(agent._config_context_length, int)@@ -2326,11 +2331,12 @@ def init_agent(agent, _agent_cfg, base_url)_build_context_engine(agent, _agent_cfg, cs, _custom_providers, _effective_context_length, session_db)+ # num_ctx before the floor: the served Ollama window is part of what the floor judges.+ _configure_ollama_num_ctx(agent, _model_cfg, _config_context_length)_enforce_minimum_context(agent)_warn_nonagentic_hermes_model(agent)_inject_context_engine_tools(agent)_init_usage_state(agent)- _configure_ollama_num_ctx(agent, _model_cfg, _config_context_length)_emit_compression_summary(agent, cs)_snapshot_primary_runtime(agent)diff --git a/tests/agent/test_ollama_num_ctx.py b/tests/agent/test_ollama_num_ctx.pyindex d4f9b8607fc..9bbb882f31b 100644--- a/tests/agent/test_ollama_num_ctx.py+++ b/tests/agent/test_ollama_num_ctx.py@@ -7,6 +7,8 @@ Covers:from unittest.mock import patch, MagicMock+import pytest+from agent.model_metadata import query_ollama_num_ctx, query_ollama_supports_vision@@ -187,3 +189,18 @@ class TestCompressorClampsToNumCtx:# num_ctx above the resolved window must not RAISE the compressor# window: the clamp is one-directional.assert agent.context_compressor.context_length == 65536+++class TestServedNumCtxSatisfiesTheFloor(TestCompressorClampsToNumCtx):+ """#100437: the 64K floor judges the window Ollama actually serves. A Modelfile or+ model.ollama_num_ctx at 64K+ is usable even when the GGUF metadata advertises 40K, so+ construction must succeed; the compressor still targets the smaller probed window."""++ def test_explicit_num_ctx_above_the_floor_admits_a_small_metadata_window(self):+ agent = self._build_agent({"agent": {}, "model": {"ollama_num_ctx": 65536}}, probed_ctx=40960)+ assert agent._ollama_num_ctx == 65536+ assert agent.context_compressor.context_length == 40960 # one-directional clamp unchanged++ def test_served_window_below_the_floor_is_still_rejected(self):+ with pytest.raises(ValueError, match="below the minimum"):+ self._build_agent({"agent": {}, "model": {"ollama_num_ctx": 32768}}, probed_ctx=40960)