Skip to content

Web Access

pawaca edited this page Aug 30, 2026 · 1 revision

Web Access

Edge adaptation of the upstream web search and fetch capability.

What Upstream Provides

The web access subsystem gives the model two tools for retrieving information from the internet:

  • web_search — sends search queries to a configured provider, returns an answer snippet + ranked source URLs. Multi-query support (up to 5 concurrent queries per tool call).
  • web_fetch — retrieves the full content of a URL, converts HTML to model-readable text, truncates to a configurable character limit. Handles redirects, blocked URLs, and content-type detection.

Three packages compose the capability:

  • WebRuntime (ctx.web) — capability seam with provider registries for both search and fetch. Provider selection, cancellation, and error handling.
  • DeepSeekWebSearch — search provider calling the DeepSeek search API (Anthropic-compatible endpoint).
  • ToolWeb — registers the model-facing tools. Configurable: { search: boolean, fetch: boolean } controls which tools are exposed.

What Edge Changed

Direct Reuse Web search

installEdgeWebSearch() installs all three packages with { search: true, fetch: false }:

  • WebRuntime — search provider set to DeepSeek
  • DeepSeekWebSearch — configurable base URL via DEEPSEEK_SEARCH_BASE_URL env var
  • ToolCallTimeoutPolicy — enforces per-call timeouts
  • ToolWebweb_search tool registered, web_fetch tool not registered

The model sees web_search in its tool list and can search the web. The system prompt adjusts accordingly — without web_fetch, the model is told to use source snippets directly rather than following up with a fetch.

Not implemented: web_fetch

web_fetch is disabled via config (fetch: false). The upstream fetch capability requires:

  • An HTTP client that can follow redirects and handle various content types
  • HTML-to-text conversion (upstream has a built-in HTML parser + markdown renderer)
  • URL validation and blocking (prevent SSRF, local network access)

Workers' built-in fetch() API can make HTTP requests, and upstream's HTML-to-text conversion runs in pure JS — no Node.js dependency. The technical blockers are policy, not platform:

  • SSRF risk: Workers' fetch() can reach internal Cloudflare services and potentially other Workers. Upstream's URL validator may need Edge-specific additions.
  • Egress cost: fetched pages count against Workers' subrequest limits and bandwidth.
  • Content rendering: complex pages (SPAs, JS-rendered content) need a browser engine, not just HTTP fetch.

What Edge Did NOT Change

  • WebRuntime capability seam (provider selection, cancellation, error handling)
  • DeepSeek search provider implementation
  • web_search tool schema, multi-query support, source formatting
  • ToolCallTimeoutPolicy enforcement

Performance Characteristics

Search latency

Each web_search call makes an HTTP request to the DeepSeek search API. Latency is dominated by the external API response time (typically 500ms–2s). Multiple queries within one tool call run concurrently (up to 5). The timeout policy enforces an upper bound.

No fetch overhead

Since web_fetch is disabled, there is zero overhead from page fetching. The model works with search result snippets only.

Cloudflare Enablers for Fetch

Approach Capability Plan Complexity
Workers fetch() Basic HTTP: HTML pages, JSON APIs, text files Free Low — enable fetch: true, add SSRF guards
Browser Rendering API Full page rendering: SPAs, JS-heavy sites, screenshots Workers Paid Medium — need fetch provider wrapping the Rendering API

The simplest path is enabling Workers fetch() with SSRF protection — upstream's HTML parser is pure JS and already works in the Worker runtime. Browser Rendering adds full-page capability but requires a paid plan and a custom fetch provider.

Architecture Summary

Component Category Edge Code
WebRuntime Reuse One ctx.plugin() call
DeepSeekWebSearch Reuse One ctx.plugin() call
ToolWeb (search only) Reuse { search: true, fetch: false }
web_fetch ⚠️ Disabled Config flag — no code removed

Key observation: Web search is fully upstream code — zero Edge adaptation beyond the config flag. Enabling web_fetch is a config change + SSRF policy decision, not a platform limitation.

TODO

Enable web_fetch with SSRF guards. Upstream's HTML-to-text converter is pure JS and works in Workers. The main work is adding URL validation rules to prevent local-network and internal-service access. Change { search: true, fetch: false } to { search: true, fetch: true } and register a fetch provider backed by Workers fetch(). Available on free plan.

Evaluate Browser Rendering for rich page content. For JS-rendered pages that Workers fetch() can't handle, Cloudflare's Browser Rendering API provides a headless Chromium. Requires Workers Paid plan. Would need a custom WebFetchProvider that renders the page and extracts text.

English

中文

Clone this wiki locally