DSH / Atlas
2026-09-27implementedarchitecture

Offer web_search and web_fetch only while the selected provider is ready

仅在选中的提供方就绪时提供 web_search 与 web_fetch

`dsh-tool-web` registers `web_search` whenever search is enabled, and the [web capability seam decision](2026-06-24-web-capability-seam.md) keeps it visible while the selected provider cannot run. The DeepSeek web providers authenticate an operation with the DeepSeek account token only for a model request on the `deepseek-account` route; every other route needs a configured API key. Without a readiness check, a Sessi

English

Problem

dsh-tool-web registers web_search whenever search is enabled, and the web capability seam decision keeps it visible while the selected provider cannot run. The DeepSeek web providers authenticate an operation with the DeepSeek account token only for a model request on the deepseek-account route; every other route needs a configured API key. Without a readiness check, a Session on an API-key route without a key is offered a tool whose every call fails with WEB_PROVIDER_CREDENTIAL_MISSING. Sessions in one Host can use different routes, a Session can switch routes between requests, and the Web app registers web_search once per agent preset, so no registration decision matches every request. The Fetch API of dsh-web-deepseek-api, which the user selects separately from the search provider (provider selection), needs the same credential, so such a Session with it selected would also be offered a web_fetch whose every call fails.

Decision

Each role of the web capability seam owns one part of the readiness check that decides whether an Agent sees each Web tool:

  • Service Definition. WebSearchProvider and WebFetchProvider have an optional ready(llmProvider) that answers whether an operation made for a model request on that chat route has a credential to send. It checks configuration only and makes no network calls. ctx.web.searchReady(llmProvider?) and ctx.web.fetchReady(llmProvider?) resolve the provider with the same rules as search() and fetch() and return its answer. A provider without ready() counts as ready, and a selection failure answers true because the operation reports that failure as a structured WebError.
  • Service Provider. Each DeepSeek provider checks its credentials in the order its operation resolves them. dsh-web-search-deepseek checks, in a conversation on the account route, whether ctx.deepseekAuth has the account sign-in configured for its Messages endpoint, and then its literal apiKey or its apiKeyEnv reference. The Search and Fetch API providers of dsh-web-deepseek-api resolve the same plan as the operation (credential resolution): a capability with its own YAML fields checks only the key under its *ApiKeyEnv; otherwise, on the account route with the account model route mounted, the account sign-in configured for the endpoint under that route's origin counts, and then the key of the deepseek-official route, or DEEPSEEK_API_KEY without that route. A key counts when ctx.credentials.describe() reports its reference configured (without that service, when the launching environment carries it); ctx.deepseekAuth performs these checks, a key's through the reference helpers of dsh-credentials. A failed account-token or credential-store read answers false, because the operation fails on that read instead of trying the next credential. The providers name no tool or prompt section.
  • Consumer. dsh-tool-web registers web_search and web_fetch in an AgentToolRegistry, asks ctx.web.searchReady() and ctx.web.fetchReady() about the route agent.model.current() names, and adds or removes each tool for that Agent. It checks when the Agent is created, which waits for the check; when the Agent's Session records a model selection, a request on another route, or a preset change; when a stored credential or the account sign-in changes; when the registered Web providers change; and for Agents that exist when it loads. The tool:web_search and tool:web_fetch prompt sections are registered with the tools and render for an Agent only while tool-web has added the tool for it. A step captures its tools once, so the declared tools, PTC program bindings, and dispatch read the same tools.

The route decides only whether the account token is checked before the API key, which happens on the deepseek-account route; an API key counts on every route, so a conversation on another provider's model is offered the DeepSeek web tools whenever a DeepSeek key is configured. A Search or Fetch API capability with its own YAML fields ignores the route and is ready exactly when its own key is configured.

Only presence decides: no API key value is read and no endpoint is contacted, so a wrong key or an endpoint that does not serve the native web_search_20250305 server tool keeps the tool offered. A step whose Agent lacks a web tool also refuses calls to it as UNKNOWN_TOOL, so a model that repeats an earlier call reaches no provider; an operation made outside a model step resolves its credential when it runs and fails with WEB_PROVIDER_CREDENTIAL_MISSING when there is none.

The request header records the assembled tools, so the agent loop announces each change through tool-registry updates. A route switch, a stored key, or a removed key changes the first request that starts after the check finishes; DeepSeek routes load a returning tool as a deferred addition, and routes without tool-update support receive the complete tool list.

Alternatives considered

Let the DeepSeek provider remove web_search in its own assemble listener. The seam stays unchanged, but the provider then names another package's tool, prompt section, and PTC transport, and it removes the tool even when the deployment selects another search provider, such as one a plugin registers, whose searches would succeed.

Extend available(). It is synchronous and takes no request, while this check reads an asynchronous credential store and depends on the request's route. A route-dependent available() would also make provider selection depend on the conversation.

Read the route from the Session's latest request/context event instead of passing it. That event records the previous request, so a new Session's first request and the first request after a model switch would be decided for the wrong route or for none.

Register or unregister web_search for the whole preset in dsh-tool-web. Registration is shared by every Session of an agent preset, while credentials depend on each request's route. Unregistering would also make toolOrder entries and subagent toolFilter restrictions that name web_search fail. The per-Agent registry keeps one shared registration whose unscoped view still lists the tool, so those names stay valid.

Remove web_search from the assembled request. A system-prompt/assemble listener could drop the declaration and its section, but the tool would stay executable, so a model that repeats an earlier call would still run it, and PTC programs would still bind it. Prompt assembly also no longer carries tool declarations.

Offer search only on the DeepSeek account route. Account tokens are issued only for the official endpoint, so a gateway key could never reach DeepSeek. But every shipped profile defaults to the deepseek-official route, so search would be off by default, including the official API-key case.

Withhold the tools from other providers' conversations unless search has a key of its own. A search from another model's conversation bills the DeepSeek key, but DeepSeek search is one of the services that key pays for, and a user who configured it expects search to work whatever model chats. The Search and Fetch APIs send the chat route's own key, and the settings page saves the legacy Messages search key under apiKeyEnv, DEEPSEEK_API_KEY by default, which the chat route also reads, so withholding them would leave a configured key unable to serve another model; a routes setting that opens them would be one more thing a user has to find.

Compare the official chat route's endpoint with the web endpoint and withhold the tools when they differ. It would keep a gateway's key away from DeepSeek, but it would also withhold web tools from users who chat through a proxy or development endpoint with a key the web endpoint accepts. The Search and Fetch APIs instead derive their endpoint from the origin of the route whose key they send, so the key and endpoint come from one route; legacy Messages search keeps its own endpoint, where a gateway user's search fails.

Keep the tool offered and fail at execution. The model spends a call on a search that cannot authenticate, and the failure repeats on every attempt.

Probe the key or endpoint before offering the tool. A network request per model request adds latency and cost; the user controls configuration, not its validity at that moment.

Check before every step from an awaited step event. Every step would read its exact route and current credentials, but the agent loop would keep a public per-step extension point for this one consumer, and the check would run for every Agent and step although its inputs change rarely; most of them change through an event, and the ones without one are listed under Consequences.

Consequences

dsh-web gains public members: the optional ready() of both provider interfaces, WebRuntime.searchReady(), and WebRuntime.fetchReady(). Each readiness method is the smallest query its one consumer needs, which is how the observation-surface decision lets a status query return; neither reports availability or selection failures. The HTTP fetch provider implements no ready(), so web_fetch stays offered whenever HTTP fetch is selected. A step whose Agent lacks a web tool leaves it out of PTC program bindings too. An endpoint that cannot serve the native server tool keeps the tool offered and fails each call. A step that starts while a check runs uses the previous answer, so the first step after a model switch can still offer or omit a tool for the previous route; Web provider settings edited without a change event, such as a literal key, a key reference name, or the selected provider, apply at the Agent's next check. The route of a blank Web Session that follows the default model also changes without an event when another Session saves a new default: the first step uses the answer checked for the old route, that step's request/header starts a check, and if the new route is not ready the tool is withdrawn while the model answers, so a declared web_search call fails as UNKNOWN_TOOL, or with WEB_PROVIDER_CREDENTIAL_MISSING when it starts before the check settles. Removing a tool on an unchanged route changes the declared tools and misses the prompt cache once; a model switch already invalidates it. Searches and fetches from other providers' conversations bill the configured DeepSeek key. A deployment whose official route chats through a gateway sends the gateway's key to that gateway's origin with /v1/tools for the Search and Fetch APIs, and to the configured Messages endpoint, the official one by default, for legacy Messages search, where each search fails unless that endpoint accepts the key. The Search and Fetch APIs read the DeepSeek model routes' Loader entries through the model provider directory.

Unit tests pin each role: web.spec.ts covers which provider searchReady() and fetchReady() ask and their answer on selection failure, deepseek.spec.ts and credential-resolution.spec.ts cover each credential case of ready() on the account route and on other routes, including readiness that matches each operation, and tool-web.spec.ts prepares model steps that offer or withhold both tools through the real prompt, tool, and root registry services, including the UNKNOWN_TOOL refusal of a call in a step that withheld the tool. In real compositions, the shipped headless keyless smoke test and the web-search-unconfigured recorded-session snapshot, whose search key references are unset, pin the withheld search tool. Snapshot replays supply a placeholder DeepSeek key, so their tool lists do not depend on the runner's environment; with it, the pi-ai-conversation-updates conversation on a pi-ai route keeps web_search.

中文

Problem

dsh-tool-web 在启用搜索时总会注册 web_search,而 web 能力 seam 决策让它在选中的提供方无法运行时仍然可见。DeepSeek Web 提供方只对 deepseek-account 路由上的模型请求使用 DeepSeek 账号 token 为操作鉴权;其他路由都需要已配置的 API 密钥。没有就绪检查时,API 密钥路由上没有密钥的会话会获得一个每次调用都以 WEB_PROVIDER_CREDENTIAL_MISSING 失败的工具。同一 Host 中的会话可以使用不同路由,一个会话可以在请求之间切换路由,而 Web 应用按 agent preset 只注册一次 web_search,因此任何注册层面的决定都无法与每个请求相符。dsh-web-deepseek-api 的 Fetch API 由用户与搜索提供方分别选择(提供方选择),它需要同一份凭据,因此这样的会话选中它时,还会获得一个每次调用都失败的 web_fetch。

Decision

web 能力 seam 的每个角色各负责就绪检查的一部分,该检查决定 Agent 能否看到每个 Web 工具:

  • Service Definition。 WebSearchProvider 与 WebFetchProvider 有一个可选的 ready(llmProvider),回答为该对话路由上的模型请求发起的操作是否有可发送的凭据。它只检查配置,不发起网络调用。ctx.web.searchReady(llmProvider?) 与 ctx.web.fetchReady(llmProvider?) 按与 search()、fetch() 相同的规则解析提供方并返回其回答。没有 ready() 的提供方视为就绪;选择失败时回答 true,因为对应操作会把该失败报告为结构化 WebError。
  • Service Provider。 每个 DeepSeek 提供方都按其操作解析凭据的顺序检查凭据。dsh-web-search-deepseek 在账号路由上的会话里检查 ctx.deepseekAuth 是否已为其 Messages 端点配置账号登录凭据,然后检查其字面 apiKey 或 apiKeyEnv 引用。dsh-web-deepseek-api 的 Search 与 Fetch API 提供方解析与操作相同的方案(凭据解析):在 YAML 中设置了单独字段的能力只检查其 *ApiKeyEnv 下的密钥;否则,在账号路由上且账号模型路由已挂载时,为该路由 origin 之下的端点配置的账号登录凭据算数,然后是 deepseek-official 路由的密钥,没有该路由时为 DEEPSEEK_API_KEY。ctx.credentials.describe() 报告其引用已配置时(没有该服务时,启动环境中存在该变量),密钥即算存在;这些存在性检查由 ctx.deepseekAuth 执行,其中密钥的检查经由 dsh-credentials 的引用函数。读取账号 token 或凭据存储失败时回答 false,因为操作会在该次读取上失败,而不会尝试下一种凭据。提供方不点名任何工具或提示词段落。
  • Consumer。 dsh-tool-web 在一个 AgentToolRegistry 中注册 web_search 与 web_fetch,以 agent.model.current() 指明的路由询问 ctx.web.searchReady() 与 ctx.web.fetchReady(),再为该 Agent 添加或移除每个工具。它在以下时机检查:创建 Agent 时,创建过程会等待该检查完成;该 Agent 的会话记录模型选择、另一路由上的请求或预设变化时;已存储的凭据或账号登录状态变化时;已注册的 Web 提供方变化时。它加载时还会检查已存在的 Agent。tool:web_search 与 tool:web_fetch 提示词段落与工具一起注册,并且只有在 tool-web 已为某个 Agent 添加该工具时,才会为该 Agent 渲染。每个步骤只捕获一次工具,因此声明的工具、PTC 程序绑定与派发都读取同一组工具。

路由只决定是否先检查账号 token 再检查 API 密钥,这发生在 deepseek-account 路由上;API 密钥在每条路由上都算数,因此只要配置了 DeepSeek 密钥,使用其他提供方模型的对话也会获得 DeepSeek Web 工具。在 YAML 中设置了单独字段的 Search 或 Fetch API 能力不看路由,恰在其自身密钥已配置时就绪。

只看凭据是否存在:不读取 API 密钥的值,也不访问任何端点,因此密钥错误,或端点不提供原生 web_search_20250305 服务器工具时,仍会提供该工具。所属 Agent 没有某个 Web 工具的步骤也会以 UNKNOWN_TOOL 拒绝对它的调用,因此模型重复先前的调用也到达不了任何提供方;在模型步骤之外发起的操作在运行时解析凭据,没有凭据时以 WEB_PROVIDER_CREDENTIAL_MISSING 失败。

请求头记录组装后的工具,因此 agent loop(智能体循环)通过工具注册表更新宣告每次变化。路由切换、存储密钥或删除密钥都会改变检查完成后开始的第一个请求;DeepSeek 路由以延迟加载的新增方式载入重新提供的工具,不支持工具更新的路由则接收完整工具列表。

Alternatives considered

让 DeepSeek 提供方在自己的 assemble 监听器中移除 web_search。 seam 保持不变,但提供方因此要点名另一个包的工具、提示词段落与 PTC 传输工具;而且即使部署选择了另一个搜索成功的提供方(例如插件注册的提供方),它也会移除该工具。

扩展 available()。 它是同步的且不接收请求,而这项检查要读取异步凭据存储,并取决于请求的路由。依赖路由的 available() 还会让提供方选择取决于对话。

从会话最近的 request/context 事件读取路由,而不是传入路由。 该事件记录的是上一个请求,因此新会话的首个请求,以及模型切换后的首个请求,会按错误的路由判断,或根本没有路由可用。

在 dsh-tool-web 中为整个 preset 注册或注销 web_search。 注册由同一 agent preset 的所有会话共享,而凭据取决于每个请求的路由。注销还会使点名 web_search 的 toolOrder 条目和 subagent toolFilter 限制失败。按 Agent 提供工具的注册表保留一份共享注册,其不带作用域的视图仍列出该工具,因此这些名称保持有效。

从组装好的请求中移除 web_search。 system-prompt/assemble 监听器可以删掉该声明及其段落,但工具仍可执行,因此模型重复先前的调用时仍会运行它,PTC 程序也仍能绑定它。提示词组装也已不再携带工具声明。

只在 DeepSeek 账号路由上提供搜索。 账号 token 只对官方端点签发,因此网关的密钥不可能到达 DeepSeek。但所有发行 profile 的默认路由都是 deepseek-official,搜索会因此默认关闭,连官方 API 密钥的情况也一并关闭。

除非搜索有自己的密钥,否则不向其他提供方的对话提供这些工具。 其他模型对话中的搜索会由 DeepSeek 密钥计费,但 DeepSeek 搜索本就是该密钥付费使用的服务之一,配置了它的用户也期望无论用哪个模型对话,搜索都能用。Search 与 Fetch API 发送聊天路由自己的密钥,设置页把旧版 Messages 搜索的密钥存在 apiKeyEnv 指向的引用下,默认是聊天路由也在读取的 DEEPSEEK_API_KEY,因此撤下工具会让已配置的密钥无法服务其他模型;再加一个开放这些路由的 routes 配置项,只会让用户多找一样东西。

比较官方聊天路由的端点与 Web 端点,二者不同时撤下工具。 这能让网关的密钥远离 DeepSeek,但也会让经代理或开发端点对话、而密钥能被 Web 端点接受的用户失去网页工具。Search 与 Fetch API 改为从其所发送密钥的路由的 origin 推导端点,因此密钥与端点来自同一条路由;旧版 Messages 搜索保留自己的端点,网关用户的搜索会在那里失败。

保持工具可见,在执行时失败。 模型会把一次调用花在无法鉴权的搜索上,并且每次尝试都会重复失败。

提供工具前探测密钥或端点。 每个模型请求都发起一次网络请求会增加延迟与成本;用户控制的是配置本身,而不是它在那一刻是否有效。

在每个步骤之前,通过一个需等待完成的步骤事件检查。 这样每个步骤都能读取其确切路由与当前凭据,但 agent loop 要为这一个消费方保留一个公共的逐步骤扩展点,而且尽管检查的输入很少变化,检查仍会对每个 Agent 的每个步骤运行。这些输入大多通过事件变化,没有对应事件的输入列在「Consequences」一节中。

Consequences

dsh-web 增加以下公共成员:两个提供方接口上可选的 ready()、WebRuntime.searchReady() 与 WebRuntime.fetchReady()。每个就绪方法都是其唯一消费方所需的最小查询,这正是观测接口决策允许状态查询回归的方式;它们既不报告可用性,也不报告选择失败。HTTP 抓取提供方没有实现 ready(),因此只要选中 HTTP 抓取,就始终提供 web_fetch。所属 Agent 没有某个 Web 工具的步骤,其 PTC 程序绑定中也没有它。端点无法提供原生服务器工具时,仍会提供该工具,并使每次调用失败。在检查运行期间开始的步骤使用先前的回答,因此模型切换后的第一个步骤仍可能按先前的路由提供或省略某个工具;在没有变化事件的情况下编辑的 Web 提供方设置(例如字面密钥、密钥引用名称或选中的提供方)在该 Agent 的下一次检查时生效。跟随默认模型的空白 Web 会话,其路由也会在另一个会话保存新的默认模型时变化,且没有对应事件:第一个步骤使用针对旧路由检查得到的回答,该步骤的 request/header 会启动一次检查;如果新路由未就绪,该工具会在模型回答期间被撤下,因此已声明的 web_search 调用以 UNKNOWN_TOOL 失败;若该调用在检查结算之前开始,则以 WEB_PROVIDER_CREDENTIAL_MISSING 失败。在路由不变时移除工具会改变声明的工具,并使提示词缓存失效一次;模型切换本身已经使缓存失效。其他提供方对话中的搜索与抓取由配置的 DeepSeek 密钥计费。官方路由经网关对话的部署,对 Search 与 Fetch API 会把网关的密钥发往该网关 origin 加 /v1/tools,对旧版 Messages 搜索则发往配置的 Messages 端点(默认是官方端点),除非该端点接受这个密钥,否则每次搜索都会失败。Search 与 Fetch API 通过模型提供方目录读取 DeepSeek 模型路由的 Loader 条目。

单元测试分别固定每个角色:web.spec.ts 覆盖 searchReady() 与 fetchReady() 询问哪个提供方以及选择失败时的回答,deepseek.spec.ts 与 credential-resolution.spec.ts 覆盖 ready() 在账号路由与其他路由上的每种凭据情况,包括就绪判断与每次操作一致,tool-web.spec.ts 通过真实的提示词、工具与根注册表服务准备提供或撤下这两个工具的模型步骤,包括在撤下该工具的步骤中调用它时以 UNKNOWN_TOOL 拒绝。在真实组合中,发行版 headless 无密钥冒烟测试与 web-search-unconfigured 录制会话快照的搜索密钥引用都未设置,二者固定了搜索工具的撤下行为。快照回放提供占位 DeepSeek 密钥,因此其工具列表不依赖运行环境;借助该密钥,pi-ai-conversation-updates 中 pi-ai 路由上的对话保留 web_search。