Skip to content

The agent that grows with you

fix(agent): re-read the provider-level answer_in_reasoning opt-in on the live route

kshitijk4poor1ddcb56a64bc
diff --git a/agent/reasoning_promotion.py b/agent/reasoning_promotion.py
index 19120e76e81..52a4def0749 100644
--- a/agent/reasoning_promotion.py
+++ b/agent/reasoning_promotion.py
@@ -19,10 +19,9 @@ _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`` (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 local
+ Trusted: an explicit ``answer_in_reasoning`` bool in ``runtime_capabilities``, a
+ custom_providers per-model ``answer_in_reasoning`` opt-in or provider-level
+ ``capabilities: {answer_in_reasoning: ...}`` block on the live route, or the local
Nemotron-3.5-Lightning parser route from #109205. OpenRouter and non-chat-completions
transports are never trusted.
"""
@@ -44,15 +43,24 @@ def answer_in_reasoning_capability(agent: Any) -> bool:
# Returns None on unreadable config, so no guard is needed here.
from hermes_cli.config import get_custom_provider_model_capability
+ from hermes_cli.config_providers import _entries_for_route
+
model = str(getattr(agent, "model", "") or "")
+ custom_providers = getattr(agent, "_custom_providers", None)
configured = get_custom_provider_model_capability(
model=model,
base_url=base_url,
capability=_ANSWER_IN_REASONING_CAPABILITY,
- custom_providers=getattr(agent, "_custom_providers", None),
+ custom_providers=custom_providers,
)
if configured is not None:
return configured
+ # The provider-level ``capabilities:`` block, re-read on the live route like the per-model key
+ # so it holds on CLI/TUI (no constructor ``capabilities=``) and survives /model switches.
+ for entry in _entries_for_route(base_url, custom_providers, None):
+ configured = (entry.get("capabilities") or {}).get(_ANSWER_IN_REASONING_CAPABILITY)
+ if isinstance(configured, bool):
+ return configured
if _NEMOTRON_PARSER_MODEL_MARKER not in model.lower():
return False
diff --git a/tests/agent/test_empty_terminal_reasoning_surface.py b/tests/agent/test_empty_terminal_reasoning_surface.py
index 4234e7c50f6..94cd271a37b 100644
--- a/tests/agent/test_empty_terminal_reasoning_surface.py
+++ b/tests/agent/test_empty_terminal_reasoning_surface.py
@@ -173,21 +173,26 @@ def test_length_cut_reasoning_is_not_promoted(tmp_path, monkeypatch):
assert result["api_calls"] == 2
[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},
+_OPTED_IN_ENTRY = {"name": "acme", "base_url": "https://llm.example.com/v1", "model": "acme/reasoner",
+ "capabilities": {"answer_in_reasoning": True}}
+
+
[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",
"private thoughts that must not be shown", 1),
+ ("custom", "https://llm.example.com/v1", "acme/reasoner", "private thoughts that must not be shown", 1),
+ ("custom", "https://llm.example.com/v1", "acme/after-model-switch", "private thoughts that must not be shown", 1),
+ ("custom", "https://fallback.example.com/v1", "acme/reasoner", "the visible answer", 2),
])
-def test_reasoning_promotion_requires_a_trusted_route(
- tmp_path, monkeypatch, provider, base_url, model, capabilities, final, calls,
-):
+def test_reasoning_promotion_requires_a_trusted_route(tmp_path, monkeypatch, provider, base_url, model, final, calls):
"""Private reasoning on an untrusted route retries to the visible answer and never
- 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)
+ surfaces; the local Nemotron parser route (#109205) and a provider-level ``capabilities:``
+ opt-in promote in one call, re-read on the live route (any model on that provider, never a
+ fallback on another base_url), with no constructor ``capabilities=`` (CLI/TUI)."""
+ agent = _build_agent(tmp_path, monkeypatch, capabilities={})
agent.provider, agent.base_url, agent.model = provider, base_url, model
+ agent._custom_providers = [_OPTED_IN_ENTRY]
responses = [
_private_reasoning_only_response(),
SimpleNamespace(