Repository navigation
search: web_search + web_fetch tools with DDG/Brave/Tavily providers (Wave 1) - #80
Conversation
…(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 (&, <,
>, ", ', , —, –,
…), 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
There was a problem hiding this comment.
💡 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); |
There was a problem hiding this comment.
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 👍 / 👎.
picoclaw ships 9 web-search providers under a single
SearchProviderinterface and a model-callableweb_searchtool. PasClaw had none. Wave 1 ports the three lowest-friction providers (one no-key fallback + two API-key providers) plus a siblingweb_fetchtool 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/searchTypesISearchProvider,TSearchResult,TSearchResultArray. Flat shape — title + URL + snippet — because that's all the model actually reads.DuckDuckGohtml.duckduckgo.com/html/, unwraps the//duckduckgo.com/l/?uddg=redirector so the model gets real URLs.Braveapi.search.brave.com/res/v1/web/search,X-Subscription-Tokenheader. Parsesweb.results[].Tavilyapi.tavily.com/search, api_key in body. Purpose-built for LLM augmentation.HTMLTextHTMLToText(html, maxChars)— strips<script>/<style>/<!--…-->wholesale, drops other tags, decodes 9 common entities, collapses whitespace.FactoryNewSearchProvider(cfg) -> ISearchProvider. Empty/unknown falls back to DuckDuckGo with a warn. Env wins over cfg fields for API keys.New tools under
src/pkg/toolsConfig
Serialised only when non-default so existing
config.jsonfiles round-trip byte-identical; parser defaultsprovider=''(= DuckDuckGo) andmax_results=5. Env-var values win over the cfgapi_keyso secrets stay out ofconfig.json.{ "web_search": { "provider": "brave", "max_results": 5 } }Tool registration
RegisterWebSearchTool+RegisterWebFetchToolwired intoPasClaw.Cmd.Agent/Gateway/TUI/Serveand bothTPasClawAgent.EnsureToolsRegisteredpaths inPasClaw.Component— same five sitesRegisterMemoryToolslives in. Honours--no-tools.Build
MakefileUNIT_DIRSgainssrc/pkg/search.PasClaw.dprojDCC_UnitSearchPathadds..\pkg\search; 7 newDCCReferenceentries (6 search units + 2 tools).PASCLAW_BRAVE_API_KEY+PASCLAW_TAVILY_API_KEY; new "### Web search" section under Configuration with the provider table; repo-layoutsearch/row.Verification
make— clean build under FPC 3.2.2.HTMLToTextsmoke 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 statusoutput byte-identical.pasclaw --helpunchanged.Out of scope (intentional)
web_fetchweb_fetchhttps://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code