Skip to content

feat(websearch): let the model pick a provider per call - #64486

Open
TOMUIV wants to merge 1 commit into
anomalyco:devfrom
TOMUIV:feat/websearch-tool-provider-id
Open

TOMUIV wants to merge 1 commit into
anomalyco:devfrom
TOMUIV:feat/websearch-tool-provider-id

Conversation

@TOMUIV

@TOMUIV TOMUIV commented Nov 17, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

WebSearch.Input.providerID already exists in the schema, the HTTP API and the plugin host, but the model-facing tool only declares query, so a model that names a provider has that field silently dropped. This wires the existing field through to the model.

The input gains an optional providerID, and the session context hook rewrites it into a JSON-Schema enum built from the live provider registry, so providers registered by plugins appear automatically. A pinned provider is used as-is for that one call: no failover, no cooldown write, and no change to the saved preference — only the user's answers to the consent form write websearch:provider. An unknown id fails with the available ids instead of falling back, and WebSearch.query now also honours a saved "disabled" for explicit-provider callers.

How did you verify your code works?

Ran from source with the simulated model: the advertised schema contains the enum, a call naming exa goes through the normal consent form, an unknown id fails with the available list, and a pinned call leaves websearch:provider untouched. bun run --cwd packages/core test test/tool-websearch.test.ts test/websearch.test.ts test/plugin/websearch.test.ts and bun run --cwd packages/core typecheck pass.

Screenshots / recordings

No UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Public API: adds optional providerID to the model-facing websearch tool; POST /api/websearch with providerID now honours a disabled web search (otherwise backwards compatible)

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Nov 17, 2026

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature works as described. Running OpenCode from source with the simulated model, the websearch tool now gets an optional providerID with an enum of the live provider IDs, and a model call that names exa goes through the usual consent form. On the base, a call with providerID isn't rejected as the description says: the field is quietly ignored. I couldn't run a real search through a pinned provider (no credentials). The websearch, tool-websearch and session-ui sources tests pass, and tsc -b in packages/core is clean.

Public API: the model-facing websearch tool gains an optional providerID input (backwards compatible). POST /api/websearch with providerID while web search is disabled now returns websearch_disabled (400) instead of searching, which is a behaviour change for HTTP callers. The SDK, client, schema and plugin API are unchanged.

Concerns:

  • Please rebase on dev. #64471 replaced the tool output with a plain array of results (the provider is kept only in metadata), which conflicts with the { provider, results } output and the new Provider: line here. #64475 made codemode follow the full_codemode flag instead of false. After rebasing, please check that the providerID enum, which is written by the session context hook, still reaches the model in Code Mode.
  • The model can override a provider the user explicitly chose (see inline). This needs a maintainer decision.
  • Tests: tool-websearch.test.ts gains about 680 lines for one optional field. Please cut it down to a few small cases: the enum appears, an unknown ID fails, disabled beats a pinned provider, and a pinned call doesn't change the saved preference.
  • Scope: about 330 lines of tool code is a lot for exposing one field. The name sanitising, enum size limits, re-mapping provider-not-found errors after the consent form, and the special 429 message could mostly go, which would make the change easier to review and maintain.

yield* permission.assertNotDenied(approval)
return yield* new WebSearch.DisabledError()
}
needsConsent = saved.value === undefined

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the user has saved a specific provider ("Choose another provider" in the form, or a provider set in config), a pinned providerID still overrides it for that call. A user who picked a provider for cost, privacy or account reasons loses that control, and the model decides instead. Before this change, the tool always used the user's selection. Should a pinned provider only be honoured when the saved choice is random/unset, or should this be confirmed as the intended product behaviour first?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken — I adopted the conservative option.

With a specific saved provider, that choice wins: providerID must match it, and a different id is refused with Web search is pinned to "<saved>" by the user. Omit providerID or pass "<saved>". Only "random" (or no choice yet) lets the model pick. The refusal happens before the search and before any approval prompt, so it costs no provider call and leaves no saved permission.

WebSearch.selection() is now exposed on the service so the tool can read the saved choice without guessing from default() (which cannot tell "random" from a specific id). Test: saved exa + request parallel fails with the message and runs zero queries; saved random + request parallel still searches with parallel. Docs updated on websearch.mdx. See 6083d36.

.join("\n\n")
: NO_RESULTS
const content = [
`Provider: ${displayText(output.provider)}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#64471 just removed provider from the tool output (it is now an array of results, with the provider only in metadata). This extra Provider: line in the content also needs sources.ts to know to skip it. Please rebase and check that it fits the new output shape, or drop it: the provider is already recorded in metadata.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in the rebase — the Provider: line is gone entirely. content is now byte-identical to dev (flat result array, provider only in metadata), so sources.ts needs no special case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed at 6083d36: the Provider: line is gone, the output and content follow #64471's flat result array with the provider only in metadata, and sources.ts is no longer touched. This thread is resolved. The only open point is the enum one from my latest review: when a specific provider is saved, the enum still lists every id.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@TOMUIV
TOMUIV force-pushed the feat/websearch-tool-provider-id branch from f4cc7b9 to 7f70a46 Compare November 17, 2026 18:24
@TOMUIV

TOMUIV commented Nov 17, 2026

Copy link
Copy Markdown
Author

Rebased onto dev (0e447fc) and cut the change down per the review. Thanks for the detailed pass.

Rebase

  • refactor(core): simplify websearch tool results #64471: output is now the flat result array and the provider stays in metadata. I dropped the Provider: content line entirely, so content is byte-identical to dev.
  • feat(core): enable websearch in full Code Mode #64475: codemode now follows full_codemode and I kept that. One consequence worth stating: when full_codemode is on, this tool is advertised from the Code Mode catalog, whose schema is rendered and cached from the registry, so the enum only applies on the direct-tool path. Unknown ids still fail with the full list, and the default (full_codemode off) keeps the enum.

Size

  • Tool code: ~330 → 65 lines. Removed the name sanitising, the enum size limits, the post-consent ProviderNotFound remapping (and the Effect.result/suspend structure it needed), the special 429 message, and the withProviderEnum helper (inlined into the hook).
  • Tests: ~680 → 102 lines, five cases: the enum appears in the model-visible schema, a pinned call doesn't change the saved choice, an unknown id fails before searching, consent still runs before the first pinned search, and disabled beats a pinned provider at the service layer.
  • Total now +186/−8 across 6 files.

On the override question

Happy to defer to you here. The intent was that providerID only routes this call: it never writes websearch:provider, never enters the 429 cooldown, and doesn't fail over. A saved disabled now also wins inside WebSearch.query, so an explicit id can't reopen search the user turned off, and the first use still goes through the consent form. So it can't move the user's preference, only pick among providers the user has already consented to.

If you'd rather user choice be absolute, I can either drop the request path or gate it behind a flag — say which you prefer and I'll adjust.

Also noted: on dev a providerID is silently dropped rather than rejected; the description now says that.

`WebSearch.Input.providerID` already exists in the schema, the HTTP API and the
plugin host, but the model-facing tool only declares `query`, so a model that
names a provider has it silently dropped. Wire the field through.

- The input gains an optional `providerID`, and the session context hook rewrites
  it into a JSON-Schema enum built from the live provider registry, so providers
  registered by plugins appear automatically. Ids are de-duplicated and sorted,
  so the emitted schema is byte-identical while the set is unchanged.
- A pinned provider is used as-is for that one call: no failover, no cooldown
  write, and no change to the saved preference — only the user's answers to the
  consent form write `websearch:provider`.
- A provider the user saved outranks the request: with a specific saved choice,
  `providerID` must match it, so a search can never leave the provider the user
  chose. With `"random"` (or before consent) the model is free to pick.
- An unknown id fails with the available ids instead of falling back, and
  `WebSearch.query` now also honours a saved "disabled" for explicit-provider
  callers.
@TOMUIV
TOMUIV force-pushed the feat/websearch-tool-provider-id branch from 7f70a46 to 6083d36 Compare November 17, 2026 18:58

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 6083d36. All my earlier points are resolved: a provider the user saved (in the consent form or in config) now wins, and a different providerID is refused before the approval prompt, with policy deny rules still checked first. The PR is rebased onto #64471 and #64475, so the output follows the new array format, the Provider: line is gone, and sources.ts is no longer touched. The Code Mode limitation is documented, and the change and its tests are much smaller. The websearch tests (62 pass) and tsc -b in packages/core pass.

Public API: the model-facing websearch tool gains an optional providerID (backwards compatible). POST /api/websearch with providerID while web search is disabled now returns websearch_disabled instead of searching, which is a behaviour change for HTTP callers. WebSearch.Service.selection() is new but internal to core and not exposed to plugins. The SDK, client, schema and plugin API are unchanged.

One remaining point, not blocking: when a specific provider is saved, the enum still lists every provider (inline).

...properties,
providerID: {
type: "string",
enum: Array.from(new Set(providers.map((provider) => provider.id))).toSorted(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the user has saved a specific provider, the tool refuses every other id, but this enum still lists all providers. The model is invited to make calls that will always fail. Could the hook publish only the saved id in that case (or drop providerID from the schema), and keep the full list for random or no choice yet? It would only need the same websearch.selection() read the tool already does.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant