AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).
feat(providers): use OpenRouter's web-search server tool instead of the plugin
Rufusfa726001fbcf
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 662ff9b5..56a1832a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -122,12 +122,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0stripped the web-search tool for non-Claude models, so a researchspecialist or the Executive pinned to Gemini, GPT, Llama, DeepSeek orGrok 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;- a configured domain allow/block list cannot be applied to it, so on that- path such a setting disables search rather than widening it.+ nothing). The tool is now kept for any OpenRouter model and replaced by+ OpenRouter's own `openrouter:web_search` server tool (the deprecated web+ plugin is no longer used); only a self-hosted OpenAI-compatible backend+ still strips it. The server tool carries the same contract as+ Anthropic's: the model decides when to search, `max_uses` caps searches+ server-side, the domain allow/block lists apply, and the search count is+ reported, so `RESEARCH_WEB_SEARCH_MAX_USES` and `WEB_SEARCH_MAX_USES`+ mean the same thing on both deployment types.- **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 bd937589..bf42a067 100644--- a/packages/core/openexecutive/architecture/architecture-facts.yaml+++ b/packages/core/openexecutive/architecture/architecture-facts.yaml@@ -129,21 +129,24 @@ caching:those backends have no equivalent feature and would reject thefield. The two-block layout above is unchanged either way.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 with the plugin's own default (5) as the floor, and OpenRouter- reports no search count, so `web_search_requests` on those usage rows- reads 0 even though search ran. The plugin has no domain filter, so- when WEB_SEARCH_ALLOWED_DOMAINS / BLOCKED_DOMAINS is set the translator- attaches NO plugin (fail closed, with a warning) rather than an- unrestricted search. The plugin's ``<cite>`` markup is stripped from- tool-call arguments before they are parsed, so a citation inside an+ is preserved by replacing the Anthropic web_search server tool with+ OpenRouter's own ``openrouter:web_search`` server tool (see+ providers.translator_shapes), so a research specialist or the+ Executive pinned to e.g. Gemini still searches, and with the SAME+ contract as Anthropic-direct: the model decides when to search,+ ``max_uses`` caps searches server-side (so RESEARCH_WEB_SEARCH_MAX_USES+ and WEB_SEARCH_MAX_USES mean the same thing on both deployment types),+ WEB_SEARCH_ALLOWED_DOMAINS / BLOCKED_DOMAINS map to allowed_domains /+ excluded_domains, and the response's ``usage.web_search_requests`` is+ surfaced as ``server_tool_use`` so the usage rows record searches on+ this path too. The engine is left on OpenRouter's ``auto`` (native+ provider search for Claude / GPT / Gemini / Grok, Exa otherwise).+ OpenRouter search's ``<cite>`` markup is stripped from tool-call+ arguments before they are parsed, so a citation inside an`emit_research_findings` string cannot empty the payload. Only the- self-hosted OpenAI-compatible backend strips the tool (no plugin there).+ self-hosted OpenAI-compatible backend strips the tool (no server tool+ there). The older ``plugins:[{"id":"web"}]`` plugin is deprecated by+ OpenRouter and no longer used.providers:module: openexecutive.providers@@ -165,8 +168,8 @@ providers:thinking + output_config, and — for the local backend only — theAnthropic server-side web_search tool; every OpenRouter model keepsweb_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.+ translator can turn it into OpenRouter's ``openrouter:web_search``+ server tool. 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@@ -216,12 +219,14 @@ providers:already wired should deep reasoning ever be added to them).The Anthropicserver-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- from the tool's max_uses, capped) for ANY model routed via OpenRouter,- Claude or not — without this a call routed+ OpenRouter, so it is replaced in ``tools[]`` by OpenRouter's+ ``{"type": "openrouter:web_search", "parameters": {max_uses,+ allowed_domains, excluded_domains}}`` server tool for ANY model routed+ via OpenRouter, Claude or not — without this a call routedvia OpenRouter would silently lose web search (the executive_research- council emitted zero findings). The plugin makes the model cite sources+ council emitted zero findings). Server-side tool calls in the response+ (``tool_calls[].type != "function"``) are skipped, never surfaced as+ tool_use blocks for the caller to run. OpenRouter search makes the model cite sourceswith inline ``<cite index="...">…</cite>`` markup; the response pathstrips those wrapper tags from both text and tool-call arguments so theydon't leak into findings / chat replies. Streaming SSE chunksdiff --git a/packages/core/openexecutive/architecture/prebuilt/external_monitoring.json b/packages/core/openexecutive/architecture/prebuilt/external_monitoring.jsonindex edfb1d0b..332d5292 100644--- a/packages/core/openexecutive/architecture/prebuilt/external_monitoring.json+++ b/packages/core/openexecutive/architecture/prebuilt/external_monitoring.json@@ -1,7 +1,7 @@{"section_id": "external_monitoring","title": "External Monitoring",- "markdown": "`openexecutive.monitoring` watches the outside world on a heartbeat and turns detected changes into briefing proposals via the same alert pipeline that handles inbound email and Slack.\n\nThe `external_monitor_scan` heartbeat (`__internal__` channel, default every 5 min) walks `list_watchlist(enabled_only=True)`, skipping rows fresher than their per-source cadence floor. For each due row it fires a read-only source adapter resolved from `_REGISTRY` by `signal_type`:\n\n- `vendor_status` — Statuspage Atom/RSS incident feeds (AWS, Stripe, GitHub, …). Reads each incident's current status out of the entry body, parses `<updated>` into `published_at`, and keys its dedup on `(entry id, <updated>)`; a **seeding** source (see below).\n- `rss` — generic Atom/RSS via feedparser (changelogs, layoffs.fyi, filings). Parses each entry's `<pubDate>`/`<updated>` into `published_at`; a **seeding** source (see below).\n- `stock` — Yahoo Finance chart endpoint; fires on `abs_change_pct_gte` moves.\n- `page_watch` — change-detection on a feed-less page, fetched with the keyless httpx fetcher. A row written before the external scrape path was removed still carries `config.fetch = \"xcrawl\"`; the adapter treats that as a stale baseline, re-captures it from the plain fetch without emitting a signal, and clears the marker.\n- `edgar` and the BILLED `query` web-search adapter.\n\nEach `Signal` is trigger-filtered, severity-clamped to the row's `[floor, ceiling]`, and INSERTed into `external_signals` where `UNIQUE(dedup_key)` drops replays. Survivors pass a suppression cascade (`baseline` → `stale` → `dry_run` → `below_floor` → capture-time relevance enrichment → promote), then `promote_signal_to_alert` builds an `AlertEvent` handed to `alerts.pipeline.schedule_evaluation` and surfaced as a `/today` proposal.\n\nEvery signal carries two timestamps that are never conflated: `captured_at` (when the monitor first saw it) and `published_at` (when the upstream says it happened — RSS `<pubDate>`, EDGAR filing date; null for `stock`, `page_watch`, `query`). Two freshness gates run first in the cascade, before anything that costs an LLM call. **Baseline:** the first poll that returns entries for a row whose adapter declares `seed_on_first_poll` (`rss`, `edgar`) records every entry already in the feed — trigger misses included, so the first entry that ever matches a keyword is news and a later, wider trigger can't resurface old ones — as `suppressed_baseline`, promotes nothing, and stamps `watchlist.baselined_at`, so a new watch reports what changes from now on instead of replaying the feed's back-catalogue (the same idea as `page_watch`'s first-observation baseline). It is keyed on `baselined_at` rather than `last_polled_at`, so a failed first fetch can't forfeit it; the claim and the recording are one transaction (a compare-and-swap on the stamp plus the rows, all-or-nothing), so of two overlapping scans exactly one records the back-catalogue and a failure part-way leaves nothing behind to replay; the other scan promotes only entries dated after that stamp (undated entries count as baseline, since the feed controls the date; entries dated more than a few minutes past its own clock are deferred rather than recorded); and baseline rows don't count against `max_signals_per_scan`, so a large feed can't be half-baselined. `vendor_status` used to sit outside both gates for a structural reason: its dedup key was `sha256(slug, entry id)`, and an incident's id never changes across its updates, so any suppressed insert muted that incident for good. Keying on `(entry id, <updated>)` instead (issue #90) makes a suppression cost one *state* of an incident rather than the incident, so both gates now apply to vendor feeds too — and an incident moving Investigating → Resolved mints a new key and surfaces, while re-polling an unchanged feed still dedups. Because a history feed's archive is mostly incidents resolved months ago, the adapter also carves live news out of its own baseline: it reads each incident's current status from the entry body (Statuspage renders the newest update first as `<strong>Resolved</strong>` / `Investigating` / `Monitoring` / … — the body is parsed by a real HTML parser, off the event loop, and the reading is deliberately asymmetric: any sign that the incident is over closes it, wherever it appears, while only a marked-up label can say it is still open. Working out which update is newest turned out to be something tag soup cannot be trusted to express, and every attempt reported a long-resolved incident as live) and exempts the ones still OPEN via the optional `promote_on_baseline` hook, so a watch added during an outage reports that outage on its first poll while the resolved archive is recorded as `suppressed_baseline`. An unrecognised status counts as closed — a vendor changing feed format must not be able to promote its whole archive at HIGH, and nothing is lost, since the next `<updated>` bump surfaces normally. An exempt entry must still pass the row's trigger filter (one that misses stays in the baseline, so widening a trigger later cannot resurface it) and is still judged by the stale gate below: the exemption buys an entry past the baseline, never past its own timestamp, because \"this is live\" is a reading of vendor-controlled markup and an entry the feed dates outside the age window is not news whatever that reading says. **Stale:** a signal whose `published_at` is older than `EXTERNAL_MONITOR_MAX_SIGNAL_AGE_DAYS` (default 7; `0` disables) at capture time is recorded as `suppressed_stale` and never promoted — a January article a feed resurfaces in September is not September news. An entry dated more than `EXTERNAL_MONITOR_MAX_FUTURE_SKEW_HOURS` ahead (default 24; `0` disables; `config_json.max_future_skew_hours` overrides it per row for calendar or maintenance feeds that legitimately date entries ahead) is deferred instead: skipped for the tick and not recorded (recording would burn its dedup key and let a feed mute an announcement for good by post-dating it), with one aggregated `external_signal_deferred` audit row per poll — carrying each held-back entry's summary and link, and emitted even if the poll later raises — then judged normally once the date passes. Inside the window, the alert body handed to triage carries `Published:` and `Discovered:` lines so the item is judged on when it happened. Adapters prefer a plausible date key over one more than a day in the future (and keep the future value when every key is implausible, so the pipeline defers it rather than waving an undated entry through), and the alert body collapses whitespace in the summary so no source can forge its own labeled body line.\n\nThe `query` adapter is a special case: it emits every web hit flat-LOW (it can't judge materiality per-hit), so for query signals enrichment runs BEFORE the floor gate and `_grade_query_severity` regrades from the relevance read (≥0.8 HIGH, ≥0.5 MEDIUM, else LOW). Without this, any query watch item with a `severity_floor` above LOW would suppress every hit — which is what left the Monitoring section empty even while standing queries were returning material findings.\n\nWhich lane a proposal lands in is decided by `briefing.ranking.categorize`: an unrouted, low/medium signal from a monitoring source (`stock`, `vendor_status`, `rss`, `query`, `edgar`, `page_watch`, or any `external:*` topic tag) is `monitoring` (the collapsible Monitoring section); a routed or high/urgent one is `action` (the \"Needs you\" queue). The triage prompt's External Signals rule covers all six source kinds so it trusts the source and emits the `external:*` tags that drive this split.\n\nThe watchlist is editable from chat (`add_watchlist_entry`, `tune_watchlist_entry`) and HTTP (`/watchlist`); the `executive_research` workflow proposes what to watch through a deterministic policy (next section). Because that workflow is LLM-driven and historically proposed feed URLs it never verified (most were dead — 404 / 403 / not-actually-a-feed), every `rss` target is validated at insert time (`monitoring.target_validation`): a URL that fetches and parses as a feed is kept; a public page that isn't a feed is converted to a `page_watch` when the body the feed check already fetched reduces to readable text, otherwise rejected (HTTP 422 / tool error); SSRF-blocked or unparseable URLs are rejected outright and never fetched. Non-`rss` types insert unchanged with no network I/O.\n\n### One watch, one card — and dismissals teach the watch\n\n`promote_signal_to_alert` stamps the `AlertEvent` with `dedup_hint=\"watch:<slug>\"`, which `alerts.pipeline` uses as the *alert* dedup key. A repeat from the same watch coalesces into the open card (`occurrence_count`, `last_seen_at`, severity max) rather than minting another, and re-pings only when severity rose into high/urgent — so a ticker that stays over its threshold or an incident that keeps updating no longer produces a new \"Needs you\" item every day. The signal-level `dedup_key` (stock's UTC-date bucket, vendor_status's `<updated>`) is untouched, so every observation still lands in `external_signals`. Dismissing a watch-sourced alert calls `store.record_dismissal(slug)` (`dismiss_count += 1`, `trust_score = max(0.2, trust × 0.8)`); approving calls `record_confirmation` (+0.05). `trust_score` discounts the briefing ranking and is shown to the Executive's alert review as evidence, alongside the newer signals for that watch (a \"Resolved\" incident state, a reversed move) that let it close the card with evidence.\n\n### What the research pass may put on the watchlist\n\nThe run itself: seven specialists (or the subset named by `RESEARCH_SPECIALISTS`) each make one call with the basic `web_search` server tool, capped at `RESEARCH_WEB_SEARCH_MAX_USES` searches (default 3, separate from the chat knob; via OpenRouter, Claude or not, the tool becomes the web plugin's single search with at least five results, and a configured domain list disables search on that path rather than being ignored), and emit at most three findings — the cap sits in the tool schema and is applied again after parsing. Every specialist sees what department heads asked to have watched (a `DEPARTMENT WATCH INTERESTS` block) and the ten most recent decisions, and may ground a finding in either. Findings are deduplicated, low-confidence ones dropped, then the Executive routes the rest; the routing pass cannot start a workflow (`run_workflow` is withheld, `suggest_workflow` is not). There is no external fetch or verify service: every page read is the on-box fetcher. The periodic run is considered every `WATCHLIST_RESEARCH_INTERVAL_MINUTES` (default 360) and skipped when nothing changed. Every model call the run makes is recorded as a `cache_event` audit row tagged with the run id, and the run's result and its `watchlist_research_periodic_ran` row carry a `usage` block (calls, tokens, searches, per source), so what a run did is readable from the audit log.\n\nEvery watchlist row carries an `origin`: `manual` (the principal, via UI/API), `executive` (the chat tool acting on a request), `research` (the research pass added it on its own) or `research_proposed` (a pending suggestion). The `executive_research` workflow's watchlist pass no longer calls `add_watchlist_entry`; its only tool is `propose_watch` (slug, signal_type, target, `grounding_entity`, `rationale`, `certainty`), and `monitoring.research.watch_policy` decides what happens to each proposal from company data, not from the model's confidence in itself:\n\n- **Direct add** — the row lands live, `origin=research`, with quiet defaults the model cannot loosen (daily cadence — hourly for `vendor_status`, weekly for `page_watch`/`query` — `severity_floor=medium`, a keyword trigger of material-event words + the current-year priority terms for `rss` / `query` only — never for `page_watch`, whose summary is just \"page changed\" and would never match, and never the entity's own name, which appears in every feed entry's label and would fire on everything — and `abs_change_pct_gte=5` for stocks). Requires the `grounding_entity` to name an external entity in company data — the company itself, a `competitive_landscape.primary_competitors` entry, one of the profile's `vendors` / `tickers`, or an entity a department lists under its **watched entities** (each list entry is parsed to its name: \"Tesla (TSLA) — Model Y is the benchmark\" grounds as `Tesla` plus the ticker `TSLA`, \"GM / Chevrolet (…)\" as both names, and \"Brex (brex.com)\" pins Brex's own domains so only those sites count as its own source; the description after the dash never becomes a term, short names such as BYD or GM match as whole words, and a ticker grounds only as itself) (an initiative title, a current-year priority, a department's charter-scope phrase or a goal's key result also grounds a proposal, but only ever to a suggestion: they are bags of common words a planted finding can echo) — *and* a score ≥ 4 on a fixed ledger: +2 entity in company data (mandatory), +1 entity already watched under another source, +1 target is the entity's own source (for stock/edgar the grounding entity must be the ticker itself; a URL whose site label — `acme` in `status.acme.com` / `acme.co.uk`, never a subdomain or TLD — is the entity's leading name or all its words run together, never a generic trailing word; or a primary-source host such as sec.gov), +1 finding confidence high, +1 cross-specialist consensus (the finding points count only when the cited finding concerns this source: a URL target must share its site with one of the finding's cited URLs, a ticker must appear in its text — a strong finding cannot be borrowed for an unrelated page), +1 the entity (a company-data term, never a bare watch label) is named in one of the ten most recent episodic decisions from the last 90 days — the whole term, or every distinctive word of it, as whole words — ±1 from the policy's own approval history for that `(signal_type, grounding kind)` once it has ≥5 samples. A direct add is further reserved for the entity's **own** source (its ticker, its site, its status page): a well-corroborated third-party page about a competitor is the principal's call. It also always needs a linked finding that cites the source — company data plus a decision mention can reach the score bar alone, but nothing goes live on hearsay. The model's `certainty` can only downgrade a direct add to a suggestion; a `query` watch is always a suggestion. At most `WATCHLIST_RESEARCH_MAX_DIRECT_ADDS` (2) per run. When one term appears in several sources the strongest kind wins (company > competitor > vendor > ticker > department entity > initiative > priority > department scope > watch label); a term that came from a department carries the department along even when a stronger profile kind wins, so a profile vendor that Finance also lists stays a vendor and still routes to Finance.\n- **Linked finding.** `finding_index` is required on `propose_watch` and the pass is told so; when the model omits it anyway, or cites a finding that does not concern the source, the policy links the finding that best does (a cited URL on the target's site or the ticker named in its text outranks a mere mention of the entity; then the entity's own site, confidence) and says so in the first reason. A proposal that no finding cites is rejected as having no evidence.\n- **Suggestion** — anything that validates, has a linked finding and scores at least 1 but misses the bar is inserted in `dry_run` (polls and records signals, never alerts) with `origin=research_proposed` and the rationale in `notes`, at most `WATCHLIST_RESEARCH_MAX_PROPOSALS` (2) per run. `/watchlist` shows them in a \"Suggested by the Executive\" section with Approve (`POST /watchlist/{slug}/approve` → `active`, `origin=research`) and Decline (`POST /watchlist/{slug}/decline` with a reason: `not_relevant` blacklists the entity, `wrong_source` blacklists only this target, `too_noisy` keeps the source live with `severity_floor=high` — the one way a suggestion goes live without an approve — and counts as a decline for calibration). A suggestion nobody reviews within `WATCHLIST_PROPOSAL_TTL_DAYS` (14) is removed. The morning brief mentions the pending count in one line; a `watchlist_suggestions` alert nudges only once ≥3 suggestions have waited ≥7 days — one card for the whole pile (an open card is refreshed in place; a dismissed one is not re-minted until the next ISO week), so acting on a suggestion never spawns another nudge.\n- **Routed to a department** — a watch grounded in a department's term (or whose entity a recent decision recorded for that department names) is inserted with `route_to_department` and `route_to_person_id` set to the department and its head at insert time. `_signal_to_alert_event` now maps both onto the `AlertEvent` for every watch (`routed_to_person_id`, `department=<slug>` — a tag hint, deliberately not the `channel` field triage reads as a team room), so the alerts it raises queue on the head's `/today` (as action items, since routed alerts are never hidden in Monitoring) and carry the `department:<slug>` tag instead of landing in the principal's unrouted queue. Suggestions in a department's area are put in front of its head, not the principal: after each run, one \"Watch suggestions for <Department>\" card per department is filed through `propose_via_alert` (routed to the head, or the principal when there is no head; an open card is refreshed in place and an acknowledged one is not re-minted until the next ISO week), and the principal's pile-up nudge counts only suggestions that reached no head — the principal's own and those of a department without a head — so none can become invisible. `/watchlist` labels routed rows \"for: <department>\".\n- **Reject** — an invalid target, a second watch on the same site + signal type (disabled rows included), a declined target or entity, nothing vouching for it (no linked finding, score 0), the enabled-watch ceiling `WATCHLIST_MAX_ENABLED` (40; suggestions poll too, so the ceiling stops them as well), or a spent budget. Every decision is audited (`watchlist_research_added` / `_suggested` / `_rejected`) with the score and reasons; the stamp also lives in the row's `config_json._policy` so approve/decline/auto-disable can attribute the outcome.\n\n**Declines are remembered and enforced.** `watchlist_declines` is keyed by the normalized target (upper-cased ticker; URL with `https` forced, `www.` dropped, host and path lower-cased, query, fragment and trailing slash removed; free-text queries case- and whitespace-folded). A `not_relevant` decline also blacklists the *entity*: any later proposal whose `grounding_entity` names it is refused whatever the target. An explicit decline — the Decline button, \"Stop watching…\" on a research-added card, `remove_watchlist_entry` or `DELETE /watchlist/{slug}` on a research-origin row — is permanent; an unreviewed expiry may be re-proposed once after 90 days. The `propose_watch` handler refuses a declined target or entity before anything is fetched, so a new slug cannot route around a decline (URL keys also fold percent-encoding, dot segments and a trailing host dot); the list is also rendered to the model as DECLINED. The routing pass that runs before the watchlist pass has no watchlist write tools at all (`add_watchlist_entry`, `tune_watchlist_entry`, `remove_watchlist_entry` are withheld from synthesis), and `tune_watchlist_entry` accepts only `notes` on a pending suggestion — never `mode` / `enabled` (only the principal's approve or decline moves one out of review) nor cadence / floor / trigger (it goes live with the quiet defaults policy gave it). Every URL-typed target (`rss`, `vendor_status`, `page_watch`) is checked against the SSRF guard at insert time, and a suggestion's `source_url` link is kept only when it is a public http(s) URL.\n\n**The policy learns from outcomes.** Approve, decline, expiry and auto-disable write `watchlist_policy_outcomes` rows keyed by `(signal_type, grounding kind, specialist)`; the pass renders the tallies (\"stock watches grounded in a competitor: 4 approved / 1 declined\"; \"proposals from cso: …\") and the score ledger reads them. The research turn also shows each existing watch's `origin`, `fired_count`, `dismiss_count` and `trust_score`.\n\n**Research watches retire themselves.** The scheduler's 15-minute sweep (`watch_policy.sweep`, alongside the alert expiry sweep) disables a `research`-origin watch — audited as `watchlist_auto_disabled`, re-enable from `/watchlist` — when it fired ≥5 alerts of which ≥2 were dismissed and trust ≤ 0.5, or after 3 consecutive poll failures (silence is deliberately not a rule: an unchanged page or a healthy vendor is a working watch); the retired target is also recorded as a 90-day decline so the next run cannot re-add it under a new slug with fresh counters (a disabled row already counts as \"same source watched\"). Approve, decline and expiry are compare-and-act on \"still pending\", so a concurrent approve always wins over a decline or the sweep. Direct adds and auto-disables appear in the brief's \"handled overnight\" block as `watching` / `stopped_watching`. The research skip-if-unchanged fingerprint hashes only enabled, `active` rows, so approving or declining a suggestion never triggers a fresh 7-specialist run.\n\n### Invariants\n\n- Adapters are read-only — they never write upstream and never auto-execute.\n- Every `Signal` carries a deterministic `dedup_key` and a mandatory `provenance_url`.\n- Every fetch is the on-box httpx fetcher: SSRF-guarded and bounded by `external_monitor_max_fetch_bytes`. No path delegates a fetch to an external service.\n- Suppressed signals are still persisted so audits show the full picture.\n- A repeat from the same watch never becomes a second open card: the alert-level `watch:<slug>` key coalesces it, and only a severity escalation re-dispatches.\n- The research model never writes the watchlist: it proposes, deterministic policy adds (only when grounded in company data) or suggests, and a target the principal declined is refused at the handler.",+ "markdown": "`openexecutive.monitoring` watches the outside world on a heartbeat and turns detected changes into briefing proposals via the same alert pipeline that handles inbound email and Slack.\n\nThe `external_monitor_scan` heartbeat (`__internal__` channel, default every 5 min) walks `list_watchlist(enabled_only=True)`, skipping rows fresher than their per-source cadence floor. For each due row it fires a read-only source adapter resolved from `_REGISTRY` by `signal_type`:\n\n- `vendor_status` — Statuspage Atom/RSS incident feeds (AWS, Stripe, GitHub, …). Reads each incident's current status out of the entry body, parses `<updated>` into `published_at`, and keys its dedup on `(entry id, <updated>)`; a **seeding** source (see below).\n- `rss` — generic Atom/RSS via feedparser (changelogs, layoffs.fyi, filings). Parses each entry's `<pubDate>`/`<updated>` into `published_at`; a **seeding** source (see below).\n- `stock` — Yahoo Finance chart endpoint; fires on `abs_change_pct_gte` moves.\n- `page_watch` — change-detection on a feed-less page, fetched with the keyless httpx fetcher. A row written before the external scrape path was removed still carries `config.fetch = \"xcrawl\"`; the adapter treats that as a stale baseline, re-captures it from the plain fetch without emitting a signal, and clears the marker.\n- `edgar` and the BILLED `query` web-search adapter.\n\nEach `Signal` is trigger-filtered, severity-clamped to the row's `[floor, ceiling]`, and INSERTed into `external_signals` where `UNIQUE(dedup_key)` drops replays. Survivors pass a suppression cascade (`baseline` → `stale` → `dry_run` → `below_floor` → capture-time relevance enrichment → promote), then `promote_signal_to_alert` builds an `AlertEvent` handed to `alerts.pipeline.schedule_evaluation` and surfaced as a `/today` proposal.\n\nEvery signal carries two timestamps that are never conflated: `captured_at` (when the monitor first saw it) and `published_at` (when the upstream says it happened — RSS `<pubDate>`, EDGAR filing date; null for `stock`, `page_watch`, `query`). Two freshness gates run first in the cascade, before anything that costs an LLM call. **Baseline:** the first poll that returns entries for a row whose adapter declares `seed_on_first_poll` (`rss`, `edgar`) records every entry already in the feed — trigger misses included, so the first entry that ever matches a keyword is news and a later, wider trigger can't resurface old ones — as `suppressed_baseline`, promotes nothing, and stamps `watchlist.baselined_at`, so a new watch reports what changes from now on instead of replaying the feed's back-catalogue (the same idea as `page_watch`'s first-observation baseline). It is keyed on `baselined_at` rather than `last_polled_at`, so a failed first fetch can't forfeit it; the claim and the recording are one transaction (a compare-and-swap on the stamp plus the rows, all-or-nothing), so of two overlapping scans exactly one records the back-catalogue and a failure part-way leaves nothing behind to replay; the other scan promotes only entries dated after that stamp (undated entries count as baseline, since the feed controls the date; entries dated more than a few minutes past its own clock are deferred rather than recorded); and baseline rows don't count against `max_signals_per_scan`, so a large feed can't be half-baselined. `vendor_status` used to sit outside both gates for a structural reason: its dedup key was `sha256(slug, entry id)`, and an incident's id never changes across its updates, so any suppressed insert muted that incident for good. Keying on `(entry id, <updated>)` instead (issue #90) makes a suppression cost one *state* of an incident rather than the incident, so both gates now apply to vendor feeds too — and an incident moving Investigating → Resolved mints a new key and surfaces, while re-polling an unchanged feed still dedups. Because a history feed's archive is mostly incidents resolved months ago, the adapter also carves live news out of its own baseline: it reads each incident's current status from the entry body (Statuspage renders the newest update first as `<strong>Resolved</strong>` / `Investigating` / `Monitoring` / … — the body is parsed by a real HTML parser, off the event loop, and the reading is deliberately asymmetric: any sign that the incident is over closes it, wherever it appears, while only a marked-up label can say it is still open. Working out which update is newest turned out to be something tag soup cannot be trusted to express, and every attempt reported a long-resolved incident as live) and exempts the ones still OPEN via the optional `promote_on_baseline` hook, so a watch added during an outage reports that outage on its first poll while the resolved archive is recorded as `suppressed_baseline`. An unrecognised status counts as closed — a vendor changing feed format must not be able to promote its whole archive at HIGH, and nothing is lost, since the next `<updated>` bump surfaces normally. An exempt entry must still pass the row's trigger filter (one that misses stays in the baseline, so widening a trigger later cannot resurface it) and is still judged by the stale gate below: the exemption buys an entry past the baseline, never past its own timestamp, because \"this is live\" is a reading of vendor-controlled markup and an entry the feed dates outside the age window is not news whatever that reading says. **Stale:** a signal whose `published_at` is older than `EXTERNAL_MONITOR_MAX_SIGNAL_AGE_DAYS` (default 7; `0` disables) at capture time is recorded as `suppressed_stale` and never promoted — a January article a feed resurfaces in September is not September news. An entry dated more than `EXTERNAL_MONITOR_MAX_FUTURE_SKEW_HOURS` ahead (default 24; `0` disables; `config_json.max_future_skew_hours` overrides it per row for calendar or maintenance feeds that legitimately date entries ahead) is deferred instead: skipped for the tick and not recorded (recording would burn its dedup key and let a feed mute an announcement for good by post-dating it), with one aggregated `external_signal_deferred` audit row per poll — carrying each held-back entry's summary and link, and emitted even if the poll later raises — then judged normally once the date passes. Inside the window, the alert body handed to triage carries `Published:` and `Discovered:` lines so the item is judged on when it happened. Adapters prefer a plausible date key over one more than a day in the future (and keep the future value when every key is implausible, so the pipeline defers it rather than waving an undated entry through), and the alert body collapses whitespace in the summary so no source can forge its own labeled body line.\n\nThe `query` adapter is a special case: it emits every web hit flat-LOW (it can't judge materiality per-hit), so for query signals enrichment runs BEFORE the floor gate and `_grade_query_severity` regrades from the relevance read (≥0.8 HIGH, ≥0.5 MEDIUM, else LOW). Without this, any query watch item with a `severity_floor` above LOW would suppress every hit — which is what left the Monitoring section empty even while standing queries were returning material findings.\n\nWhich lane a proposal lands in is decided by `briefing.ranking.categorize`: an unrouted, low/medium signal from a monitoring source (`stock`, `vendor_status`, `rss`, `query`, `edgar`, `page_watch`, or any `external:*` topic tag) is `monitoring` (the collapsible Monitoring section); a routed or high/urgent one is `action` (the \"Needs you\" queue). The triage prompt's External Signals rule covers all six source kinds so it trusts the source and emits the `external:*` tags that drive this split.\n\nThe watchlist is editable from chat (`add_watchlist_entry`, `tune_watchlist_entry`) and HTTP (`/watchlist`); the `executive_research` workflow proposes what to watch through a deterministic policy (next section). Because that workflow is LLM-driven and historically proposed feed URLs it never verified (most were dead — 404 / 403 / not-actually-a-feed), every `rss` target is validated at insert time (`monitoring.target_validation`): a URL that fetches and parses as a feed is kept; a public page that isn't a feed is converted to a `page_watch` when the body the feed check already fetched reduces to readable text, otherwise rejected (HTTP 422 / tool error); SSRF-blocked or unparseable URLs are rejected outright and never fetched. Non-`rss` types insert unchanged with no network I/O.\n\n### One watch, one card — and dismissals teach the watch\n\n`promote_signal_to_alert` stamps the `AlertEvent` with `dedup_hint=\"watch:<slug>\"`, which `alerts.pipeline` uses as the *alert* dedup key. A repeat from the same watch coalesces into the open card (`occurrence_count`, `last_seen_at`, severity max) rather than minting another, and re-pings only when severity rose into high/urgent — so a ticker that stays over its threshold or an incident that keeps updating no longer produces a new \"Needs you\" item every day. The signal-level `dedup_key` (stock's UTC-date bucket, vendor_status's `<updated>`) is untouched, so every observation still lands in `external_signals`. Dismissing a watch-sourced alert calls `store.record_dismissal(slug)` (`dismiss_count += 1`, `trust_score = max(0.2, trust × 0.8)`); approving calls `record_confirmation` (+0.05). `trust_score` discounts the briefing ranking and is shown to the Executive's alert review as evidence, alongside the newer signals for that watch (a \"Resolved\" incident state, a reversed move) that let it close the card with evidence.\n\n### What the research pass may put on the watchlist\n\nThe run itself: seven specialists (or the subset named by `RESEARCH_SPECIALISTS`) each make one call with the basic `web_search` server tool, capped at `RESEARCH_WEB_SEARCH_MAX_USES` searches (default 3, separate from the chat knob; via OpenRouter, Claude or not, the tool becomes OpenRouter's `openrouter:web_search` server tool with the same cap and domain lists, and the search count is recorded there too), and emit at most three findings — the cap sits in the tool schema and is applied again after parsing. Every specialist sees what department heads asked to have watched (a `DEPARTMENT WATCH INTERESTS` block) and the ten most recent decisions, and may ground a finding in either. Findings are deduplicated, low-confidence ones dropped, then the Executive routes the rest; the routing pass cannot start a workflow (`run_workflow` is withheld, `suggest_workflow` is not). There is no external fetch or verify service: every page read is the on-box fetcher. The periodic run is considered every `WATCHLIST_RESEARCH_INTERVAL_MINUTES` (default 360) and skipped when nothing changed. Every model call the run makes is recorded as a `cache_event` audit row tagged with the run id, and the run's result and its `watchlist_research_periodic_ran` row carry a `usage` block (calls, tokens, searches, per source), so what a run did is readable from the audit log.\n\nEvery watchlist row carries an `origin`: `manual` (the principal, via UI/API), `executive` (the chat tool acting on a request), `research` (the research pass added it on its own) or `research_proposed` (a pending suggestion). The `executive_research` workflow's watchlist pass no longer calls `add_watchlist_entry`; its only tool is `propose_watch` (slug, signal_type, target, `grounding_entity`, `rationale`, `certainty`), and `monitoring.research.watch_policy` decides what happens to each proposal from company data, not from the model's confidence in itself:\n\n- **Direct add** — the row lands live, `origin=research`, with quiet defaults the model cannot loosen (daily cadence — hourly for `vendor_status`, weekly for `page_watch`/`query` — `severity_floor=medium`, a keyword trigger of material-event words + the current-year priority terms for `rss` / `query` only — never for `page_watch`, whose summary is just \"page changed\" and would never match, and never the entity's own name, which appears in every feed entry's label and would fire on everything — and `abs_change_pct_gte=5` for stocks). Requires the `grounding_entity` to name an external entity in company data — the company itself, a `competitive_landscape.primary_competitors` entry, one of the profile's `vendors` / `tickers`, or an entity a department lists under its **watched entities** (each list entry is parsed to its name: \"Tesla (TSLA) — Model Y is the benchmark\" grounds as `Tesla` plus the ticker `TSLA`, \"GM / Chevrolet (…)\" as both names, and \"Brex (brex.com)\" pins Brex's own domains so only those sites count as its own source; the description after the dash never becomes a term, short names such as BYD or GM match as whole words, and a ticker grounds only as itself) (an initiative title, a current-year priority, a department's charter-scope phrase or a goal's key result also grounds a proposal, but only ever to a suggestion: they are bags of common words a planted finding can echo) — *and* a score ≥ 4 on a fixed ledger: +2 entity in company data (mandatory), +1 entity already watched under another source, +1 target is the entity's own source (for stock/edgar the grounding entity must be the ticker itself; a URL whose site label — `acme` in `status.acme.com` / `acme.co.uk`, never a subdomain or TLD — is the entity's leading name or all its words run together, never a generic trailing word; or a primary-source host such as sec.gov), +1 finding confidence high, +1 cross-specialist consensus (the finding points count only when the cited finding concerns this source: a URL target must share its site with one of the finding's cited URLs, a ticker must appear in its text — a strong finding cannot be borrowed for an unrelated page), +1 the entity (a company-data term, never a bare watch label) is named in one of the ten most recent episodic decisions from the last 90 days — the whole term, or every distinctive word of it, as whole words — ±1 from the policy's own approval history for that `(signal_type, grounding kind)` once it has ≥5 samples. A direct add is further reserved for the entity's **own** source (its ticker, its site, its status page): a well-corroborated third-party page about a competitor is the principal's call. It also always needs a linked finding that cites the source — company data plus a decision mention can reach the score bar alone, but nothing goes live on hearsay. The model's `certainty` can only downgrade a direct add to a suggestion; a `query` watch is always a suggestion. At most `WATCHLIST_RESEARCH_MAX_DIRECT_ADDS` (2) per run. When one term appears in several sources the strongest kind wins (company > competitor > vendor > ticker > department entity > initiative > priority > department scope > watch label); a term that came from a department carries the department along even when a stronger profile kind wins, so a profile vendor that Finance also lists stays a vendor and still routes to Finance.\n- **Linked finding.** `finding_index` is required on `propose_watch` and the pass is told so; when the model omits it anyway, or cites a finding that does not concern the source, the policy links the finding that best does (a cited URL on the target's site or the ticker named in its text outranks a mere mention of the entity; then the entity's own site, confidence) and says so in the first reason. A proposal that no finding cites is rejected as having no evidence.\n- **Suggestion** — anything that validates, has a linked finding and scores at least 1 but misses the bar is inserted in `dry_run` (polls and records signals, never alerts) with `origin=research_proposed` and the rationale in `notes`, at most `WATCHLIST_RESEARCH_MAX_PROPOSALS` (2) per run. `/watchlist` shows them in a \"Suggested by the Executive\" section with Approve (`POST /watchlist/{slug}/approve` → `active`, `origin=research`) and Decline (`POST /watchlist/{slug}/decline` with a reason: `not_relevant` blacklists the entity, `wrong_source` blacklists only this target, `too_noisy` keeps the source live with `severity_floor=high` — the one way a suggestion goes live without an approve — and counts as a decline for calibration). A suggestion nobody reviews within `WATCHLIST_PROPOSAL_TTL_DAYS` (14) is removed. The morning brief mentions the pending count in one line; a `watchlist_suggestions` alert nudges only once ≥3 suggestions have waited ≥7 days — one card for the whole pile (an open card is refreshed in place; a dismissed one is not re-minted until the next ISO week), so acting on a suggestion never spawns another nudge.\n- **Routed to a department** — a watch grounded in a department's term (or whose entity a recent decision recorded for that department names) is inserted with `route_to_department` and `route_to_person_id` set to the department and its head at insert time. `_signal_to_alert_event` now maps both onto the `AlertEvent` for every watch (`routed_to_person_id`, `department=<slug>` — a tag hint, deliberately not the `channel` field triage reads as a team room), so the alerts it raises queue on the head's `/today` (as action items, since routed alerts are never hidden in Monitoring) and carry the `department:<slug>` tag instead of landing in the principal's unrouted queue. Suggestions in a department's area are put in front of its head, not the principal: after each run, one \"Watch suggestions for <Department>\" card per department is filed through `propose_via_alert` (routed to the head, or the principal when there is no head; an open card is refreshed in place and an acknowledged one is not re-minted until the next ISO week), and the principal's pile-up nudge counts only suggestions that reached no head — the principal's own and those of a department without a head — so none can become invisible. `/watchlist` labels routed rows \"for: <department>\".\n- **Reject** — an invalid target, a second watch on the same site + signal type (disabled rows included), a declined target or entity, nothing vouching for it (no linked finding, score 0), the enabled-watch ceiling `WATCHLIST_MAX_ENABLED` (40; suggestions poll too, so the ceiling stops them as well), or a spent budget. Every decision is audited (`watchlist_research_added` / `_suggested` / `_rejected`) with the score and reasons; the stamp also lives in the row's `config_json._policy` so approve/decline/auto-disable can attribute the outcome.\n\n**Declines are remembered and enforced.** `watchlist_declines` is keyed by the normalized target (upper-cased ticker; URL with `https` forced, `www.` dropped, host and path lower-cased, query, fragment and trailing slash removed; free-text queries case- and whitespace-folded). A `not_relevant` decline also blacklists the *entity*: any later proposal whose `grounding_entity` names it is refused whatever the target. An explicit decline — the Decline button, \"Stop watching…\" on a research-added card, `remove_watchlist_entry` or `DELETE /watchlist/{slug}` on a research-origin row — is permanent; an unreviewed expiry may be re-proposed once after 90 days. The `propose_watch` handler refuses a declined target or entity before anything is fetched, so a new slug cannot route around a decline (URL keys also fold percent-encoding, dot segments and a trailing host dot); the list is also rendered to the model as DECLINED. The routing pass that runs before the watchlist pass has no watchlist write tools at all (`add_watchlist_entry`, `tune_watchlist_entry`, `remove_watchlist_entry` are withheld from synthesis), and `tune_watchlist_entry` accepts only `notes` on a pending suggestion — never `mode` / `enabled` (only the principal's approve or decline moves one out of review) nor cadence / floor / trigger (it goes live with the quiet defaults policy gave it). Every URL-typed target (`rss`, `vendor_status`, `page_watch`) is checked against the SSRF guard at insert time, and a suggestion's `source_url` link is kept only when it is a public http(s) URL.\n\n**The policy learns from outcomes.** Approve, decline, expiry and auto-disable write `watchlist_policy_outcomes` rows keyed by `(signal_type, grounding kind, specialist)`; the pass renders the tallies (\"stock watches grounded in a competitor: 4 approved / 1 declined\"; \"proposals from cso: …\") and the score ledger reads them. The research turn also shows each existing watch's `origin`, `fired_count`, `dismiss_count` and `trust_score`.\n\n**Research watches retire themselves.** The scheduler's 15-minute sweep (`watch_policy.sweep`, alongside the alert expiry sweep) disables a `research`-origin watch — audited as `watchlist_auto_disabled`, re-enable from `/watchlist` — when it fired ≥5 alerts of which ≥2 were dismissed and trust ≤ 0.5, or after 3 consecutive poll failures (silence is deliberately not a rule: an unchanged page or a healthy vendor is a working watch); the retired target is also recorded as a 90-day decline so the next run cannot re-add it under a new slug with fresh counters (a disabled row already counts as \"same source watched\"). Approve, decline and expiry are compare-and-act on \"still pending\", so a concurrent approve always wins over a decline or the sweep. Direct adds and auto-disables appear in the brief's \"handled overnight\" block as `watching` / `stopped_watching`. The research skip-if-unchanged fingerprint hashes only enabled, `active` rows, so approving or declining a suggestion never triggers a fresh 7-specialist run.\n\n### Invariants\n\n- Adapters are read-only — they never write upstream and never auto-execute.\n- Every `Signal` carries a deterministic `dedup_key` and a mandatory `provenance_url`.\n- Every fetch is the on-box httpx fetcher: SSRF-guarded and bounded by `external_monitor_max_fetch_bytes`. No path delegates a fetch to an external service.\n- Suppressed signals are still persisted so audits show the full picture.\n- A repeat from the same watch never becomes a second open card: the alert-level `watch:<slug>` key coalesces it, and only a severity escalation re-dispatches.\n- The research model never writes the watchlist: it proposes, deterministic policy adds (only when grounded in company data) or suggests, and a target the principal declined is refused at the handler.","mermaid": "flowchart TD\n ADD[\"add (chat tool / POST /watchlist / research)\"]\n VAL[\"target_validation: rss feed? → keep / readable page → page_watch / reject\"]\n WL[(\"watchlist\")]\n HB[\"external_monitor_scan heartbeat (~5 min)\"]\n AD[\"read-only adapters: vendor_status / rss / stock / query / edgar / page_watch (httpx)\"]\n SIG[(\"external_signals UNIQUE(dedup_key)\")]\n ENRICH[\"capture-time enrichment<br/>(relevance score + why_it_matters)\"]\n PROMO[\"promote_signal_to_alert\"]\n PIPE[\"alert pipeline (triage)\"]\n TODAY[\"/today proposals\"]\n ADD --> VAL\n VAL -->|\"insert valid rows\"| WL\n HB -->|\"walk enabled rows\"| WL\n WL -->|\"poll due rows\"| AD\n AD -->|\"emit Signal\"| SIG\n SIG -->|\"baseline / stale / dry_run / floor gates\"| ENRICH\n ENRICH -->|\"≥ relevance floor\"| PROMO\n PROMO --> PIPE\n PIPE --> TODAY\n class HB hot\n class WL storage\n class VAL compute\n class AD external\n class SIG storage\n class ENRICH compute\n class PROMO compute\n class PIPE compute\n class TODAY entry\n class ADD compute","generated_at": "2026-09-12T17:10:00+00:00"}diff --git a/packages/core/openexecutive/architecture/prebuilt/lifecycle.json b/packages/core/openexecutive/architecture/prebuilt/lifecycle.jsonindex edee0e67..e0e8ce5b 100644--- a/packages/core/openexecutive/architecture/prebuilt/lifecycle.json+++ b/packages/core/openexecutive/architecture/prebuilt/lifecycle.json@@ -1,7 +1,7 @@{"section_id": "lifecycle","title": "Request Lifecycle",- "markdown": "A single chat message makes a full round-trip through the API, the orchestrator's tool-use loop, a parallel specialist fan-out, and synthesis — all streamed back as server-sent events.\n\n### Steps\n\n1. **Arrival** — the client posts to `POST /chat` (`openexecutive.api.routes.chat`). The turn carries a `<current_speaker>` hint resolved from the caller's `person_id`, plus a `<briefing>` digest of current open alerts (built in parallel with RAG/episodic/peer-memory fetches) so the Executive can discuss any item shown on the `/today` briefing page.\n2. **Tool-use loop** — the `Executive` calls Claude. For a cross-domain question the assistant turn emits multiple `consult_specialist` tool-use blocks at once.\n3. **Parallel fan-out** — `openexecutive.orchestrator.router.route_parallel` dispatches those calls concurrently, bounded by `MAX_PARALLEL_SPECIALISTS`; calls past the cap get a skip tool_result.\n4. **Per-specialist RAG** — each specialist runs its own domain-filtered ChromaDB query, then reasons over the retrieved chunks and returns analysis as a tool_result.\n5. **Synthesis** — the Executive feeds the tool_results back to Claude and streams one coherent reply; a `thinking` keepalive covers the specialist round.\n6. **Optional committee review** — when enabled, `Executive.stream_chat_with_committee()` runs a silent draft, parallel reviewer critiques, then a streamed revision pass.\n7. **Side effects** — any side-effecting tool call surfaces an `action_taken` chip; the stream closes with a `done` event.\n\nWeb search, when invoked on the Anthropic path, executes inside the Anthropic API itself (`web_search_20250305`) and returns within the same generation; for any model routed via OpenRouter the same tool becomes OpenRouter's web plugin, which runs one prompt-derived search before generation and injects the results (the model cannot search again mid-turn).",+ "markdown": "A single chat message makes a full round-trip through the API, the orchestrator's tool-use loop, a parallel specialist fan-out, and synthesis — all streamed back as server-sent events.\n\n### Steps\n\n1. **Arrival** — the client posts to `POST /chat` (`openexecutive.api.routes.chat`). The turn carries a `<current_speaker>` hint resolved from the caller's `person_id`, plus a `<briefing>` digest of current open alerts (built in parallel with RAG/episodic/peer-memory fetches) so the Executive can discuss any item shown on the `/today` briefing page.\n2. **Tool-use loop** — the `Executive` calls Claude. For a cross-domain question the assistant turn emits multiple `consult_specialist` tool-use blocks at once.\n3. **Parallel fan-out** — `openexecutive.orchestrator.router.route_parallel` dispatches those calls concurrently, bounded by `MAX_PARALLEL_SPECIALISTS`; calls past the cap get a skip tool_result.\n4. **Per-specialist RAG** — each specialist runs its own domain-filtered ChromaDB query, then reasons over the retrieved chunks and returns analysis as a tool_result.\n5. **Synthesis** — the Executive feeds the tool_results back to Claude and streams one coherent reply; a `thinking` keepalive covers the specialist round.\n6. **Optional committee review** — when enabled, `Executive.stream_chat_with_committee()` runs a silent draft, parallel reviewer critiques, then a streamed revision pass.\n7. **Side effects** — any side-effecting tool call surfaces an `action_taken` chip; the stream closes with a `done` event.\n\nWeb search, when invoked on the Anthropic path, executes inside the Anthropic API itself (`web_search_20250305`) and returns within the same generation; for any model routed via OpenRouter the same tool becomes OpenRouter's `openrouter:web_search` server tool, which also runs inside the generation with the same search cap and domain lists.","mermaid": "sequenceDiagram\n participant C as Client\n participant API as FastAPI /chat\n participant E as Executive\n participant CL as Claude\n participant S as Specialists\n participant KB as ChromaDB\n C->>API: POST /chat message\n API->>E: start turn\n E->>CL: messages (tool-use loop)\n CL-->>E: consult_specialist calls\n E->>S: route_parallel fan-out\n S->>KB: domain-filtered RAG\n KB-->>S: chunks\n S-->>E: analysis tool_results\n E->>CL: synthesize\n CL-->>E: streamed reply\n E-->>API: SSE chunks then done\n API-->>C: streamed response","generated_at": "2026-06-01T00:00:00+00:00"}diff --git a/packages/core/openexecutive/monitoring/models.py b/packages/core/openexecutive/monitoring/models.pyindex 65301874..ab30c287 100644--- a/packages/core/openexecutive/monitoring/models.py+++ b/packages/core/openexecutive/monitoring/models.py@@ -21,7 +21,7 @@ SOURCE_KIND_VENDOR_STATUS = "vendor_status"SOURCE_KIND_RSS = "rss" # reserved for PR-BSOURCE_KIND_STOCK = "stock" # reserved for PR-B# Standing web-search query — runs a natural-language query on a cadence via-# the provider's web_search tool (Anthropic native or OpenRouter web plugin),+# the provider's web_search tool (Anthropic native or OpenRouter's server tool),# so the watchlist can monitor *arbitrary* conditions, not just feeds.SOURCE_KIND_QUERY = "query"# SEC EDGAR filings — polls a company's recent filings (8-K / 10-K / 10-Q /diff --git a/packages/core/openexecutive/monitoring/sources/query.py b/packages/core/openexecutive/monitoring/sources/query.pyindex ac714d69..4494ce78 100644--- a/packages/core/openexecutive/monitoring/sources/query.py+++ b/packages/core/openexecutive/monitoring/sources/query.py@@ -23,17 +23,17 @@ Watchlist row shape:"allowed_domains": [...], "blocked_domains": [...]}``.``allowed_domains`` / ``blocked_domains`` are passed to the model as*best-effort* prompt hints — they are NOT the same as the global- ``WEB_SEARCH_ALLOWED_DOMAINS`` setting, and the OpenRouter web plugin- does not honour Anthropic's domain-filter fields (see- ``providers/translator.py``), so do not rely on them as a hard guarantee.+ ``WEB_SEARCH_ALLOWED_DOMAINS`` setting (which the provider layer applies+ as a real filter on both the Anthropic and OpenRouter paths), so do not+ rely on them as a hard guarantee.- ``trigger_json``: optional ``{"keywords": [...]}`` — same semantics as therss adapter (a result surfaces only if a keyword appears in title/summary).Provider routing: the call goes through ``BaseAgent.analyze_with_tools`` with``model_override=get_research_model()`` exactly like the research fan-out, so anOpenRouter Council override is honoured. The provider layer translates the-native web_search tool into OpenRouter's ``plugins:[{id:web}]`` when routed-there; no special-casing lives here.+native web_search tool into OpenRouter's ``openrouter:web_search`` server+tool when routed there; no special-casing lives here.Severity hint defaults to ``LOW`` — open-web results are noisy. Capture-timeenrichment (``monitoring.enrichment``) scores relevance downstream and thediff --git a/packages/core/openexecutive/providers/registry.py b/packages/core/openexecutive/providers/registry.pyindex 39745e1b..01df1838 100644--- a/packages/core/openexecutive/providers/registry.py+++ b/packages/core/openexecutive/providers/registry.py@@ -133,13 +133,11 @@ _CLAUDE_FEATURE_SPEC = FeatureSpec(# 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.+# web_search tool never reaches the upstream model — the translator replaces+# it with OpenRouter's own ``openrouter:web_search`` server tool, which works+# for any model OpenRouter serves and carries the same contract (the model+# decides when to search, ``max_uses`` caps searches, domain lists apply,+# the search count is reported)._DEFAULT_NON_CLAUDE_SPEC = FeatureSpec(supports_cache_control=False,supports_thinking=False,@@ -159,7 +157,7 @@ _NON_CLAUDE_REASONING_SPEC = FeatureSpec()# 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+# tool 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,@@ -248,7 +246,7 @@ def _openrouter_model_resolver(model: str) -> tuple[str, FeatureSpec] | None: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``), web search- kept (translated to the ``web`` plugin), cache stripped.+ kept (translated to OpenRouter's server tool), cache stripped.* Anything else → unchanged, the non-Claude default (tools + websearch; cache and thinking stripped)."""@@ -308,7 +306,7 @@ def _local() -> OpenAICompatibleProvider:)# 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.+ # search tool and would 400 (or silently ignore) the rest.spec_lookup: dict[str, FeatureSpec] = {m: _LOCAL_FEATURE_SPEC for m in _local_models(settings)}diff --git a/packages/core/openexecutive/providers/translator.py b/packages/core/openexecutive/providers/translator.pyindex 71dbe6b3..bae4533c 100644--- a/packages/core/openexecutive/providers/translator.py+++ b/packages/core/openexecutive/providers/translator.py@@ -31,16 +31,17 @@ What we DO NOT translate:response are ignored by the response path — only ``content`` and``tool_calls`` are read. Seehttps://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- OpenRouter as-is, so ``to_openai_request`` translates its *intent* into- OpenRouter's ``plugins:[{"id":"web"}]`` web-search plugin (the tool- itself is still dropped from ``tools[]`` — it has no ``input_schema``).- See https://openrouter.ai/docs/guides/features/plugins/web-search.- OpenRouter's plugin injects search results inline and the model cites- them with ``<cite index="...">…</cite>`` markup; the response path- strips that markup so it doesn't leak into findings / chat text.+* Web-search server tools — feature_gate strips these only for the local+ OpenAI-compatible backend. For every OpenRouter model the Anthropic+ ``web_search_*`` server tool (which OpenRouter can't execute as-is, and+ which has no ``input_schema``) is replaced in ``tools[]`` by OpenRouter's+ own ``openrouter:web_search`` server tool with the same ``max_uses`` and+ domain lists, so the search cap and filters hold on this path and the+ response's ``usage.web_search_requests`` is recorded. See+ https://openrouter.ai/docs/guides/features/server-tools/web-search.+ OpenRouter's search makes the model cite results with+ ``(cite index="...">…</cite>`` markup; the response path strips that+ markup so it doesn't leak into findings / chat text."""from __future__ import annotations@@ -290,28 +291,31 @@ def _anthropic_tools_to_openai(tools: list[Any]) -> list[dict[str, Any]]:# Anthropic native web-search server-tool type prefix (e.g.# ``web_search_20250305``). OpenRouter cannot execute Anthropic's server tool,-# but its own ``web`` plugin does the same job, so we translate the intent.+# but its own server tool does the same job, so we translate the intent.logger = logging.getLogger(__name__)_WEB_SEARCH_TOOL_PREFIX = "web_search_"-# OpenRouter's web plugin defaults to 5 results. We derive ``max_results`` from-# the Anthropic tool's ``max_uses`` but cap it: ``max_uses`` is a search *count*-# while ``max_results`` is a result *count* (Exa bills per result), so a large-# ``max_uses`` must not translate into an unbounded result count.-_WEB_PLUGIN_DEFAULT_MAX_RESULTS = 5-_WEB_PLUGIN_MAX_RESULTS_CAP = 10+# OpenRouter's own web-search server tool. Like Anthropic's, it runs inside+# the provider request: the model decides when to search (0..N times), the+# search count is capped server-side by ``max_uses``, domain lists apply, and+# the response reports ``usage.web_search_requests``. The engine is left on+# ``auto``: Claude, GPT, Gemini and Grok use their provider's native search,+# everything else Exa. See+# https://openrouter.ai/docs/guides/features/server-tools/web-search.+_OPENROUTER_WEB_SEARCH_TYPE = "openrouter:web_search"-def _web_search_plugin(tools: Any) -> dict[str, Any] | None:- """Return the OpenRouter ``web`` plugin spec when ``tools`` carries an- Anthropic native ``web_search_*`` server tool, else ``None``.+def _web_search_server_tool(tools: Any) -> dict[str, Any] | None:+ """Return the OpenRouter ``openrouter:web_search`` server tool entry+ when ``tools`` carries an Anthropic native ``web_search_*`` server tool,+ else ``None``.OpenRouter's OpenAI-format endpoint can't run Anthropic's server-side``web_search_20250305`` tool — ``_anthropic_tools_to_openai`` drops it- (no ``input_schema``), which would silently strip web search from a- Claude call routed via OpenRouter. We instead reproduce its intent with- OpenRouter's ``plugins:[{"id":"web"}]`` mechanism. ``max_results`` is- derived from the tool's ``max_uses`` (capped).+ (no ``input_schema``), which would silently strip web search from a call+ routed via OpenRouter. Its own server tool carries the same controls, so+ ``max_uses`` and the domain lists translate one-to-one+ (``blocked_domains`` → ``excluded_domains``)."""if not isinstance(tools, list):return None@@ -322,31 +326,21 @@ def _web_search_plugin(tools: Any) -> dict[str, Any] | None:and isinstance(t.get("type"), str)and t["type"].startswith(_WEB_SEARCH_TOOL_PREFIX)):- if t.get("allowed_domains") or t.get("blocked_domains"):- # The plugin has no domain filter. A configured allow/block- # list is a real control, so fail closed: no search at all- # on this path rather than an unrestricted one.- logger.warning(- "web_search: WEB_SEARCH_ALLOWED_DOMAINS / BLOCKED_DOMAINS cannot "- "be applied to OpenRouter's web plugin — search disabled for "- "this OpenRouter call"- )- return None+ params: dict[str, Any] = {}max_uses = t.get("max_uses")- # ``max_uses`` is a search COUNT; the plugin runs one search and- # ``max_results`` is how many results it injects. Never go below- # the plugin's own default (a cap of two searches must not become- # two results), and cap the top so a large search budget cannot- # become an unbounded result count (Exa bills per result). bool- # is an int subtype, so exclude it explicitly.- max_results = (- min(max(max_uses, _WEB_PLUGIN_DEFAULT_MAX_RESULTS), _WEB_PLUGIN_MAX_RESULTS_CAP)- if isinstance(max_uses, int)- and not isinstance(max_uses, bool)- and max_uses > 0- else _WEB_PLUGIN_DEFAULT_MAX_RESULTS- )- return {"id": "web", "max_results": max_results}+ # bool is an int subtype, so exclude it explicitly.+ if isinstance(max_uses, int) and not isinstance(max_uses, bool) and max_uses > 0:+ params["max_uses"] = max_uses+ allowed = t.get("allowed_domains")+ if isinstance(allowed, list) and allowed:+ params["allowed_domains"] = [str(d) for d in allowed]+ blocked = t.get("blocked_domains")+ if isinstance(blocked, list) and blocked:+ params["excluded_domains"] = [str(d) for d in blocked]+ tool: dict[str, Any] = {"type": _OPENROUTER_WEB_SEARCH_TYPE}+ if params:+ tool["parameters"] = params+ return toolreturn None@@ -417,14 +411,14 @@ def to_openai_request(model_slug: str, anthropic_kwargs: dict[str, Any]) -> dicttools = anthropic_kwargs.get("tools")if tools:translated = _anthropic_tools_to_openai(tools)+ # Anthropic's web_search server tool is dropped from ``tools`` above+ # (OpenRouter can't execute it); OpenRouter's own server tool takes+ # its place with the same cap and domain lists.+ web_search = _web_search_server_tool(tools)+ if web_search is not None:+ translated.append(web_search)if translated:body["tools"] = translated- # Anthropic's web_search server tool is dropped from ``tools`` above- # (OpenRouter can't execute it); reproduce its intent via OpenRouter's- # ``web`` plugin so search still runs for Claude-via-OpenRouter calls.- web_plugin = _web_search_plugin(tools)- if web_plugin is not None:- body["plugins"] = [web_plugin]tool_choice = anthropic_kwargs.get("tool_choice")if tool_choice is not None:@@ -514,7 +508,7 @@ def _stop_reason_from_openai(reason: str | None) -> str:return reason or "end_turn"-# OpenRouter's web plugin makes the model cite sources with inline+# OpenRouter's web search makes the model cite sources with inline# ``<cite index="3-14,3-15">…</cite>`` markup (it appears both in free text and# inside tool-call argument strings). The wrapper tags are an upstream artifact# that would otherwise leak into research findings, artifacts, and chat replies,@@ -540,7 +534,7 @@ def _remove_complete_cite_tags(text: str) -> str:def _parse_tool_arguments(raw_args: Any, tool_name: str) -> Any:- """Parse a tool call's JSON arguments. The web plugin's ``<cite>`` markup+ """Parse a tool call's JSON arguments. OpenRouter search's ``<cite>`` markupcan land inside argument strings with unescaped quotes; strip it from theraw text before parsing so a citation cannot turn a full payload into anempty one. A payload that still fails to parse is logged (it would@@ -626,6 +620,10 @@ def from_openai_response(body: dict[str, Any]) -> SimpleNamespace:content_blocks.append(_block("text", text=_strip_cite_markup(text)))for call in msg.get("tool_calls") or []:+ if call.get("type") not in (None, "function"):+ # A server-side tool call (OpenRouter executed it already) is not+ # for the caller to run.+ continuefn = call.get("function") or {}raw_args = fn.get("arguments") or "{}"parsed = _parse_tool_arguments(raw_args, fn.get("name", ""))@@ -664,10 +662,23 @@ def from_openai_response(body: dict[str, Any]) -> SimpleNamespace:# Actual USD charged for this generation, present when the request# set `usage: {include: true}`. None for upstreams that omit it.cost=usage.get("cost"),+ server_tool_use=_server_tool_usage(usage),),)+def _server_tool_usage(usage: dict[str, Any]) -> SimpleNamespace:+ """Anthropic-shape ``usage.server_tool_use`` from OpenRouter's flat+ ``usage.web_search_requests`` (present when the request carried the+ ``openrouter:web_search`` server tool; 0 otherwise)."""+ raw = usage.get("web_search_requests", 0)+ try:+ count = int(raw or 0)+ except (TypeError, ValueError, OverflowError):+ count = 0+ return SimpleNamespace(web_search_requests=count)++def _extract_cache_token_counts(usage: dict[str, Any]) -> tuple[int, int]:"""Pull cache_read / cache_create token counts out of an OpenAI-formatusage block, accommodating OpenRouter's nesting shape.@@ -785,6 +796,8 @@ class StreamAccumulator:self._reasoning_details.extend(details)for tc in delta.get("tool_calls") or []:+ if tc.get("type") not in (None, "function"):+ continue # server-side tool call, already executed upstreamidx = tc.get("index", 0)slot = self._tool_calls.setdefault(idx, {"id": "", "name": "", "arg_chunks": []}@@ -861,5 +874,6 @@ class StreamAccumulator:# Actual USD charged, from the stream's final usage chunk when# the request set `usage: {include: true}`. None if absent.cost=self._usage.get("cost"),+ server_tool_use=_server_tool_usage(self._usage),),)diff --git a/packages/core/tests/unit/test_openrouter_translator.py b/packages/core/tests/unit/test_openrouter_translator.pyindex 209b331d..3c4abf31 100644--- a/packages/core/tests/unit/test_openrouter_translator.py+++ b/packages/core/tests/unit/test_openrouter_translator.py@@ -247,7 +247,7 @@ def test_request_flattens_user_content_to_string_when_no_cache_control() -> Noneassert user_msg["content"] == "Part one\n\nPart two"-def test_request_drops_web_search_tool_but_injects_web_plugin() -> None:+def test_request_replaces_anthropic_web_search_with_openrouter_server_tool() -> None:body = to_openai_request("anthropic/claude-opus-4.7",{@@ -257,69 +257,57 @@ def test_request_drops_web_search_tool_but_injects_web_plugin() -> None:],},)- # The Anthropic server tool has no OpenAI equivalent — it's still dropped- # from ``tools`` so the body doesn't carry a phantom function entry...- assert "tools" not in body or body["tools"] == []- # ...but its intent is reproduced via OpenRouter's ``web`` plugin so search- # actually runs (the bug this fixes: research specialists got no search and- # emitted zero findings). Default max_results when no max_uses is given.- assert body["plugins"] == [{"id": "web", "max_results": 5}]+ # The Anthropic server tool has no OpenAI equivalent, so it is replaced+ # in ``tools`` by OpenRouter's own server tool (the bug this fixes:+ # research specialists got no search and emitted zero findings). With+ # no max_uses or domain lists there are no parameters.+ assert body["tools"] == [{"type": "openrouter:web_search"}]+ assert "plugins" not in body-def test_request_web_search_max_uses_maps_to_capped_max_results() -> None:- # max_uses within the cap is honored verbatim.+def test_request_web_search_translates_cap_and_domain_lists() -> None:+ # max_uses is a search count on both sides: it passes through unchanged,+ # so RESEARCH_WEB_SEARCH_MAX_USES caps searches via OpenRouter too.body = to_openai_request(- "anthropic/claude-opus-4.7",+ "google/gemini-2.5-flash",{"messages": [{"role": "user", "content": "hi"}],"tools": [- {"type": "web_search_20250305", "name": "web_search", "max_uses": 8},+ {"name": "emit", "input_schema": {"type": "object"}},+ {"type": "web_search_20250305", "name": "web_search", "max_uses": 3,+ "allowed_domains": ["sec.gov", "federalregister.gov"]},],},)- assert body["plugins"] == [{"id": "web", "max_results": 8}]-- # A small search budget never becomes a tiny result count: the plugin- # runs one search, so its own default (5) is the floor.- small = to_openai_request(+ assert body["tools"] == [+ {"type": "function", "function": {"name": "emit", "description": "", "parameters": {"type": "object"}}},+ {"type": "openrouter:web_search",+ "parameters": {"max_uses": 3, "allowed_domains": ["sec.gov", "federalregister.gov"]}},+ ]+ blocked = to_openai_request("anthropic/claude-opus-4.7",{"messages": [{"role": "user", "content": "hi"}],"tools": [- {"type": "web_search_20250305", "name": "web_search", "max_uses": 2},+ {"type": "web_search_20250305", "name": "web_search", "max_uses": 8,+ "blocked_domains": ["example.com"]},],},)- assert small["plugins"] == [{"id": "web", "max_results": 5}]-- # A configured domain list cannot be applied by the plugin: fail closed.- for key in ("allowed_domains", "blocked_domains"):- restricted = to_openai_request(+ assert blocked["tools"] == [+ {"type": "openrouter:web_search",+ "parameters": {"max_uses": 8, "excluded_domains": ["example.com"]}},+ ]+ # A bool or non-positive max_uses is not a cap.+ for bad in (True, 0, -1, "3"):+ odd = to_openai_request("anthropic/claude-opus-4.7",- {- "messages": [{"role": "user", "content": "hi"}],- "tools": [- {"type": "web_search_20250305", "name": "web_search", "max_uses": 3, key: ["sec.gov"]},- ],- },+ {"messages": [], "tools": [{"type": "web_search_20250305", "name": "web_search", "max_uses": bad}]},)- assert "plugins" not in restricted-- # An oversized max_uses is capped so a search *count* can't become an- # unbounded result *count* (Exa bills per result).- capped = to_openai_request(- "anthropic/claude-opus-4.7",- {- "messages": [{"role": "user", "content": "hi"}],- "tools": [- {"type": "web_search_20250305", "name": "web_search", "max_uses": 50},- ],- },- )- assert capped["plugins"] == [{"id": "web", "max_results": 10}]+ assert odd["tools"] == [{"type": "openrouter:web_search"}]-def test_request_no_web_plugin_without_web_search_tool() -> None:+def test_request_no_server_tool_without_web_search_tool() -> None:body = to_openai_request("anthropic/claude-opus-4.7",{@@ -333,11 +321,35 @@ def test_request_no_web_plugin_without_web_search_tool() -> None:],},)- # Ordinary client tools must not trigger the web plugin.- assert "plugins" not in body+ # Ordinary client tools must not trigger the web-search server tool.+ assert [t["type"] for t in body["tools"]] == ["function"]assert body["tools"][0]["function"]["name"] == "consult_specialist"+def test_response_reports_search_count_and_skips_server_tool_calls() -> None:+ msg = from_openai_response({+ "id": "x", "model": "anthropic/claude-sonnet-5",+ "choices": [{"finish_reason": "tool_calls", "message": {+ "role": "assistant", "content": "done",+ "tool_calls": [+ {"id": "s1", "type": "openrouter:web_search", "function": {"name": "web_search", "arguments": "{}"}},+ {"id": "c1", "type": "function",+ "function": {"name": "emit_research_findings", "arguments": "{\"findings\": []}"}},+ ],+ }}],+ "usage": {"prompt_tokens": 10, "completion_tokens": 2, "web_search_requests": 3},+ })+ assert msg.usage.server_tool_use.web_search_requests == 3+ assert [b.name for b in msg.content if b.type == "tool_use"] == ["emit_research_findings"]+ # Absent → 0, never missing (audit usage reads it on every row).+ plain = from_openai_response({+ "id": "y", "model": "m",+ "choices": [{"finish_reason": "stop", "message": {"role": "assistant", "content": "ok"}}],+ "usage": {"prompt_tokens": 1, "completion_tokens": 1},+ })+ assert plain.usage.server_tool_use.web_search_requests == 0++def test_request_lifts_assistant_tool_use_blocks_to_tool_calls() -> None:body = to_openai_request("openai/gpt-5",@@ -1011,3 +1023,12 @@ def test_stream_accumulator_emits_legitimate_trailing_text_with_angle_bracket()if ev.type == "content_block_delta" and ev.delta.type == "text_delta":streamed += ev.delta.textassert streamed == "5 < 10 is true."+++def test_stream_accumulator_reports_search_count() -> None:+ acc = StreamAccumulator()+ acc.feed({"id": "s", "model": "m", "choices": [{"delta": {"content": "hi"}, "finish_reason": None}]})+ acc.feed({"id": "s", "model": "m", "choices": [{"delta": {}, "finish_reason": "stop"}],+ "usage": {"prompt_tokens": 5, "completion_tokens": 1, "web_search_requests": 2}})+ msg = acc.finalize()+ assert msg.usage.server_tool_use.web_search_requests == 2diff --git a/packages/core/tests/unit/test_research_controls.py b/packages/core/tests/unit/test_research_controls.pyindex 74befbd9..cb17b59d 100644--- a/packages/core/tests/unit/test_research_controls.py+++ b/packages/core/tests/unit/test_research_controls.py@@ -110,7 +110,8 @@ def test_non_claude_openrouter_models_keep_web_search_but_local_models_do_not(assert not registry._LOCAL_FEATURE_SPEC.supports_web_search- # End to end through the gate + translator: the plugin is attached.+ # End to end through the gate + translator: OpenRouter's server tool+ # replaces the Anthropic one with the same cap.kwargs = {"model": "google/gemini-2.5-flash", "max_tokens": 10, "messages": [],"tools": [@@ -120,11 +121,12 @@ def test_non_claude_openrouter_models_keep_web_search_but_local_models_do_not(}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": 5}] # plugin default is the floor- assert [t["function"]["name"] for t in body["tools"]] == ["emit"]+ assert body["tools"][-1] == {"type": "openrouter:web_search", "parameters": {"max_uses": 3}}+ assert [t["function"]["name"] for t in body["tools"][:-1]] == ["emit"]stripped = apply_feature_gates(registry._LOCAL_FEATURE_SPEC, dict(kwargs))- assert "plugins" not in to_openai_request("local-model", stripped)+ local_body = to_openai_request("local-model", stripped)+ assert all(t["type"] == "function" for t in local_body["tools"])def test_local_backend_provider_never_carries_web_search(monkeypatch: pytest.MonkeyPatch) -> None: