AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).
feat(providers): keep web search for every OpenRouter model
Rufus2cfd1c26c8c0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 52ac63bc..917775d4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -118,6 +118,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0routing pass can no longer start a workflow (`run_workflow` is withheld,`suggest_workflow` remains); the periodic run's default interval movesfrom 120 to 360 minutes.+- **Web search reaches every OpenRouter model.** The provider feature gate+ stripped the web-search tool for non-Claude models, so a research+ specialist or the Executive pinned to Gemini, GPT, Llama, DeepSeek or+ Grok ran without search (and the research prompt then told it to emit+ nothing). The tool is now kept for any OpenRouter model and translated+ into OpenRouter's web plugin, as it already was for Claude via+ OpenRouter; only a self-hosted OpenAI-compatible backend still strips+ it. The plugin runs one search per request and reports no search count.- **Every model call is recorded.** Research specialists, the researchrouting and watchlist passes, triage and the chat memory extractor nowwrite the same `cache_event` audit row the Executive's chat turns alwaysdiff --git a/packages/core/openexecutive/architecture/architecture-facts.yaml b/packages/core/openexecutive/architecture/architecture-facts.yamlindex 0116d097..b573a71b 100644--- a/packages/core/openexecutive/architecture/architecture-facts.yaml+++ b/packages/core/openexecutive/architecture/architecture-facts.yaml@@ -54,8 +54,9 @@ system:in LOCAL_MODELS route to a self-hosted OpenAI-compatible server(Ollama / LM Studio / vLLM / llama.cpp) through the same provider seam,reusing the OpenRouter request/response/stream translator. Those slugs- are added to the Council UI dropdown and get the non-Claude feature- spec (no cache_control / thinking / web_search). This makes+ are added to the Council UI dropdown and get the tools-only local+ feature spec (no cache_control / thinking / web_search — a+ self-hosted server has no search plugin). This makesANTHROPIC_API_KEY optional: a deployment with only local (orOpenRouter) models configured boots with no Anthropic key — theSettings validator just requires that at least one provider is@@ -81,7 +82,7 @@ system:- Company-specific data lives under packages/core/company/ and is gitignored. Never commit it.- Audit writes never break a chat turn or tool call — exceptions are swallowed with a warning.- Provider selection is per-call by model (openexecutive.providers.get_provider(model)). A single chat turn can mix Anthropic-routed Claude calls, OpenRouter-routed non-Claude calls, and locally-routed self-hosted models — no global "current provider" state.- - When a non-Claude or local model is selected, Anthropic-only fields (cache_control on system/tool/user blocks, adaptive thinking + output_config, server-side web_search) are stripped by the feature gate before the request leaves the process. Callers do NOT need to know which model they're routing to.+ - When a non-Claude or local model is selected, Anthropic-only fields (cache_control on system/tool/user blocks, adaptive thinking + output_config) are stripped by the feature gate before the request leaves the process. The web_search server tool is kept for every OpenRouter model (the translator swaps it for OpenRouter's `web` plugin, which serves any model) and stripped only for a self-hosted OpenAI-compatible backend, which has no search plugin. Callers do NOT need to know which model they're routing to.- ANTHROPIC_API_KEY is optional: a Settings validator requires at least one provider (Anthropic key, OpenRouter, or local models) to be configured, so an Anthropic-free deployment is supported but a zero-provider one fails fast at startup.- External-monitor adapters are read-only — they never write to upstream systems. The whole `monitoring/` subsystem is observation-only; surfacing happens through the alert pipeline, never via a direct upstream side-effect.- External signals never auto-execute on the principal's behalf. Every signal that surfaces is proposed via the alert pipeline (and thus subject to triage / mute / severity gates); the scheduler never dispatches an outbound message directly off a signal.@@ -127,10 +128,17 @@ caching:models the feature gate strips cache_control before translation —those backends have no equivalent feature and would reject thefield. The two-block layout above is unchanged either way.- Web search for Claude-via-OpenRouter is preserved by translating the- Anthropic web_search server tool into OpenRouter's ``web`` plugin (see- providers.translator_shapes), so server-side search still runs when- Claude is proxied through OpenRouter.+ Web search via OpenRouter — for Claude and non-Claude models alike —+ is preserved by translating the Anthropic web_search server tool into+ OpenRouter's ``web`` plugin (see providers.translator_shapes), so a+ research specialist or the Executive pinned to e.g. Gemini still+ searches. The plugin is not the Anthropic tool: it runs one+ prompt-derived search per request and injects the results (the model+ cannot search again), ``max_uses`` becomes a result count capped at+ 10, allowed/blocked domain lists are not applied, and OpenRouter+ reports no search count, so `web_search_requests` on those usage rows+ reads 0 even though search ran. Only the self-hosted+ OpenAI-compatible backend strips the tool (no plugin there).providers:module: openexecutive.providers@@ -149,8 +157,11 @@ providers:openexecutive.providers.feature_gate.apply_feature_gates(spec, kwargs)runs inside the OpenRouter provider before translation. Spec-drivenstripping 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.+ thinking + output_config, and — for the local backend only — the+ Anthropic server-side web_search tool; every OpenRouter model keeps+ web_search (supports_web_search=True on both non-Claude specs) so the+ translator can turn it into the ``web`` plugin. A misrouted call+ cannot ship an unsupported field.supports_thinking is TRUE for the Claude family and for any non-Claudecatalog slug whose OpenRouter entry lists "reasoning" insupported_parameters (registry._openrouter_model_resolver consults@@ -202,7 +213,8 @@ providers:server-side web_search tool (no input_schema) cannot be executed byOpenRouter, so its intent is translated into OpenRouter's``plugins:[{"id":"web","max_results":N}]`` web-search plugin (N derived- from the tool's max_uses, capped) — without this a Claude call routed+ from the tool's max_uses, capped) for ANY model routed via OpenRouter,+ Claude or not — without this a call routedvia OpenRouter would silently lose web search (the executive_researchcouncil emitted zero findings). The plugin makes the model cite sourceswith inline ``<cite index="...">…</cite>`` markup; the response pathdiff --git a/packages/core/openexecutive/providers/registry.py b/packages/core/openexecutive/providers/registry.pyindex 10020722..4ff69f1e 100644--- a/packages/core/openexecutive/providers/registry.py+++ b/packages/core/openexecutive/providers/registry.py@@ -130,23 +130,40 @@ _CLAUDE_FEATURE_SPEC = FeatureSpec()-# Per-non-Claude model spec. ``supports_tool_use`` is universal across-# the curated set; the other three are off — Anthropic-specific server-# tools and prompt-caching annotations have no OpenAI-format equivalent.+# Per-non-Claude OpenRouter model spec. ``supports_tool_use`` is universal+# across the curated set; cache_control and thinking are off (no+# OpenAI-format equivalent). ``supports_web_search`` is ON: the Anthropic+# web_search tool never reaches the upstream model — the translator drops+# it from ``tools`` and attaches OpenRouter's ``web`` plugin instead, and+# that plugin works for any model OpenRouter serves, not only Claude. What+# the plugin gives differs from Anthropic's tool (one prompt-derived search+# per request, results injected; ``max_uses`` becomes a result count; no+# domain lists; no search count in usage), but a specialist told to emit+# nothing it cannot confirm by search gets a search._DEFAULT_NON_CLAUDE_SPEC = FeatureSpec(supports_cache_control=False,supports_thinking=False,- supports_web_search=False,+ supports_web_search=True,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.+# stays off — that really is Anthropic-only._NON_CLAUDE_REASONING_SPEC = FeatureSpec(supports_cache_control=False,supports_thinking=True,+ supports_web_search=True,+ supports_tool_use=True,+)++# Self-hosted OpenAI-compatible backend: tools only. There is no search+# plugin on that path, so the web_search tool is stripped (it would be+# rejected or silently ignored by the server).+_LOCAL_FEATURE_SPEC = FeatureSpec(+ supports_cache_control=False,+ supports_thinking=False,supports_web_search=False,supports_tool_use=True,)@@ -230,8 +247,10 @@ def _openrouter_model_resolver(model: str) -> tuple[str, FeatureSpec] | None:unchanged, Claude spec — OpenRouter forwards cache_control / thinkingto 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.+ thinking kept (translated to OpenRouter ``reasoning``), web search+ kept (translated to the ``web`` plugin), cache stripped.+ * Anything else → unchanged, the non-Claude default (tools + web+ search; cache and thinking stripped)."""slug = openrouter_slug_for_claude(model)if slug is not None:@@ -243,7 +262,7 @@ def _openrouter_model_resolver(model: str) -> tuple[str, FeatureSpec] | None:# outside the catalog) keeps the conservative thinking-off default.if openrouter_catalog.supports_reasoning(model):return model, _NON_CLAUDE_REASONING_SPEC- return None+ return model, _DEFAULT_NON_CLAUDE_SPEC# Module-level singletons — providers pool their own HTTP connections and@@ -287,11 +306,11 @@ def _local() -> OpenAICompatibleProvider:status_code=400,detail="Local model routing requires LOCAL_BASE_URL",)- # Local models get the non-Claude feature spec: no cache_control,- # thinking, or server-side web_search — those are Anthropic-only and- # would 400 (or be silently ignored) on an OpenAI-compatible server.+ # Local models get the tools-only spec: no cache_control, thinking,+ # or web_search — a self-hosted OpenAI-compatible server has no+ # search plugin and would 400 (or silently ignore) the rest.spec_lookup: dict[str, FeatureSpec] = {- m: _DEFAULT_NON_CLAUDE_SPEC for m in _local_models(settings)+ m: _LOCAL_FEATURE_SPEC for m in _local_models(settings)}_local_provider = OpenAICompatibleProvider(base_url=base_url,diff --git a/packages/core/tests/unit/test_openrouter_catalog.py b/packages/core/tests/unit/test_openrouter_catalog.pyindex 7090fb91..630ca6bf 100644--- a/packages/core/tests/unit/test_openrouter_catalog.py+++ b/packages/core/tests/unit/test_openrouter_catalog.py@@ -442,11 +442,12 @@ def test_openrouter_provider_resolves_specs_by_rule(assert slug == "anthropic/claude-opus-4.8"assert spec.supports_cache_control and spec.supports_thinking- # Anything else: passthrough slug, non-Claude default (Anthropic-only- # fields stripped).+ # Anything else: passthrough slug, non-Claude default (cache and+ # thinking stripped; web search kept, since the translator turns it+ # into OpenRouter's web plugin for any model).slug, spec = provider._resolve("openai/gpt-6")assert slug == "openai/gpt-6"assert not spec.supports_cache_controlassert not spec.supports_thinking- assert not spec.supports_web_search+ assert spec.supports_web_searchassert spec.supports_tool_usediff --git a/packages/core/tests/unit/test_research_controls.py b/packages/core/tests/unit/test_research_controls.pyindex 1caee24a..e9632deb 100644--- a/packages/core/tests/unit/test_research_controls.py+++ b/packages/core/tests/unit/test_research_controls.py@@ -84,3 +84,44 @@ def test_env_example_documents_the_controls() -> None:text = fh.read()for key in ("RESEARCH_WEB_SEARCH_MAX_USES", "RESEARCH_SPECIALISTS", "WATCHLIST_RESEARCH_INTERVAL_MINUTES"):assert key in text+++def test_non_claude_openrouter_models_keep_web_search_but_local_models_do_not(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """The feature gate used to strip the web_search tool for every+ non-Claude model, so a research specialist pinned to e.g. Gemini ran+ without search. OpenRouter's web plugin works for any model it serves,+ so the gate now keeps the tool there; a self-hosted backend has no+ plugin, so it is still stripped."""+ from openexecutive.providers import registry+ from openexecutive.providers.feature_gate import apply_feature_gates+ from openexecutive.providers.translator import to_openai_request++ monkeypatch.setattr(registry.openrouter_catalog, "supports_reasoning", lambda _m: False)+ resolved = registry._openrouter_model_resolver("google/gemini-2.5-flash")+ assert resolved is not None+ slug, spec = resolved+ assert slug == "google/gemini-2.5-flash" and spec.supports_web_search++ monkeypatch.setattr(registry.openrouter_catalog, "supports_reasoning", lambda _m: True)+ _slug, reasoning_spec = registry._openrouter_model_resolver("deepseek/deepseek-v4-pro")+ assert reasoning_spec.supports_web_search and reasoning_spec.supports_thinking++ assert not registry._LOCAL_FEATURE_SPEC.supports_web_search++ # End to end through the gate + translator: the plugin is attached.+ kwargs = {+ "model": "google/gemini-2.5-flash", "max_tokens": 10, "messages": [],+ "tools": [+ {"name": "emit", "input_schema": {"type": "object"}},+ {"type": "web_search_20250305", "name": "web_search", "max_uses": 3},+ ],+ }+ gated = apply_feature_gates(spec, dict(kwargs))+ body = to_openai_request("google/gemini-2.5-flash", gated)+ assert body.get("plugins") == [{"id": "web", "max_results": 3}]+ assert [t["function"]["name"] for t in body["tools"]] == ["emit"]++ stripped = apply_feature_gates(registry._LOCAL_FEATURE_SPEC, dict(kwargs))+ assert "plugins" not in to_openai_request("local-model", stripped)