Skip to content

AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).

feat: deep reasoning on every reasoning-capable model, with a Haiku guard

Claude03fe7c332578
diff --git a/packages/core/openexecutive/agents/base.py b/packages/core/openexecutive/agents/base.py
index e8091d96..ba834cd1 100644
--- a/packages/core/openexecutive/agents/base.py
+++ b/packages/core/openexecutive/agents/base.py
@@ -1,13 +1,16 @@
from __future__ import annotations
+import logging
from abc import ABC, abstractmethod
from typing import Any
from openexecutive.config import get_settings
-from openexecutive.providers import get_provider
+from openexecutive.providers import get_provider, model_supports_deep_reasoning
_SPECIALIST_TIMEOUT = 180.0
+logger = logging.getLogger(__name__)
+
class BaseAgent(ABC):
name: str
@@ -121,8 +124,8 @@ class BaseAgent(ABC):
"messages": [{"role": "user", "content": user_content}],
}
- if use_deep:
- # Opus 4.7 requires `adaptive` thinking; we cap effort via
+ if use_deep and model_supports_deep_reasoning(model):
+ # Adaptive thinking with effort capped via
# output_config.effort. Default "low" — adaptive at default
# effort routinely burned 20k+ thinking tokens. "low" still
# leaves room for nuanced reasoning while being ~3x faster.
@@ -139,6 +142,18 @@ class BaseAgent(ABC):
message = await provider.messages_create(**create_kwargs)
text_blocks = [b for b in message.content if b.type == "text"]
+ if not text_blocks:
+ # A reasoning model can spend the whole max_tokens budget thinking
+ # and return no text; the Executive would then synthesize as if
+ # this specialist had nothing to say. Make that visible.
+ logger.warning(
+ "specialist %s (%s) returned no text block (stop_reason=%s, "
+ "deep_reasoning=%s); its analysis will be empty",
+ self.name,
+ model,
+ getattr(message, "stop_reason", None),
+ use_deep,
+ )
return text_blocks[0].text if text_blocks else ""
async def analyze_with_tools(
@@ -207,7 +222,7 @@ class BaseAgent(ABC):
"messages": [{"role": "user", "content": user_content}],
}
- if use_deep:
+ if use_deep and model_supports_deep_reasoning(model):
create_kwargs["thinking"] = {"type": "adaptive"}
create_kwargs["output_config"] = {"effort": settings.specialist_effort}
create_kwargs["max_tokens"] = max(max_tokens, 16000)
diff --git a/packages/core/openexecutive/architecture/architecture-facts.yaml b/packages/core/openexecutive/architecture/architecture-facts.yaml
index 4b220ffb..0a2e1009 100644
--- a/packages/core/openexecutive/architecture/architecture-facts.yaml
+++ b/packages/core/openexecutive/architecture/architecture-facts.yaml
@@ -148,11 +148,56 @@ providers:
stripping covers cache_control on system/tool/user blocks, adaptive
thinking + output_config, and Anthropic server-side web_search
tools. A misrouted call cannot ship an unsupported field.
+ supports_thinking is TRUE for the Claude family and for any non-Claude
+ catalog slug whose OpenRouter entry lists "reasoning" in
+ supported_parameters (registry._openrouter_model_resolver consults
+ openrouter_catalog.supports_reasoning); unknown slugs (hardcoded
+ fallback list, or outside the catalog) keep thinking OFF.
+ deep_reasoning: |
+ The Council "Deep reasoning" toggle (BaseAgent.use_deep_reasoning /
+ agent_overrides.use_deep_reasoning) adds Anthropic-native
+ ``thinking={"type":"adaptive"}`` + ``output_config.effort``
+ (SPECIALIST_EFFORT) to the call. It is honoured on: Claude Opus/Sonnet
+ via Anthropic direct; Claude via OpenRouter; and every non-Claude
+ OpenRouter model the live catalog marks reasoning-capable (today: all
+ OpenAI, Gemini, DeepSeek and Grok entries — not Llama). It is a silent
+ no-op on models that can't reason (feature gate strips the fields).
+ Haiku guard: Haiku rejects adaptive thinking (HTTP 400), so
+ providers.registry.model_supports_deep_reasoning() returns False for any
+ Claude id / OpenRouter Claude slug naming the Haiku family (current
+ ``claude-haiku-4-5`` and legacy ``claude-3-5-haiku-…`` orderings; scoped
+ to Claude names so an unrelated slug containing "haiku" is unaffected)
+ and the agent call paths (BaseAgent.analyze,
+ analyze_with_tools, monitoring.research.agentic) skip the thinking fields
+ for it; the Council UI disables the checkbox for the same models, clears
+ it when the model is switched to Haiku, masks a stale stored
+ deep_reasoning=true on load (so the next Save corrects the row), and
+ never sends deep reasoning for a Haiku model from the Test button.
translator_shapes: |
Anthropic ``system`` list → OpenAI single ``system`` message;
Anthropic ``tools[].input_schema`` → OpenAI ``tools[].function.parameters``;
Anthropic ``tool_choice={"type":"tool","name":X}`` → OpenAI
- ``{"type":"function","function":{"name":X}}``. The Anthropic
+ ``{"type":"function","function":{"name":X}}``;
+ Anthropic ``thinking={"type":"adaptive"}`` + ``output_config.effort`` →
+ OpenRouter unified ``reasoning={"effort": <level>}`` where level is passed
+ through when it is one of OpenRouter's accepted strings
+ (none/minimal/low/medium/high/xhigh/max) and otherwise FAILS CLOSED to
+ "low" — never up to an expensive tier (legacy
+ ``{"type":"enabled","budget_tokens":N}`` → ``reasoning={"max_tokens":N}``;
+ ``enabled`` with no usable budget → no field),
+ which OpenRouter maps to each vendor's native form. The
+ ``reasoning_details`` array OpenRouter returns (non-streaming
+ ``message.reasoning_details``, streaming ``delta.reasoning_details``) is
+ carried as a synthetic ``openrouter_reasoning`` content block (always
+ LAST in ``content`` so ``content[0].text`` readers are unaffected) and
+ replayed verbatim as ``reasoning_details`` on the assistant message by
+ the request translator. The one tool loop that runs with deep reasoning
+ on — monitoring.research.agentic._assistant_turn — echoes the block, so
+ it keeps reasoning continuity (the OpenRouter-path equivalent of echoing
+ Anthropic thinking blocks). The Executive / executive_research /
+ executive_reflection loops never enable thinking and drop the block
+ harmlessly; wire the echo in if deep reasoning is ever added to them.
+ The Anthropic
server-side web_search tool (no input_schema) cannot be executed by
OpenRouter, so its intent is translated into OpenRouter's
``plugins:[{"id":"web","max_results":N}]`` web-search plugin (N derived
diff --git a/packages/core/openexecutive/architecture/prebuilt/agents.json b/packages/core/openexecutive/architecture/prebuilt/agents.json
index 448116e1..af6507d2 100644
--- a/packages/core/openexecutive/architecture/prebuilt/agents.json
+++ b/packages/core/openexecutive/architecture/prebuilt/agents.json
@@ -1,7 +1,7 @@
{
"section_id": "agents",
"title": "Agent Council",
- "markdown": "The Executive (`openexecutive.orchestrator.executive.Executive`) is a single coherent persona that fans out to specialist sub-agents via Anthropic tool use. Each specialist subclasses `openexecutive.agents.base.BaseAgent`, carrying a `name`, `domain`, and `model`, and exposes `analyze(...)`, which wraps the question in user-turn context and calls Claude through the per-call provider.\n\nRouting uses one `consult_specialist` tool. Multiple parallel `tool_use` blocks in a single assistant turn fan out concurrently through `router.route_parallel`, each running its own domain-filtered ChromaDB query before the specialist sees the question. The Executive then synthesizes the returned analyses into one reply.\n\nThe ten entries in `SPECIALIST_REGISTRY` (`openexecutive.orchestrator.router`):\n\n| Key | Agent | Domain |\n| --- | --- | --- |\n| `cso` | `StrategyAgent` | strategy |\n| `cfo` | `FinanceAgent` | finance |\n| `chro` | `HRAgent` | hr |\n| `gc` | `LegalAgent` | legal |\n| `coo` | `OperationsAgent` | operations |\n| `cmo` | `MarketingAgent` | marketing |\n| `cpo` | `ProductAgent` | product |\n| `board_comms` | `BoardCommsAgent` | board |\n| `talent` | `TalentAgent` | talent |\n| `triage` | `TriageAgent` | triage |\n\nModels: specialists default to `claude-sonnet-5`; a deep-reasoning tier uses `claude-opus-5` (adaptive thinking); routing/fast classification uses `claude-haiku-4-5`. With `OPENROUTER_ENABLED`, the Council dropdown's non-Anthropic entries come from OpenRouter's live `/models` catalog (fetched at startup, refreshed in the background, filtered to tool-capable paid text models from an allowlisted vendor set), falling back to a built-in snapshot if the fetch fails. Four Council-only agents (`quality_judge`, `utility_fast`, `research`, `fixture_generator`) are model/prompt-overridable in the UI but not callable via `consult_specialist`.\n\nMost specialists only *advise* — they return analysis the Executive synthesizes. The `talent` specialist (Head of Talent & Executive Search) additionally backs a vertical the Executive can *act* on: `orchestrator.talent_tools` gives the main tool loop read access to the live search pipeline (`list_engagements`, `list_candidates`, `get_candidate`, `match_candidates`) plus two side-effecting tools (`set_candidate_stage`, `start_talent_workflow`), so a chat turn can move a candidate or fire a screen/outreach workflow, not just opine. See the Talent section.\n\nBeyond the talent vertical, the Executive can launch *any* workflow conversationally: `orchestrator.workflow_run_tools` adds `list_workflows` (the launchable catalog with each workflow's inputs) and `run_workflow` (runs a built-in or custom workflow to completion and returns its artifact, checkpointing approval gates as `awaiting_human`). This makes the `/jobs` catalog reachable from chat — see the Workflows section.\n\nThe Executive also backs the **Ask OE** panel's form-fill tier via `orchestrator.form_tools.propose_form_values`: when a chat turn arrives with a `<page_context>` block describing a form on the user's screen, the Executive can propose values for it. The proposal is delivered to the UI as a `form_patch` SSE event and placed into the form as highlighted suggestions — the tool never saves or submits anything; the user reviews and saves manually. The tool is **always** in the tool list (tool definitions sit at the top of the cached prompt prefix, so a conditionally-present tool would invalidate the prompt cache whenever panel and non-panel turns alternate); its description restricts usage to turns that carry a form descriptor.",
+ "markdown": "The Executive (`openexecutive.orchestrator.executive.Executive`) is a single coherent persona that fans out to specialist sub-agents via Anthropic tool use. Each specialist subclasses `openexecutive.agents.base.BaseAgent`, carrying a `name`, `domain`, and `model`, and exposes `analyze(...)`, which wraps the question in user-turn context and calls Claude through the per-call provider.\n\nRouting uses one `consult_specialist` tool. Multiple parallel `tool_use` blocks in a single assistant turn fan out concurrently through `router.route_parallel`, each running its own domain-filtered ChromaDB query before the specialist sees the question. The Executive then synthesizes the returned analyses into one reply.\n\nThe ten entries in `SPECIALIST_REGISTRY` (`openexecutive.orchestrator.router`):\n\n| Key | Agent | Domain |\n| --- | --- | --- |\n| `cso` | `StrategyAgent` | strategy |\n| `cfo` | `FinanceAgent` | finance |\n| `chro` | `HRAgent` | hr |\n| `gc` | `LegalAgent` | legal |\n| `coo` | `OperationsAgent` | operations |\n| `cmo` | `MarketingAgent` | marketing |\n| `cpo` | `ProductAgent` | product |\n| `board_comms` | `BoardCommsAgent` | board |\n| `talent` | `TalentAgent` | talent |\n| `triage` | `TriageAgent` | triage |\n\nModels: specialists default to `claude-sonnet-5`; a deep-reasoning tier uses `claude-opus-5` (adaptive thinking); routing/fast classification uses `claude-haiku-4-5`. The Council's **Deep reasoning** toggle is honoured on Claude Opus/Sonnet (direct or via OpenRouter) and on any OpenRouter model whose live catalog entry supports `reasoning` (today all OpenAI, Gemini, DeepSeek and Grok entries; not Llama) — the request translator turns Anthropic adaptive thinking + effort into OpenRouter's `reasoning` parameter. It is a silent no-op on models that can't reason, and disabled for Haiku, which rejects adaptive thinking. With `OPENROUTER_ENABLED`, the Council dropdown's non-Anthropic entries come from OpenRouter's live `/models` catalog (fetched at startup, refreshed in the background, filtered to tool-capable paid text models from an allowlisted vendor set), falling back to a built-in snapshot if the fetch fails. Four Council-only agents (`quality_judge`, `utility_fast`, `research`, `fixture_generator`) are model/prompt-overridable in the UI but not callable via `consult_specialist`.\n\nMost specialists only *advise* — they return analysis the Executive synthesizes. The `talent` specialist (Head of Talent & Executive Search) additionally backs a vertical the Executive can *act* on: `orchestrator.talent_tools` gives the main tool loop read access to the live search pipeline (`list_engagements`, `list_candidates`, `get_candidate`, `match_candidates`) plus two side-effecting tools (`set_candidate_stage`, `start_talent_workflow`), so a chat turn can move a candidate or fire a screen/outreach workflow, not just opine. See the Talent section.\n\nBeyond the talent vertical, the Executive can launch *any* workflow conversationally: `orchestrator.workflow_run_tools` adds `list_workflows` (the launchable catalog with each workflow's inputs) and `run_workflow` (runs a built-in or custom workflow to completion and returns its artifact, checkpointing approval gates as `awaiting_human`). This makes the `/jobs` catalog reachable from chat — see the Workflows section.\n\nThe Executive also backs the **Ask OE** panel's form-fill tier via `orchestrator.form_tools.propose_form_values`: when a chat turn arrives with a `<page_context>` block describing a form on the user's screen, the Executive can propose values for it. The proposal is delivered to the UI as a `form_patch` SSE event and placed into the form as highlighted suggestions — the tool never saves or submits anything; the user reviews and saves manually. The tool is **always** in the tool list (tool definitions sit at the top of the cached prompt prefix, so a conditionally-present tool would invalidate the prompt cache whenever panel and non-panel turns alternate); its description restricts usage to turns that carry a form descriptor.",
"mermaid": "flowchart TD\n User([User message]) --> Exec[\"Executive<br/>orchestrator\"]\n Exec -->|consult_specialist| Cso[\"cso: StrategyAgent\"]\n Exec -->|consult_specialist| Cfo[\"cfo: FinanceAgent\"]\n Exec -->|consult_specialist| Gc[\"gc: LegalAgent\"]\n Exec -->|consult_specialist| More[\"chro / coo / cmo / cpo<br/>board_comms / talent / triage\"]\n Cso --> Claude[\"Claude (Anthropic)\"]\n Cfo --> Claude\n Gc --> Claude\n More --> Claude\n Claude --> Exec\n class User entry\n class Exec compute\n class Cso compute\n class Cfo compute\n class Gc compute\n class More compute\n class Claude external",
"generated_at": "2026-06-11T00:00:00+00:00"
}
diff --git a/packages/core/openexecutive/config.py b/packages/core/openexecutive/config.py
index 38eee9da..ef8e693e 100644
--- a/packages/core/openexecutive/config.py
+++ b/packages/core/openexecutive/config.py
@@ -286,11 +286,14 @@ class Settings(BaseSettings):
# full-pass revision on top of the draft, typically 5–12s.
committee_extra_timeout_s: float = Field(60.0, alias="COMMITTEE_EXTRA_TIMEOUT_S")
- # Reasoning effort for deep-reasoning specialists. Opus 4.7 only supports
- # `thinking.type=adaptive` paired with `output_config.effort`. Valid
- # values: "low", "medium", "high", "xhigh", "max". `low` is ~3x faster
- # and much cheaper; bump to `medium` when answers feel shallow.
- specialist_effort: str = Field("low", alias="SPECIALIST_EFFORT")
+ # Reasoning effort for deep-reasoning specialists (adaptive thinking +
+ # `output_config.effort`; translated to OpenRouter `reasoning.effort` on
+ # that path). Validated at boot: an invalid value used to 400 on Anthropic
+ # direct and would otherwise be silently coerced on OpenRouter. `low` is
+ # ~3x faster and much cheaper; bump to `medium` when answers feel shallow.
+ specialist_effort: Literal["low", "medium", "high", "xhigh", "max"] = Field(
+ "low", alias="SPECIALIST_EFFORT"
+ )
@model_validator(mode="after")
def _resolve_paths(self) -> "Settings":
diff --git a/packages/core/openexecutive/monitoring/research/agentic.py b/packages/core/openexecutive/monitoring/research/agentic.py
index b8761494..23fa4c3b 100644
--- a/packages/core/openexecutive/monitoring/research/agentic.py
+++ b/packages/core/openexecutive/monitoring/research/agentic.py
@@ -32,7 +32,8 @@ from openexecutive.monitoring.research.scrape_tool import (
)
from openexecutive.monitoring.research.tools import EMIT_RESEARCH_FINDINGS_TOOL
from openexecutive.orchestrator.web_search_tool import build_web_search_tool
-from openexecutive.providers import get_provider
+from openexecutive.providers import get_provider, model_supports_deep_reasoning
+from openexecutive.providers.translator import reasoning_replay_block
logger = logging.getLogger(__name__)
@@ -94,7 +95,7 @@ async def run_specialist_agentic(
"tools": tools,
"messages": messages,
}
- if use_deep:
+ if use_deep and model_supports_deep_reasoning(model):
create_kwargs["thinking"] = {"type": "adaptive"}
create_kwargs["output_config"] = {
"effort": settings.specialist_effort
@@ -240,6 +241,11 @@ def _assistant_turn(
assistant_content.append(tu)
if tu["name"] == SCRAPE_URL_TOOL_NAME:
scrape_calls.append({"id": tu["id"], "input": tu["input"]})
+ elif (replay := reasoning_replay_block(block)) is not None:
+ # OpenRouter-path equivalent of a thinking block: replay its
+ # reasoning_details verbatim or the next tool-loop turn loses
+ # (Anthropic: rejects) the chain of thought.
+ assistant_content.append(replay)
elif btype in (
"thinking",
"redacted_thinking",
diff --git a/packages/core/openexecutive/orchestrator/executive.py b/packages/core/openexecutive/orchestrator/executive.py
index 40f82172..aa5bee3b 100644
--- a/packages/core/openexecutive/orchestrator/executive.py
+++ b/packages/core/openexecutive/orchestrator/executive.py
@@ -94,6 +94,7 @@ from openexecutive.orchestrator.workflow_run_tools import (
)
from openexecutive.prompts.cache_manager import build_system_blocks
from openexecutive.providers import get_provider
+from openexecutive.providers.translator import reasoning_replay_block
logger = logging.getLogger(__name__)
@@ -1205,6 +1206,10 @@ class Executive:
web_search_queries.append(query)
elif block.type == "web_search_tool_result":
response_content.append(block.model_dump(exclude_none=True))
+ elif (replay := reasoning_replay_block(block)) is not None:
+ # OpenRouter reasoning continuity across tool iterations
+ # (replayed as ``reasoning_details`` by the translator).
+ response_content.append(replay)
last_full_text = full_text
diff --git a/packages/core/openexecutive/providers/__init__.py b/packages/core/openexecutive/providers/__init__.py
index 8941a55a..7ed9cdf7 100644
--- a/packages/core/openexecutive/providers/__init__.py
+++ b/packages/core/openexecutive/providers/__init__.py
@@ -13,6 +13,7 @@ from openexecutive.providers.registry import (
allowed_models,
allowed_models_for,
get_provider,
+ model_supports_deep_reasoning,
)
__all__ = [
@@ -22,4 +23,5 @@ __all__ = [
"allowed_models",
"allowed_models_for",
"get_provider",
+ "model_supports_deep_reasoning",
]
diff --git a/packages/core/openexecutive/providers/openai_compatible.py b/packages/core/openexecutive/providers/openai_compatible.py
index 1b496e8d..e97c1930 100644
--- a/packages/core/openexecutive/providers/openai_compatible.py
+++ b/packages/core/openexecutive/providers/openai_compatible.py
@@ -46,6 +46,23 @@ from openexecutive.providers.translator import (
logger = logging.getLogger(__name__)
+# Slugs for which we've already announced that deep reasoning is being sent
+# through OpenRouter. Reasoning tokens are billed, and the Council toggle can
+# be on for an agent that was previously parked on a model where it was a
+# silent no-op — one log line per model per process makes that visible.
+_reasoning_announced: set[str] = set()
+
+
+def _announce_reasoning(slug: str, body: dict[str, Any]) -> None:
+ if "reasoning" in body and slug not in _reasoning_announced:
+ _reasoning_announced.add(slug)
+ logger.info(
+ "deep reasoning enabled for %s via OpenAI-compatible backend "
+ "(reasoning=%s); reasoning tokens are billed for this model",
+ slug,
+ body["reasoning"],
+ )
+
class OpenAICompatibleProvider:
"""LLMProvider implementation backed by any OpenAI-compatible endpoint.
@@ -129,6 +146,7 @@ class OpenAICompatibleProvider:
slug, spec = self._resolve(model)
gated = apply_feature_gates(spec, kwargs)
body = to_openai_request(slug, gated)
+ _announce_reasoning(slug, body)
try:
resp = await self._client.post(
@@ -154,6 +172,7 @@ class OpenAICompatibleProvider:
slug, spec = self._resolve(model)
gated = apply_feature_gates(spec, kwargs)
body = to_openai_request(slug, gated)
+ _announce_reasoning(slug, body)
body["stream"] = True
return _OpenAICompatibleStream(
client=self._client,
diff --git a/packages/core/openexecutive/providers/openrouter_catalog.py b/packages/core/openexecutive/providers/openrouter_catalog.py
index bf2cdf58..130c549a 100644
--- a/packages/core/openexecutive/providers/openrouter_catalog.py
+++ b/packages/core/openexecutive/providers/openrouter_catalog.py
@@ -63,6 +63,11 @@ _SLUG_RE = re.compile(r"^[A-Za-z0-9._-]{1,64}/[A-Za-z0-9._-]{1,96}$")
# filter matched nothing) and is served as-is so a misconfigured allowlist
# is visible rather than silently masked by the fallback.
_loaded_models: list[str] | None = None
+# Subset of ``_loaded_models`` whose catalog entry advertises "reasoning" in
+# ``supported_parameters`` — i.e. OpenRouter will honour a ``reasoning``
+# request field for them. Drives the Council "Deep reasoning" checkbox for
+# non-Claude models.
+_loaded_reasoning: frozenset[str] = frozenset()
_loaded_at: float | None = None
@@ -71,11 +76,42 @@ def loaded_models() -> list[str] | None:
return None if _loaded_models is None else list(_loaded_models)
+def supports_reasoning(model_id: str) -> bool | None:
+ """Whether the loaded catalog says ``model_id`` accepts ``reasoning``.
+
+ ``None`` when no catalog is loaded or the slug isn't in it — callers
+ treat that as "unknown" and keep their conservative default.
+ """
+ if _loaded_models is None or model_id not in _loaded_models:
+ return None
+ return model_id in _loaded_reasoning
+
+
+def reasoning_capable_ids(entries: Iterable[Mapping[str, Any]]) -> frozenset[str]:
+ """Ids of catalog entries that list "reasoning" in ``supported_parameters``."""
+ out: set[str] = set()
+ for entry in entries:
+ model_id = entry.get("id")
+ if isinstance(model_id, str) and _advertises(entry, "reasoning"):
+ out.add(model_id)
+ return frozenset(out)
+
+
def loaded_at() -> float | None:
"""``time.time()`` of the last successful fetch, for diagnostics."""
return _loaded_at
+def _advertises(entry: Mapping[str, Any], parameter: str) -> bool:
+ """True iff ``supported_parameters`` is a list containing ``parameter``.
+
+ Strict on type: a string value would make ``in`` a substring test and
+ a dict a key test — remote data must not flip a capability that way.
+ """
+ params = entry.get("supported_parameters")
+ return isinstance(params, list) and parameter in params
+
+
def _price(entry: Mapping[str, Any], key: str) -> float:
pricing = entry.get("pricing")
if not isinstance(pricing, Mapping):
@@ -93,7 +129,7 @@ def _is_candidate(entry: Mapping[str, Any], providers: frozenset[str]) -> bool:
provider, _, _rest = model_id.partition("/")
if provider not in providers:
return False
- if "tools" not in (entry.get("supported_parameters") or []):
+ if not _advertises(entry, "tools"):
return False
arch = entry.get("architecture")
outputs = arch.get("output_modalities") if isinstance(arch, Mapping) else None
@@ -194,7 +230,7 @@ async def refresh_openrouter_catalog(settings: Any) -> bool:
Never raises: a failure logs a warning and leaves the previous cache
(or the never-loaded state → registry fallback) untouched.
"""
- global _loaded_models, _loaded_at
+ global _loaded_models, _loaded_reasoning, _loaded_at
try:
entries = await fetch_catalog(
base_url=settings.openrouter_base_url,
@@ -215,12 +251,14 @@ async def refresh_openrouter_catalog(settings: Any) -> bool:
)
return False
_loaded_models = models
+ _loaded_reasoning = reasoning_capable_ids(entries) & frozenset(models)
_loaded_at = time.time()
logger.info(
- "OpenRouter catalog loaded: %d model(s) from %d catalog entries "
- "(providers=%s, per_provider=%d)",
+ "OpenRouter catalog loaded: %d model(s) from %d catalog entries, "
+ "%d with reasoning support (providers=%s, per_provider=%d)",
len(models),
len(entries),
+ len(_loaded_reasoning),
",".join(settings.openrouter_catalog_providers),
settings.openrouter_catalog_per_provider,
)
@@ -247,6 +285,7 @@ async def run_catalog_refresher(settings: Any) -> None:
def _reset_for_tests() -> None:
- global _loaded_models, _loaded_at
+ global _loaded_models, _loaded_reasoning, _loaded_at
_loaded_models = None
+ _loaded_reasoning = frozenset()
_loaded_at = None
diff --git a/packages/core/openexecutive/providers/registry.py b/packages/core/openexecutive/providers/registry.py
index f1da5f74..10020722 100644
--- a/packages/core/openexecutive/providers/registry.py
+++ b/packages/core/openexecutive/providers/registry.py
@@ -76,6 +76,30 @@ _CLAUDE_ID_RE = re.compile(
# Slugs on the OpenRouter side that are Claude models (either derived from an
# Anthropic id above, or listed verbatim by the live catalog).
_OPENROUTER_CLAUDE_PREFIX = "anthropic/claude-"
+_HAIKU_FAMILY = "haiku"
+
+
+def model_supports_deep_reasoning(model: str) -> bool:
+ """Whether the "Deep reasoning" toggle may add thinking fields for ``model``.
+
+ Haiku is the one Claude family that rejects adaptive thinking and the
+ ``output_config.effort`` field outright (HTTP 400 from Anthropic), so it
+ is excluded whether addressed by its Anthropic id or its OpenRouter slug,
+ in current or legacy naming. The check is scoped to Claude names, so an
+ unrelated slug that merely contains "haiku" keeps deep reasoning. Everything else is allowed
+ here; the provider feature gate then drops the fields for models that
+ can't actually reason, so a wrong guess costs nothing. Mirrors the
+ Council UI guard.
+ """
+ lowered = model.lower()
+ is_claude_name = lowered.startswith("claude-") or lowered.startswith(
+ _OPENROUTER_CLAUDE_PREFIX
+ )
+ # Scoped substring: only a Claude id / slug can be Haiku, but within that
+ # namespace the family may sit first (``claude-haiku-4-5``,
+ # ``anthropic/claude-haiku-4.5``) or last (legacy
+ # ``claude-3-5-haiku-20241022``, ``anthropic/claude-3.5-haiku``).
+ return not (is_claude_name and _HAIKU_FAMILY in lowered)
def openrouter_slug_for_claude(model: str) -> str | None:
@@ -116,6 +140,17 @@ _DEFAULT_NON_CLAUDE_SPEC = FeatureSpec(
supports_tool_use=True,
)
+# Non-Claude model whose live catalog entry advertises ``reasoning``
+# support: keep the Anthropic ``thinking`` / ``output_config`` fields so the
+# translator can turn them into OpenRouter's ``reasoning`` parameter. Cache
+# and web-search stay off — those really are Anthropic-only.
+_NON_CLAUDE_REASONING_SPEC = FeatureSpec(
+ supports_cache_control=False,
+ supports_thinking=True,
+ supports_web_search=False,
+ supports_tool_use=True,
+)
+
def _local_models(settings: Any) -> list[str]:
"""Configured local model slugs, or ``[]`` when local routing is off.
@@ -194,6 +229,8 @@ def _openrouter_model_resolver(model: str) -> tuple[str, FeatureSpec] | None:
* Verbatim Claude slug from the catalog (``anthropic/claude-opus-4.8``) →
unchanged, Claude spec — OpenRouter forwards cache_control / thinking
to Anthropic for these, so stripping them would only cost money.
+ * Non-Claude slug the catalog marks reasoning-capable → unchanged,
+ thinking kept (translated to OpenRouter ``reasoning``), rest stripped.
* Anything else → None; the provider applies the non-Claude default.
"""
slug = openrouter_slug_for_claude(model)
@@ -201,6 +238,11 @@ def _openrouter_model_resolver(model: str) -> tuple[str, FeatureSpec] | None:
return slug, _CLAUDE_FEATURE_SPEC
if model.startswith(_OPENROUTER_CLAUDE_PREFIX):
return model, _CLAUDE_FEATURE_SPEC
+ # Non-Claude: the live catalog knows whether OpenRouter will honour a
+ # ``reasoning`` request for this slug. Unknown (fallback list, or a slug
+ # outside the catalog) keeps the conservative thinking-off default.
+ if openrouter_catalog.supports_reasoning(model):
+ return model, _NON_CLAUDE_REASONING_SPEC
return None
diff --git a/packages/core/openexecutive/providers/translator.py b/packages/core/openexecutive/providers/translator.py
index eea7cdf1..7eca1474 100644
--- a/packages/core/openexecutive/providers/translator.py
+++ b/packages/core/openexecutive/providers/translator.py
@@ -19,9 +19,18 @@ What we DO NOT translate:
For non-Anthropic slugs the feature_gate has already stripped them
before we get here, so the no-cache_control path falls back to the
legacy string-flatten form for maximum upstream compatibility.
-* Anthropic thinking / output_config blocks — feature_gate has either
- preserved them (Claude family) or popped them (non-Claude); we just
- forward whatever is left.
+* Anthropic thinking / output_config blocks are NOT forwarded verbatim —
+ OpenRouter has no ``thinking`` field. When feature_gate has preserved
+ them (Claude family, or a catalog model that advertises ``reasoning``
+ support) ``to_openai_request`` translates their intent into OpenRouter's
+ unified ``reasoning`` parameter (``{"effort": ...}`` for adaptive
+ thinking, ``{"max_tokens": N}`` for a legacy ``budget_tokens`` request).
+ OpenRouter maps that onto each vendor's native form (Anthropic budget /
+ effort, OpenAI reasoning effort, Gemini thinkingLevel, …). The
+ ``reasoning`` / ``reasoning_details`` fields OpenRouter adds to the
+ response are ignored by the response path — only ``content`` and
+ ``tool_calls`` are read. See
+ https://openrouter.ai/docs/guides/best-practices/reasoning-tokens.
* Web-search server tools — feature_gate stripped these for non-Claude
models before we ran. For Claude family (where feature_gate keeps them)
the Anthropic ``web_search_*`` server tool can't be executed by
@@ -212,6 +221,7 @@ def _assistant_content_to_openai(content: Any) -> dict[str, Any]:
text_chunks: list[str] = []
tool_calls: list[dict[str, Any]] = []
+ reasoning_details: list[Any] = []
for block in content:
if not isinstance(block, dict):
continue
@@ -220,6 +230,10 @@ def _assistant_content_to_openai(content: Any) -> dict[str, Any]:
txt = block.get("text", "")
if isinstance(txt, str) and txt:
text_chunks.append(txt)
+ elif btype == OPENROUTER_REASONING_BLOCK:
+ details = block.get("reasoning_details")
+ if isinstance(details, list):
+ reasoning_details.extend(details)
elif btype == "tool_use":
tool_calls.append(
{
@@ -234,6 +248,8 @@ def _assistant_content_to_openai(content: Any) -> dict[str, Any]:
out: dict[str, Any] = {"role": "assistant"}
out["content"] = "\n\n".join(text_chunks) if text_chunks else None
+ if reasoning_details:
+ out["reasoning_details"] = reasoning_details
if tool_calls:
out["tool_calls"] = tool_calls
return out
@@ -318,6 +334,47 @@ def _web_search_plugin(tools: Any) -> dict[str, Any] | None:
return None
+# OpenRouter's accepted ``reasoning.effort`` strings. Anthropic's
+# ``output_config.effort`` values (low / medium / high / xhigh / max) are a
+# subset, so they pass through unchanged. Anything else (or no effort at
+# all) falls back to "low" — the cheapest real tier and this codebase's
+# SPECIALIST_EFFORT default — so a typo can never silently escalate to the
+# most expensive reasoning budget.
+_OPENROUTER_EFFORT_LEVELS = frozenset(
+ {"none", "minimal", "low", "medium", "high", "xhigh", "max"}
+)
+_DEFAULT_REASONING_EFFORT = "low"
+
+
+def _translate_reasoning(anthropic_kwargs: dict[str, Any]) -> dict[str, Any] | None:
+ """Anthropic ``thinking`` + ``output_config.effort`` → OpenRouter ``reasoning``.
+
+ * ``{"type": "adaptive"}`` (current models) → ``{"effort": <level>}`` where
+ the level comes from ``output_config.effort``, defaulting to "low".
+ * ``{"type": "enabled", "budget_tokens": N}`` (pre-4.6 models) →
+ ``{"max_tokens": N}``.
+ * ``{"type": "disabled"}``, absent, or malformed → ``None`` (no field).
+ """
+ thinking = anthropic_kwargs.get("thinking")
+ if not isinstance(thinking, dict):
+ return None
+ kind = thinking.get("type")
+ if kind == "enabled":
+ budget = thinking.get("budget_tokens")
+ if isinstance(budget, int) and not isinstance(budget, bool) and budget > 0:
+ return {"max_tokens": budget}
+ # ``enabled`` with no usable budget is malformed — Anthropic itself
+ # would reject it — so send no reasoning rather than guessing.
+ return None
+ if kind != "adaptive":
+ return None
+ output_config = anthropic_kwargs.get("output_config")
+ effort = output_config.get("effort") if isinstance(output_config, dict) else None
+ if not isinstance(effort, str) or effort not in _OPENROUTER_EFFORT_LEVELS:
+ effort = _DEFAULT_REASONING_EFFORT
+ return {"effort": effort}
+
+
def to_openai_request(model_slug: str, anthropic_kwargs: dict[str, Any]) -> dict[str, Any]:
"""Translate an Anthropic ``messages.create`` kwargs dict to an OpenAI
``/chat/completions`` body. ``model_slug`` is the OpenRouter model id."""
@@ -357,6 +414,13 @@ def to_openai_request(model_slug: str, anthropic_kwargs: dict[str, Any]) -> dict
if tool_choice is not None:
body["tool_choice"] = _translate_tool_choice(tool_choice)
+ # Deep reasoning: the Council checkbox sets Anthropic-native ``thinking``
+ # + ``output_config.effort``; feature_gate leaves them in place only for
+ # models that can reason, and here they become OpenRouter's ``reasoning``.
+ reasoning = _translate_reasoning(anthropic_kwargs)
+ if reasoning is not None:
+ body["reasoning"] = reasoning
+
# Ask OpenRouter to report the actual charged cost of this generation in
# the response `usage` block (and the final usage chunk when streaming).
# This is a read-only accounting flag — it does not alter the messages,
@@ -392,6 +456,35 @@ def _block(type_: str, **fields: Any) -> SimpleNamespace:
return SimpleNamespace(type=type_, **fields)
+# Synthetic content-block type carrying OpenRouter's ``reasoning_details``
+# through the Anthropic-shaped message so a multi-turn tool loop can echo
+# it back. Always the LAST content block, so ``content[0]`` stays whatever
+# it was before (text, or tool_use for a text-less turn). OpenRouter requires the array to be replayed verbatim on the
+# assistant turn for reasoning continuity (Anthropic 400s a tool_use turn
+# whose thinking was dropped; other vendors lose their chain of thought).
+# https://openrouter.ai/docs/guides/best-practices/reasoning-tokens#preserving-reasoning-blocks
+OPENROUTER_REASONING_BLOCK = "openrouter_reasoning"
+
+
+def reasoning_replay_block(block: Any) -> dict[str, Any] | None:
+ """Dict form of a response ``openrouter_reasoning`` block for the next
+ assistant turn, or ``None`` for any other block. Every multi-turn tool
+ loop that rebuilds its assistant history block-by-block calls this so
+ reasoning continuity is preserved on the OpenRouter path."""
+ if getattr(block, "type", None) != OPENROUTER_REASONING_BLOCK:
+ return None
+ details = getattr(block, "reasoning_details", None)
+ if not isinstance(details, list) or not details:
+ return None
+ return {"type": OPENROUTER_REASONING_BLOCK, "reasoning_details": list(details)}
+
+
+def _reasoning_details_block(details: Any) -> SimpleNamespace | None:
+ if isinstance(details, list) and details:
+ return _block(OPENROUTER_REASONING_BLOCK, reasoning_details=list(details))
+ return None
+
+
def _stop_reason_from_openai(reason: str | None) -> str:
"""Map OpenAI ``finish_reason`` to Anthropic ``stop_reason``."""
if reason == "tool_calls" or reason == "function_call":
@@ -514,6 +607,14 @@ def from_openai_response(body: dict[str, Any]) -> SimpleNamespace:
)
)
+ # Reasoning LAST. Several callers read ``content[0].text`` (the SDK
+ # itself only ever emits text first for those prompts), so the synthetic
+ # block must never displace the text block. Order carries no meaning on
+ # the replay side — ``reasoning_details`` is a separate message field.
+ reasoning_block = _reasoning_details_block(msg.get("reasoning_details"))
+ if reasoning_block is not None:
+ content_blocks.append(reasoning_block)
+
usage = body.get("usage") or {}
cache_read, cache_create = _extract_cache_token_counts(usage)
return SimpleNamespace(
@@ -594,6 +695,9 @@ class StreamAccumulator:
self._cite_pending = ""
# tool_calls[idx] = {"id": ..., "name": ..., "arg_chunks": [..]}
self._tool_calls: dict[int, dict[str, Any]] = {}
+ # OpenRouter streams ``delta.reasoning_details`` chunks; collected
+ # verbatim and re-emitted as one block at finalize().
+ self._reasoning_details: list[Any] = []
self._finish_reason: str | None = None
self._usage: dict[str, Any] = {}
self._model: str = ""
@@ -645,6 +749,10 @@ class StreamAccumulator:
)
)
+ details = delta.get("reasoning_details")
+ if isinstance(details, list):
+ self._reasoning_details.extend(details)
+
for tc in delta.get("tool_calls") or []:
idx = tc.get("index", 0)
slot = self._tool_calls.setdefault(
@@ -704,6 +812,10 @@ class StreamAccumulator:
input=_strip_cite_in_value(parsed),
)
)
+ # Reasoning last — see from_openai_response for why.
+ reasoning_block = _reasoning_details_block(self._reasoning_details)
+ if reasoning_block is not None:
+ content_blocks.append(reasoning_block)
cache_read, cache_create = _extract_cache_token_counts(self._usage)
return SimpleNamespace(
id=self._id,
diff --git a/packages/core/openexecutive/workflows/executive_reflection.py b/packages/core/openexecutive/workflows/executive_reflection.py
index 74b1e6d6..30f128d5 100644
--- a/packages/core/openexecutive/workflows/executive_reflection.py
+++ b/packages/core/openexecutive/workflows/executive_reflection.py
@@ -258,6 +258,7 @@ def _render_reflection_context(
# `executive_research` can reuse them without an underscore-import
# tripwire; this re-export keeps any callers that still import the
# private names from this module working.
+from openexecutive.providers.translator import reasoning_replay_block # noqa: E402
from openexecutive.workflows._synthesis import ( # noqa: E402
execute_tool_calls as _execute_tool_calls,
)
@@ -530,6 +531,9 @@ class ExecutiveReflectionWorkflow(Workflow):
"name": getattr(block, "name", ""),
"input": getattr(block, "input", {}) or {},
})
+ elif (replay := reasoning_replay_block(block)) is not None:
+ # OpenRouter reasoning continuity across tool iterations.
+ assistant_blocks.append(replay)
messages.append({"role": "assistant", "content": assistant_blocks})
# Pair each tool_use with the matching summary by index.
diff --git a/packages/core/openexecutive/workflows/executive_research.py b/packages/core/openexecutive/workflows/executive_research.py
index 3265e24f..7f3aaa59 100644
--- a/packages/core/openexecutive/workflows/executive_research.py
+++ b/packages/core/openexecutive/workflows/executive_research.py
@@ -52,6 +52,7 @@ from openexecutive.monitoring.research.models import (
from openexecutive.monitoring.research.specialist_research import (
research_one_specialist,
)
+from openexecutive.providers.translator import reasoning_replay_block
from openexecutive.workflows.base import (
Workflow,
WorkflowEvent,
@@ -843,6 +844,9 @@ async def _executive_synthesis_loop(
"name": getattr(block, "name", ""),
"input": getattr(block, "input", {}) or {},
})
+ elif (replay := reasoning_replay_block(block)) is not None:
+ # OpenRouter reasoning continuity across tool iterations.
+ assistant_blocks.append(replay)
messages.append({"role": "assistant", "content": assistant_blocks})
tool_results: list[dict[str, Any]] = []
@@ -951,6 +955,9 @@ async def _watchlist_analysis_loop(
"name": getattr(block, "name", ""),
"input": getattr(block, "input", {}) or {},
})
+ elif (replay := reasoning_replay_block(block)) is not None:
+ # OpenRouter reasoning continuity across tool iterations.
+ assistant_blocks.append(replay)
messages.append({"role": "assistant", "content": assistant_blocks})
tool_results: list[dict[str, Any]] = []
diff --git a/packages/core/tests/unit/test_deep_reasoning_support.py b/packages/core/tests/unit/test_deep_reasoning_support.py
new file mode 100644
index 00000000..4cdffe2d
--- /dev/null
+++ b/packages/core/tests/unit/test_deep_reasoning_support.py
@@ -0,0 +1,488 @@
+"""Deep reasoning beyond Anthropic-direct Claude.
+
+The Council "Deep reasoning" checkbox sets Anthropic-native ``thinking`` +
+``output_config.effort``. These tests pin the three pieces that make it
+work (or safely no-op) for every model:
+
+1. Translator: those fields become OpenRouter's unified ``reasoning``
+ parameter on the OpenRouter path — for Claude-via-OpenRouter AND for
+ non-Claude models — and are never forwarded as raw ``thinking``.
+2. Registry / catalog: a non-Claude catalog model advertising "reasoning"
+ in ``supported_parameters`` keeps its thinking fields through the
+ feature gate; one that doesn't (or an unknown slug) has them stripped.
+3. Haiku guard: Haiku rejects adaptive thinking, so the agent call paths
+ never attach it for a Haiku model, whatever the checkbox says.
+"""
+from __future__ import annotations
+
+import os
+from types import SimpleNamespace
+from typing import Any
+from unittest.mock import AsyncMock, patch
+
+os.environ.setdefault("ANTHROPIC_API_KEY", "sk-test-not-used")
+
+import httpx # noqa: E402
+import pytest # noqa: E402
+
+from openexecutive.providers import openrouter_catalog as catalog # noqa: E402
+from openexecutive.providers import registry as registry_mod # noqa: E402
+from openexecutive.providers.feature_gate import apply_feature_gates # noqa: E402
+from openexecutive.providers.registry import ( # noqa: E402
+ get_provider,
+ model_supports_deep_reasoning,
+)
+from openexecutive.providers.translator import ( # noqa: E402
+ OPENROUTER_REASONING_BLOCK,
+ StreamAccumulator,
+ from_openai_response,
+ reasoning_replay_block,
+ to_openai_request,
+)
+
+
[email protected](autouse=True)
+def _reset() -> Any:
+ catalog._reset_for_tests()
+ registry_mod._reset_for_tests()
+ yield
+ catalog._reset_for_tests()
+ registry_mod._reset_for_tests()
+
+
+def _registry_settings(*, enabled: bool = True) -> Any:
+ return SimpleNamespace(
+ anthropic_api_key="sk-test",
+ openrouter_enabled=enabled,
+ openrouter_api_key="sk-or-test",
+ openrouter_base_url="https://openrouter.example/api/v1",
+ openrouter_app_title="Open Executive",
+ openrouter_referer=None,
+ openrouter_timeout_s=180.0,
+ local_models_enabled=False,
+ local_base_url=None,
+ local_models=[],
+ local_api_key=None,
+ local_timeout_s=300.0,
+ )
+
+
+def _deep_kwargs(model: str, effort: str = "low") -> dict[str, Any]:
+ return {
+ "model": model,
+ "max_tokens": 16000,
+ "system": [{"type": "text", "text": "sys"}],
+ "messages": [{"role": "user", "content": "hi"}],
+ "thinking": {"type": "adaptive"},
+ "output_config": {"effort": effort},
+ }
+
+
+# --------------------------------------------------------------------------
+# 1. Translator: thinking + effort → OpenRouter ``reasoning``
+# --------------------------------------------------------------------------
+
+
[email protected]("effort", ["low", "medium", "high", "xhigh", "max"])
+def test_adaptive_thinking_becomes_reasoning_effort(effort: str) -> None:
+ body = to_openai_request("openai/gpt-6", _deep_kwargs("openai/gpt-6", effort))
+ assert body["reasoning"] == {"effort": effort}
+ # Anthropic-only fields must never leak into an OpenAI-format body.
+ assert "thinking" not in body
+ assert "output_config" not in body
+
+
+def test_adaptive_thinking_without_effort_defaults_to_low() -> None:
+ kwargs = _deep_kwargs("openai/gpt-6")
+ del kwargs["output_config"]
+ assert to_openai_request("openai/gpt-6", kwargs)["reasoning"] == {"effort": "low"}
+
+
[email protected]("bad", ["ludicrous", "High", "low ", "", 3, None])
+def test_invalid_effort_fails_closed_to_low(bad: Any) -> None:
+ """A mistyped SPECIALIST_EFFORT must never escalate to an expensive tier."""
+ kwargs = _deep_kwargs("openai/gpt-6")
+ kwargs["output_config"] = {"effort": bad}
+ assert to_openai_request("openai/gpt-6", kwargs)["reasoning"] == {"effort": "low"}
+
+
+def test_legacy_budget_tokens_becomes_reasoning_max_tokens() -> None:
+ kwargs = _deep_kwargs("x")
+ kwargs["thinking"] = {"type": "enabled", "budget_tokens": 4096}
+ assert to_openai_request("x", kwargs)["reasoning"] == {"max_tokens": 4096}
+
+
+ "thinking",
+ [None, {"type": "disabled"}, "adaptive", {}],
+ ids=["absent", "disabled", "not-a-dict", "no-type"],
+)
+def test_no_reasoning_field_when_thinking_is_off_or_malformed(thinking: Any) -> None:
+ kwargs = _deep_kwargs("x")
+ if thinking is None:
+ del kwargs["thinking"]
+ else:
+ kwargs["thinking"] = thinking
+ assert "reasoning" not in to_openai_request("x", kwargs)
+
+
[email protected]("budget", [0, -1, None, True, "4096"])
+def test_enabled_without_usable_budget_sends_no_reasoning(budget: Any) -> None:
+ kwargs = _deep_kwargs("x", "medium")
+ kwargs["thinking"] = {"type": "enabled", "budget_tokens": budget}
+ assert "reasoning" not in to_openai_request("x", kwargs)
+
+
+# --------------------------------------------------------------------------
+# 2. Registry + catalog: which models keep their thinking fields
+# --------------------------------------------------------------------------
+
+
+def _load_catalog(models: list[str], reasoning: list[str]) -> None:
+ catalog._loaded_models = list(models)
+ catalog._loaded_reasoning = frozenset(reasoning)
+
+
+def test_supports_reasoning_reports_catalog_capability() -> None:
+ assert catalog.supports_reasoning("openai/gpt-6") is None # nothing loaded
+ _load_catalog(["openai/gpt-6", "meta-llama/llama-4-scout"], ["openai/gpt-6"])
+ assert catalog.supports_reasoning("openai/gpt-6") is True
+ assert catalog.supports_reasoning("meta-llama/llama-4-scout") is False
+ assert catalog.supports_reasoning("not/in-catalog") is None
+
+
+def test_reasoning_capable_ids_reads_supported_parameters() -> None:
+ entries = [
+ {"id": "a/one", "supported_parameters": ["tools", "reasoning"]},
+ {"id": "a/two", "supported_parameters": ["tools"]},
+ {"id": "a/three"},
+ {"id": None, "supported_parameters": ["reasoning"]},
+ ]
+ assert catalog.reasoning_capable_ids(entries) == frozenset({"a/one"})
+
+
+def test_catalog_refresh_records_reasoning_subset(monkeypatch: pytest.MonkeyPatch) -> None:
+ def _entry(model_id: str, *params: str) -> dict[str, Any]:
+ return {
+ "id": model_id,
+ "created": 1,
+ "supported_parameters": ["tools", *params],
+ "pricing": {"prompt": "0.000001", "completion": "0.000002"},
+ "architecture": {"output_modalities": ["text"]},
+ }
+
+ payload = {"data": [_entry("openai/gpt-6", "reasoning"), _entry("meta-llama/llama-4-scout")]}
+ real_client = httpx.AsyncClient
+
+ def _factory(**kwargs: Any) -> httpx.AsyncClient:
+ kwargs["transport"] = httpx.MockTransport(lambda _r: httpx.Response(200, json=payload))
+ return real_client(**kwargs)
+
+ monkeypatch.setattr(catalog.httpx, "AsyncClient", _factory)
+ settings = SimpleNamespace(
+ openrouter_base_url="https://openrouter.example/api/v1",
+ openrouter_catalog_timeout_s=1.0,
+ openrouter_catalog_providers=["openai", "meta-llama"],
+ openrouter_catalog_per_provider=6,
+ openrouter_catalog_refresh_s=0.0,
+ )
+ import asyncio
+
+ assert asyncio.run(catalog.refresh_openrouter_catalog(settings)) is True
+ assert catalog.supports_reasoning("openai/gpt-6") is True
+ assert catalog.supports_reasoning("meta-llama/llama-4-scout") is False
+
+
+def test_openrouter_provider_keeps_thinking_only_for_reasoning_capable_models(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """End-to-end through the registry resolver + feature gate + translator:
+ the request body carries ``reasoning`` exactly when the model can use it."""
+ monkeypatch.setattr(
+ "openexecutive.providers.registry.get_settings",
+ lambda: _registry_settings(),
+ )
+ _load_catalog(
+ ["openai/gpt-6", "meta-llama/llama-4-scout", "anthropic/claude-opus-4.8"],
+ ["openai/gpt-6", "anthropic/claude-opus-4.8"],
+ )
+ provider = get_provider("openai/gpt-6")
+
+ def _body_for(model: str) -> dict[str, Any]:
+ slug, spec = provider._resolve(model)
+ kwargs = _deep_kwargs(model)
+ kwargs.pop("model")
+ return to_openai_request(slug, apply_feature_gates(spec, kwargs))
+
+ # Reasoning-capable non-Claude: thinking survives the gate → reasoning.
+ assert _body_for("openai/gpt-6")["reasoning"] == {"effort": "low"}
+ # Catalog says no reasoning: stripped, no field.
+ assert "reasoning" not in _body_for("meta-llama/llama-4-scout")
+ # Unknown slug (e.g. from the hardcoded fallback): conservative default.
+ assert "reasoning" not in _body_for("deepseek/not-in-catalog")
+ # Claude via OpenRouter, both spellings: reasoning is sent.
+ assert _body_for("claude-sonnet-5")["reasoning"] == {"effort": "low"}
+ assert _body_for("anthropic/claude-opus-4.8")["reasoning"] == {"effort": "low"}
+
+
+# --------------------------------------------------------------------------
+# 3. Haiku guard
+# --------------------------------------------------------------------------
+
+
+ ("model", "expected"),
+ [
+ ("claude-haiku-4-5", False),
+ ("claude-haiku-4-5-20251001", False),
+ ("anthropic/claude-haiku-4.5", False),
+ ("Claude-Haiku-4-5", False),
+ # Legacy ordering with the family last.
+ ("claude-3-5-haiku-20241022", False),
+ ("anthropic/claude-3.5-haiku", False),
+ ("anthropic/claude-3-haiku", False),
+ ("claude-sonnet-5", True),
+ ("claude-opus-5", True),
+ ("openai/gpt-6", True),
+ ("llama3.3", True),
+ # Structural match: an unrelated slug that merely contains the word
+ # keeps deep reasoning; a Haiku alias without the word is not caught
+ # here (the feature gate / Anthropic 400 is the backstop for that).
+ ("local/haiku-clone", True),
+ ("qwen/haiku-poet-7b", True),
+ ],
+)
+def test_model_supports_deep_reasoning(model: str, expected: bool) -> None:
+ assert model_supports_deep_reasoning(model) is expected
+
+
+async def _analyze_kwargs(model: str, deep: bool) -> dict[str, Any]:
+ from openexecutive.agents.strategy import StrategyAgent
+
+ create = AsyncMock(
+ return_value=SimpleNamespace(content=[SimpleNamespace(type="text", text="ok")])
+ )
+ fake_provider = SimpleNamespace(messages_create=create)
+ with patch("openexecutive.agents.base.get_provider", return_value=fake_provider):
+ await StrategyAgent().analyze(
+ "q", model_override=model, deep_reasoning_override=deep
+ )
+ return create.await_args.kwargs
+
+
+async def test_agent_never_sends_thinking_to_haiku() -> None:
+ kw = await _analyze_kwargs("claude-haiku-4-5", deep=True)
+ assert kw["model"] == "claude-haiku-4-5"
+ assert "thinking" not in kw
+ assert "output_config" not in kw
+
+
+async def test_agent_sends_thinking_to_sonnet_when_deep_is_on() -> None:
+ kw = await _analyze_kwargs("claude-sonnet-5", deep=True)
+ assert kw["thinking"] == {"type": "adaptive"}
+ assert "effort" in kw["output_config"]
+
+
+async def test_agent_sends_no_thinking_when_deep_is_off() -> None:
+ kw = await _analyze_kwargs("claude-sonnet-5", deep=False)
+ assert "thinking" not in kw
+
+
+# --------------------------------------------------------------------------
+# 4. Reasoning continuity across a multi-turn tool loop (OpenRouter path)
+# --------------------------------------------------------------------------
+
+_DETAILS = [{"type": "reasoning.summary", "summary": "think", "id": "r1", "format": "x"}]
+
+
+def test_response_carries_reasoning_details_as_a_block() -> None:
+ msg = from_openai_response(
+ {
+ "choices": [
+ {
+ "message": {
+ "content": "hi",
+ "reasoning_details": _DETAILS,
+ "tool_calls": [
+ {"id": "c1", "function": {"name": "f", "arguments": "{}"}}
+ ],
+ },
+ "finish_reason": "tool_calls",
+ }
+ ]
+ }
+ )
+ types = [b.type for b in msg.content]
+ # Reasoning is LAST: ``content[0]`` must stay the text block for the
+ # callers that index it directly (wait_for_human, eval judges).
+ assert types == ["text", "tool_use", OPENROUTER_REASONING_BLOCK]
+ assert msg.content[0].text == "hi"
+ assert msg.content[-1].reasoning_details == _DETAILS
+ # Absent / empty / non-list → no block.
+ for bad in (None, [], "x"):
+ m = from_openai_response({"choices": [{"message": {"content": "a", "reasoning_details": bad}}]})
+ assert [b.type for b in m.content] == ["text"]
+
+
+def test_stream_accumulates_reasoning_details_into_one_block() -> None:
+ acc = StreamAccumulator()
+ acc.feed({"id": "m", "choices": [{"delta": {"reasoning_details": _DETAILS[:1]}}]})
+ acc.feed({"choices": [{"delta": {"reasoning_details": [{"type": "reasoning.text", "text": "…"}]}}]})
+ acc.feed({"choices": [{"delta": {"content": "answer"}, "finish_reason": "stop"}]})
+ final = acc.finalize()
+ assert [b.type for b in final.content] == ["text", OPENROUTER_REASONING_BLOCK]
+ assert final.content[0].text == "answer"
+ assert len(final.content[-1].reasoning_details) == 2
+
+
+def test_reasoning_block_is_replayed_as_reasoning_details_on_assistant_turn() -> None:
+ body = to_openai_request(
+ "openai/gpt-6",
+ {
+ "messages": [
+ {"role": "user", "content": "q"},
+ {
+ "role": "assistant",
+ "content": [
+ {"type": OPENROUTER_REASONING_BLOCK, "reasoning_details": _DETAILS},
+ {"type": "tool_use", "id": "c1", "name": "f", "input": {}},
+ ],
+ },
+ {
+ "role": "user",
+ "content": [
+ {"type": "tool_result", "tool_use_id": "c1", "content": "r"}
+ ],
+ },
+ ]
+ },
+ )
+ assistant = [m for m in body["messages"] if m["role"] == "assistant"][0]
+ assert assistant["reasoning_details"] == _DETAILS
+ assert assistant["tool_calls"][0]["id"] == "c1"
+ # The synthetic block never leaks as text.
+ assert assistant["content"] is None
+
+
+def test_research_loop_echoes_reasoning_block_into_history() -> None:
+ from openexecutive.monitoring.research.agentic import _assistant_turn
+
+ block = SimpleNamespace(type=OPENROUTER_REASONING_BLOCK, reasoning_details=_DETAILS)
+ tool = SimpleNamespace(type="tool_use", id="c1", name="scrape_url", input={"url": "u"})
+ history, scrapes = _assistant_turn([block, tool])
+ assert history[0] == {"type": OPENROUTER_REASONING_BLOCK, "reasoning_details": _DETAILS}
+ assert history[1]["type"] == "tool_use"
+ assert scrapes == [{"id": "c1", "input": {"url": "u"}}]
+
+
+# --------------------------------------------------------------------------
+# 5. Remote catalog data: capability flags need a real list
+# --------------------------------------------------------------------------
+
+
+ "params",
+ ["tools,reasoning", {"reasoning": True}, None, 7],
+ ids=["string", "dict", "none", "int"],
+)
+def test_reasoning_capability_requires_a_list(params: Any) -> None:
+ assert catalog.reasoning_capable_ids([{"id": "a/one", "supported_parameters": params}]) == frozenset()
+
+
+def test_tools_capability_requires_a_list() -> None:
+ entry = {
+ "id": "openai/x",
+ "created": 1,
+ "supported_parameters": "tools", # substring would match; a list is required
+ "pricing": {"prompt": "0.000001", "completion": "0.000002"},
+ "architecture": {"output_modalities": ["text"]},
+ }
+ assert catalog.select_models([entry], providers=["openai"]) == []
+
+
+# --------------------------------------------------------------------------
+# 6. Config: SPECIALIST_EFFORT is validated at boot
+# --------------------------------------------------------------------------
+
+
+def test_specialist_effort_rejects_invalid_values(monkeypatch: pytest.MonkeyPatch) -> None:
+ from pydantic import ValidationError
+
+ from openexecutive.config import Settings
+
+ monkeypatch.setenv("EXEC_EMAIL_ADDRESS", "[email protected]")
+ monkeypatch.setenv("SPECIALIST_EFFORT", "Low")
+ with pytest.raises(ValidationError):
+ Settings()
+ monkeypatch.setenv("SPECIALIST_EFFORT", "xhigh")
+ assert Settings().specialist_effort == "xhigh"
+
+
+# --------------------------------------------------------------------------
+# 7. A reasoning-only (truncated) reply is logged, not silently empty
+# --------------------------------------------------------------------------
+
+
+async def test_empty_specialist_reply_is_logged() -> None:
+ """Asserted on the module logger directly: the app's logging config
+ (exercised by other tests in the suite) turns propagation off for the
+ ``openexecutive`` tree, which would make ``caplog`` miss the record."""
+ from openexecutive.agents import base as base_mod
+ from openexecutive.agents.strategy import StrategyAgent
+
+ create = AsyncMock(return_value=SimpleNamespace(content=[], stop_reason="max_tokens"))
+ with (
+ patch(
+ "openexecutive.agents.base.get_provider",
+ return_value=SimpleNamespace(messages_create=create),
+ ),
+ patch.object(base_mod.logger, "warning") as warn,
+ ):
+ out = await StrategyAgent().analyze(
+ "q", model_override="openai/gpt-6", deep_reasoning_override=True
+ )
+ assert out == ""
+ warn.assert_called_once()
+ rendered = warn.call_args.args[0] % warn.call_args.args[1:]
+ assert "returned no text block" in rendered
+ assert "max_tokens" in rendered
+ assert "openai/gpt-6" in rendered
+
+
+def test_content_zero_stays_text_for_direct_indexers() -> None:
+ """workflows.wait_for_human and evals.judges read ``content[0].text``; a
+ natively-reasoning OpenRouter model returns reasoning_details even when
+ not asked, so the synthetic block must never take slot 0."""
+ msg = from_openai_response(
+ {"choices": [{"message": {"content": "APPROVE", "reasoning_details": _DETAILS}}]}
+ )
+ assert msg.content[0].text == "APPROVE"
+
+
+def test_reasoning_replay_block_helper() -> None:
+ block = SimpleNamespace(type=OPENROUTER_REASONING_BLOCK, reasoning_details=_DETAILS)
+ assert reasoning_replay_block(block) == {
+ "type": OPENROUTER_REASONING_BLOCK,
+ "reasoning_details": _DETAILS,
+ }
+ for other in (
+ SimpleNamespace(type="text", text="x"),
+ SimpleNamespace(type=OPENROUTER_REASONING_BLOCK, reasoning_details=[]),
+ SimpleNamespace(type=OPENROUTER_REASONING_BLOCK, reasoning_details="nope"),
+ SimpleNamespace(type=OPENROUTER_REASONING_BLOCK),
+ object(),
+ ):
+ assert reasoning_replay_block(other) is None
+
+
+def test_every_tool_loop_replays_reasoning() -> None:
+ """The block-by-block assistant-history rebuilders all consult the
+ helper, so continuity isn't a research-loop-only property."""
+ import inspect
+
+ from openexecutive.monitoring.research import agentic
+ from openexecutive.orchestrator import executive
+ from openexecutive.workflows import executive_reflection, executive_research
+
+ for mod in (agentic, executive, executive_research, executive_reflection):
+ assert "reasoning_replay_block(block)" in inspect.getsource(mod), mod.__name__
diff --git a/packages/ui/src/app/council/page.tsx b/packages/ui/src/app/council/page.tsx
index 0e624dac..416783a8 100644
--- a/packages/ui/src/app/council/page.tsx
+++ b/packages/ui/src/app/council/page.tsx
@@ -33,11 +33,28 @@ interface DraftState {
research_focus: string | null;
}
+// Haiku is the one Claude family that rejects adaptive thinking (HTTP 400),
+// so the deep-reasoning toggle is disabled for it whether the slug is the
+// Anthropic id (claude-haiku-4-5) or the OpenRouter form
+// (anthropic/claude-haiku-4.5). Mirrors the backend guard in
+// providers.registry.model_supports_deep_reasoning.
+// Scoped to Claude names (current or legacy ordering), case-insensitive —
+// matches providers.registry.model_supports_deep_reasoning exactly.
+const HAIKU_MODEL_RE = /^(anthropic\/)?claude-.*haiku/i;
+
+function modelSupportsDeepReasoning(model: string): boolean {
+ return !HAIKU_MODEL_RE.test(model);
+}
+
function detailToDraft(d: AgentDetail): DraftState {
return {
role: d.role,
model: d.model,
- deep_reasoning: d.deep_reasoning,
+ // A stored override can pair deep_reasoning=true with a Haiku model
+ // (older UI, direct API call). Mask it on load so the checkbox, the
+ // dirty check and the Save patch all agree — saving then corrects the
+ // persisted row instead of leaving it permanently out of sync.
+ deep_reasoning: d.deep_reasoning && modelSupportsDeepReasoning(d.model),
prompt: d.prompt,
voice_persona_slug: d.voice_persona_slug ?? null,
research_focus: d.research_focus ?? null,
@@ -227,7 +244,7 @@ export default function CouncilPage() {
query: testQuery,
prompt: draft.prompt,
model: draft.model,
- use_deep_reasoning: draft.deep_reasoning,
+ use_deep_reasoning: draft.deep_reasoning && modelSupportsDeepReasoning(draft.model),
});
setTestResult(result.response);
} catch (err) {
@@ -355,7 +372,16 @@ export default function CouncilPage() {
</span>
<select
value={draft.model}
- onChange={(e) => setDraft({ ...draft, model: e.target.value })}
+ onChange={(e) => {
+ const model = e.target.value;
+ setDraft({
+ ...draft,
+ model,
+ deep_reasoning: modelSupportsDeepReasoning(model)
+ ? draft.deep_reasoning
+ : false,
+ });
+ }}
className="mt-1 w-full px-3 py-2 rounded-lg bg-surface border border-line text-fg focus:border-indigo-500/40 focus:outline-none text-sm"
>
{Array.from(new Set([detail.model_default, draft.model, ...models])).map(
@@ -371,14 +397,25 @@ export default function CouncilPage() {
</div>
{detail.name !== "utility_fast" && (
- <label className="flex items-center gap-2 text-xs text-fg-muted">
+ <label
+ className={`flex items-center gap-2 text-xs text-fg-muted ${
+ modelSupportsDeepReasoning(draft.model) ? "" : "opacity-60"
+ }`}
+ title={
+ modelSupportsDeepReasoning(draft.model)
+ ? "Adaptive thinking on Claude Opus/Sonnet, and on any OpenRouter model whose catalog entry supports reasoning. Ignored by models that can't reason."
+ : "Haiku doesn't support adaptive thinking — pick another model to enable deep reasoning."
+ }
+ >
<input
type="checkbox"
- checked={draft.deep_reasoning}
+ checked={draft.deep_reasoning && modelSupportsDeepReasoning(draft.model)}
+ disabled={!modelSupportsDeepReasoning(draft.model)}
onChange={(e) => setDraft({ ...draft, deep_reasoning: e.target.checked })}
- className="rounded border-line-strong bg-surface"
+ className="rounded border-line-strong bg-surface disabled:cursor-not-allowed"
/>
- Deep reasoning (adaptive thinking — Opus only)
+ Deep reasoning (adaptive thinking — Claude Opus/Sonnet and reasoning-capable
+ OpenRouter models; not available on Haiku)
<span className="text-[10px] text-fg-subtle">
default: {detail.deep_reasoning_default ? "on" : "off"}
</span>