The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): honour the constructor answer_in_reasoning opt-in at the promotion gate
kshitijk4poord1024897acd5
diff --git a/agent/agent_init.py b/agent/agent_init.pyindex a384a412eec..bbdd4c8d1bb 100644--- a/agent/agent_init.py+++ b/agent/agent_init.py@@ -2065,7 +2065,7 @@ def _build_context_engine(agent, _agent_cfg, cs, _custom_providers, _effective_cagent.runtime_capabilities = resolve_native_compaction_capabilities(model=agent.model, base_url=agent.base_url, provider=agent.provider,is_codex_backend=(agent.provider or "").strip().lower() == "openai-codex",- )+ ) | {k: v for k, v in agent.capabilities.items() if k == "answer_in_reasoning"}agent.max_compression_attempts = cs.max_attemptsagent.compression_idle_compact_after_seconds = cs.idle_compact_after_secondsdiff --git a/agent/reasoning_promotion.py b/agent/reasoning_promotion.pyindex a9d3e27eeea..19120e76e81 100644--- a/agent/reasoning_promotion.py+++ b/agent/reasoning_promotion.py@@ -19,8 +19,10 @@ _NEMOTRON_PARSER_MODEL_MARKER = "nemotron-3.5-lightning"def answer_in_reasoning_capability(agent: Any) -> bool:"""True when the live route may return a clean-stop reasoning payload as the answer.- Trusted: an explicit ``answer_in_reasoning`` bool in ``runtime_capabilities``, a- custom_providers per-model ``answer_in_reasoning`` opt-in, or the local+ Trusted: an explicit ``answer_in_reasoning`` bool in ``runtime_capabilities`` (seeded at+ startup from the constructor's ``capabilities=``, e.g. a provider-level ``capabilities:``+ block, so it holds on the primary route only: fallback rebuilds drop it and primary restore+ brings it back), a custom_providers per-model ``answer_in_reasoning`` opt-in, or the localNemotron-3.5-Lightning parser route from #109205. OpenRouter and non-chat-completionstransports are never trusted."""diff --git a/tests/agent/test_empty_terminal_reasoning_surface.py b/tests/agent/test_empty_terminal_reasoning_surface.pyindex f35d5ab610d..da2184f6390 100644--- a/tests/agent/test_empty_terminal_reasoning_surface.py+++ b/tests/agent/test_empty_terminal_reasoning_surface.py@@ -27,7 +27,7 @@ sys.modules.setdefault("firecrawl", types.SimpleNamespace(Firecrawl=object))sys.modules.setdefault("fal_client", types.SimpleNamespace())-def _build_agent(tmp_path, monkeypatch):+def _build_agent(tmp_path, monkeypatch, capabilities={"answer_in_reasoning": True}):monkeypatch.setenv("HERMES_HOME", str(tmp_path))(tmp_path / ".env").write_text("", encoding="utf-8")(tmp_path / "config.yaml").write_text("{}\n", encoding="utf-8")@@ -41,13 +41,13 @@ def _build_agent(tmp_path, monkeypatch):skip_context_files=True,skip_memory=True,platform="cli",+ capabilities=capabilities,)# Route through the non-streaming _interruptible_api_call path so the# monkeypatched fake responses are what the loop consumes.agent._disable_streaming = True- # This fixture represents the explicit parser-compatible route. Private reasoning- # tests clear the capability and use an OpenRouter route instead.- agent.runtime_capabilities["answer_in_reasoning"] = True+ # By default this fixture is the explicit parser-compatible route (constructor opt-in).+ # Private reasoning tests drop the opt-in and use an OpenRouter route instead.return agent@@ -177,16 +177,20 @@ def test_length_cut_reasoning_is_not_promoted(tmp_path, monkeypatch):[email protected]("provider, base_url, model, final, calls", [- ("openrouter", "https://openrouter.ai/api/v1", "deepseek/deepseek-v4.1", "the visible answer", 2),- ("vllm", "http://127.0.0.1:8000/v1", "nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-NVFP4",[email protected]("provider, base_url, model, capabilities, final, calls", [+ ("openrouter", "https://openrouter.ai/api/v1", "deepseek/deepseek-v4.1", {}, "the visible answer", 2),+ ("vllm", "http://127.0.0.1:8000/v1", "nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-NVFP4", {},+ "private thoughts that must not be shown", 1),+ ("custom", "https://llm.example.com/v1", "acme/reasoner", {"answer_in_reasoning": True},"private thoughts that must not be shown", 1),])-def test_reasoning_promotion_requires_a_trusted_route(tmp_path, monkeypatch, provider, base_url, model, final, calls):+def test_reasoning_promotion_requires_a_trusted_route(+ tmp_path, monkeypatch, provider, base_url, model, capabilities, final, calls,+):"""Private reasoning on an untrusted route retries to the visible answer and never- surfaces; the local Nemotron parser route (#109205) still promotes in one call."""- agent = _build_agent(tmp_path, monkeypatch)- agent.runtime_capabilities.pop("answer_in_reasoning")+ surfaces; the local Nemotron parser route (#109205) and an explicit constructor+ ``capabilities`` opt-in (provider-level ``capabilities:`` block) promote in one call."""+ agent = _build_agent(tmp_path, monkeypatch, capabilities=capabilities)agent.provider, agent.base_url, agent.model = provider, base_url, modelresponses = [_private_reasoning_only_response(),