Skip to content

search: web_search + web_fetch tools with DDG/Brave/Tavily providers (Wave 1) - #80

Merged
FMXExpress merged 1 commit into
mainfrom
claude/web-search-wave1
May 30, 2026
Merged

FMXExpress merged 1 commit into
mainfrom
claude/web-search-wave1

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

picoclaw ships 9 web-search providers under a single SearchProvider interface and a model-callable web_search tool. PasClaw had none. Wave 1 ports the three lowest-friction providers (one no-key fallback + two API-key providers) plus a sibling web_fetch tool for reading a specific page after a search returns interesting URLs. The remaining providers plug into the same factory; queued for Wave 2 / Wave 3.

New unit tree under src/pkg/search

Unit What it does
Types ISearchProvider, TSearchResult, TSearchResultArray. Flat shape — title + URL + snippet — because that's all the model actually reads.
DuckDuckGo Zero-config fallback. Scrapes html.duckduckgo.com/html/, unwraps the //duckduckgo.com/l/?uddg= redirector so the model gets real URLs.
Brave GET api.search.brave.com/res/v1/web/search, X-Subscription-Token header. Parses web.results[].
Tavily POST api.tavily.com/search, api_key in body. Purpose-built for LLM augmentation.
HTMLText HTMLToText(html, maxChars) — strips <script>/<style>/<!--…--> wholesale, drops other tags, decodes 9 common entities, collapses whitespace.
Factory NewSearchProvider(cfg) -> ISearchProvider. Empty/unknown falls back to DuckDuckGo with a warn. Env wins over cfg fields for API keys.

New tools under src/pkg/tools

// web_search
{ "query": "string (required)", "k": "1..25 (default 5)" }
// → numbered title/url/snippet blocks; "(no hits)" on empty
//   list; clear "set $PASCLAW_<KIND>_API_KEY" errors when a
//   keyed provider is configured without one.

// web_fetch
{ "url": "http:// or https://", "max_chars": "100..200000 (default 50000)" }
// → readable plain text via HTMLToText for text/html, raw +
//   truncation for other text/*, refused for binary types.
//   Refuses non-http/https schemes so the model can't reach
//   file:// or ftp:// via this path.

Config

TWebSearchConfig = record
  Provider:   string;   // 'duckduckgo' (default) | 'brave' | 'tavily'
  APIKey:     string;
  MaxResults: Integer;  // default 5
end;

Serialised only when non-default so existing config.json files round-trip byte-identical; parser defaults provider='' (= DuckDuckGo) and max_results=5. Env-var values win over the cfg api_key so secrets stay out of config.json.

{ "web_search": { "provider": "brave", "max_results": 5 } }

Tool registration

RegisterWebSearchTool + RegisterWebFetchTool wired into PasClaw.Cmd.Agent / Gateway / TUI / Serve and both TPasClawAgent.EnsureToolsRegistered paths in PasClaw.Component — same five sites RegisterMemoryTools lives in. Honours --no-tools.

Build

  • Makefile UNIT_DIRS gains src/pkg/search.
  • PasClaw.dproj DCC_UnitSearchPath adds ..\pkg\search; 7 new DCCReference entries (6 search units + 2 tools).
  • README: env-var table picks up PASCLAW_BRAVE_API_KEY + PASCLAW_TAVILY_API_KEY; new "### Web search" section under Configuration with the provider table; repo-layout search/ row.

Verification

  • make — clean build under FPC 3.2.2.
  • HTMLToText smoke test — 13 assertions, all pass: basic tag strip, entity decode, script+style+comment stripping, whitespace collapse, truncation, empty/whitespace-only input, realistic page fragment.
  • pasclaw status output byte-identical.
  • pasclaw --help unchanged.

Out of scope (intentional)

Item Why deferred
Wave 2: SearXNG, Perplexity Same factory + tool surface; ~250 LOC each.
Wave 3: Gemini Google Search, GLM (Zhipu), Baidu LLM-provider-tied or Chinese-ecosystem auth — heavier port.
SSRF protection in web_fetch Today's threat model is "the user is the operator". Picoclaw blocks RFC1918/loopback/link-local; PasClaw will when someone deploys a public-facing agent. Called out in the unit's docstring.
Markdown conversion in web_fetch The stripped-text output is enough for the model to read.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon


Generated by Claude Code

…(Wave 1)

picoclaw ships 9 web-search providers under a single SearchProvider
interface and a model-callable web_search tool. PasClaw had none.
Wave 1 ports the three lowest-friction providers (one no-key
fallback + two API-key providers) plus a sibling web_fetch tool
for reading a specific page after the search returns interesting
URLs. The remaining picoclaw providers (SearXNG, Perplexity,
Gemini-google_search, GLM, Baidu, Sogou) plug into the same
factory; queued for Wave 2 / Wave 3.

New unit tree under src/pkg/search:

  Types       ISearchProvider interface, TSearchResult record,
              TSearchResultArray. Flat shape — title + URL +
              snippet — because that's all the model actually
              reads. Provider-specific metadata (favicon, age,
              score) stays in the provider.

  DuckDuckGo  No key needed. Scrapes html.duckduckgo.com/html/
              for the result__a anchors and result__snippet
              divs, unwraps the //duckduckgo.com/l/?uddg=...
              redirector via percent-decode so the model gets
              real URLs. Picoclaw does the same scrape; this is
              the zero-config fallback.

  Brave       GET api.search.brave.com/res/v1/web/search with
              X-Subscription-Token header. Parses web.results[]
              for title/url/description. API key from
              $PASCLAW_BRAVE_API_KEY (env wins) or config.

  Tavily      POST api.tavily.com/search with the api_key in
              the JSON body. Tavily is purpose-built for LLM
              augmentation — pre-summarised content, short
              responses, easy parse. API key from
              $PASCLAW_TAVILY_API_KEY or config.

  HTMLText    HTMLToText(html, maxChars) — strips <script> +
              <style> + <!-- --> blocks wholesale, drops every
              other tag, decodes common entities (&amp;, &lt;,
              &gt;, &quot;, &#39;, &nbsp;, &mdash;, &ndash;,
              &hellip;), collapses whitespace runs, normalises
              line breaks. Used by web_fetch; small enough to
              also live in the search package without dragging
              in a real HTML parser.

  Factory     NewSearchProvider(cfg) -> ISearchProvider. Picks
              the impl based on cfg.WebSearch.Provider; empty /
              unknown falls back to DuckDuckGo with a warn so a
              typo'd provider name doesn't silently break the
              tool. Env wins over cfg fields for the API keys.

New tools under src/pkg/tools:

  WebSearch   Schema { query: string (required), k: 1..25 }.
              Dispatches to NewSearchProvider, formats hits as
              numbered title/url/snippet blocks, surfaces
              clear "set $PASCLAW_<KIND>_API_KEY" errors when a
              keyed provider is configured without one. Empty
              result list returns "(no hits for ... via ...)" so
              the model doesn't mistake silence for "tool broke".

  WebFetch    Schema { url: string (required), max_chars: 100..200000 }.
              GET via TIdHTTP, redirects capped at 5, default
              30s read timeout. SSL via TIdSSLIOHandlerSocketOpenSSL
              for https://. text/html and application/xhtml+xml
              responses go through HTMLToText; text/* through
              raw + truncation; other content-types refused.
              Refuses non-http/https schemes so a misbehaving
              model can't reach file:// or ftp:// via this path.

Config: TWebSearchConfig record (provider, api_key, max_results)
under TConfig.WebSearch. Serialised only when non-default so
existing config.json round-trips byte-identical. Parser defaults
provider='' (DuckDuckGo fallback), max_results=5.

Tool registration: RegisterWebSearchTool + RegisterWebFetchTool
wired into PasClaw.Cmd.Agent / Gateway / TUI / Serve and both
TPasClawAgent.EnsureToolsRegistered paths in PasClaw.Component
— same five sites RegisterMemoryTools landed in. Honours
--no-tools (no registry → no web tools).

Build: Makefile UNIT_DIRS gains src/pkg/search; PasClaw.dproj
adds DCC_UnitSearchPath entry plus DCCReference for each new
unit (5 search + 2 tools = 7 entries).

README: env-var table picks up PASCLAW_BRAVE_API_KEY +
PASCLAW_TAVILY_API_KEY; new "### Web search" section under
Configuration explains the two tools, the provider table, and
the env-wins-over-config rule; tool-view "Known tools" line
adds memory_search/web_search/web_fetch; repository layout
gets a search/ row.

Verified locally:
  make builds clean under FPC 3.2.2.
  HTMLToText smoke test — 13 assertions (basic tag strip,
  entity decode, script+style+comment stripping, whitespace
  collapse, truncation, empty/whitespace-only input, realistic
  page fragment). All pass.
  pasclaw status output byte-identical to pre-change.

Deferred to Wave 2/3:
  Wave 2: SearXNG (self-hosted, no key), Perplexity (similar
          shape to Tavily — JSON body, Bearer auth).
  Wave 3: Gemini Google Search (LLM-provider-tied), GLM
          (Zhipu), Baidu (Qianfan). All three involve
          Chinese-ecosystem auth or LLM-provider coupling
          that's heavier than the API-key dance the Wave 1
          providers use.

Also out of scope (intentional, called out in web_fetch
docstring):
  SSRF protection (block RFC1918 / loopback / link-local) —
  picoclaw does this; PasClaw will when someone deploys a
  public-facing agent. Today's threat model is "the user
  is the operator".
  Markdown conversion. The stripped-text output is enough
  for the model to read.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
@FMXExpress
FMXExpress merged commit e692317 into main May 30, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f9950defb5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

HTTP.ReadTimeout := 15000;
Body := 'q=' + UrlEncode(Query) + '&kl=us-en';
try
HTML := HTTP.Post('https://html.duckduckgo.com/html/', Body);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Assign an SSL IOHandler before the DuckDuckGo POST

With the default/empty web_search provider this path always posts to an HTTPS endpoint, but the TIdHTTP instance never gets a TIdSSLIOHandlerSocketOpenSSL assigned. In Indy, HTTPS requests need an SSL IOHandler (as the existing provider HTTP helper and the new web_fetch HTTPS branch do), so the zero-config DuckDuckGo fallback fails at runtime before returning any search results.

Useful? React with 👍 / 👎.

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.

2 participants