Skip to content

feat(search): graduate WebSearch tool + providers into engine/adapter (#363) - #366

Merged
JAORMX merged 1 commit into
mainfrom
feat/363-websearch-graduate
Aug 4, 2026
Merged

JAORMX merged 1 commit into
mainfrom
feat/363-websearch-graduate

Conversation

@JAORMX

@JAORMX JAORMX commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

What

Graduates the WebSearch tool body and its concrete provider adapters (Exa, generic HTTP / SearXNG / Brave) from the root module's internal/ into the importable engine module under engine/adapter/search/ — so engine importers get working web search out of the box instead of reimplementing it.

Closes #363.

Why

The engine module shipped the web-search port (tool.SearchProvider, SearchQuery, SearchResult, ErrSearchUnavailable/ErrSearchBackendDown) but no tool body and no concrete SearchProvider — both were locked in internal/. An engine consumer had to re-derive two things that have exactly one correct answer and fail silently when wrong:

  • the tool body's security invariants — LLM01 untrusted-result fencing, the ErrSearchUnavailable (operator-disabled) vs ErrSearchBackendDown (backend failed) degradation mapped to honest model-facing messages, and result-limit clamping;
  • the per-backend HTTP glue, auth, and response mapping.

This is the same failure mode #269 eliminated for the filesystem tools — same role, same place.

How (the #269 fstools precedent)

Piece From To Notes
Tool body internal/adapter/tools/websearch.go engine/adapter/search/websearch.go imports engine/agent for agent.FenceUntrusted; carries the small toolkit helpers locally (fstools carry pattern) so the engine module never imports the root module
Providers internal/adapter/search/{exasearch,httpsearch}.go engine/adapter/search/ verbatim; stdlib + x/sync/semaphore + engine/tool only
Offline fake — engine/adapter/search/fakesearch.go already there
Root alias — internal/adapter/tools/alias.go thin WebSearchTool/NewWebSearchTool re-export so existing callers compile unchanged
Old dir internal/adapter/search/ deleted internal/app now imports engine/adapter/search directly

engine/go.mod's require block does not grow — golang.org/x/sync was already a direct require (for engine/agent's errgroup); the providers only add the semaphore sub-package.

The one design decision

The tool body calls agent.FenceUntrusted (the single-source-of-truth LLM01 fence, engine/agent/fence.go). Graduating it forces a choice:

  • (A) copy ~560 lines of fence code — rejected: duplicates the most volatile security enumeration in the repo (framingHeaderSurfaces), with real drift risk, against AGENTS.md's "exactly one fence implementation".
  • (B) import engine/agent — chosen: smallest correct change, honours single-source-of-truth. The dep-cone cost is recorded in a NOTE on the widened engine-adapter-search depguard rule. This is the first engine/adapter package to import the agent loop.
  • (C) relocate the fence to engine/governance — the right long-term architecture, but a separable ~10-file refactor touching a guarded core package (api:check impact). Deferred to Relocate the untrusted-content fence primitives from engine/agent to engine/governance #380 rather than bundled into a "graduate websearch" PR.

Verification

  • task lint — green (0 issues, both modules)
  • task test — green (root + engine + test:engine-standalone GOWORK=off proof)
  • task api:check — green (unaffected; engine/adapter/search is excluded from the guarded surface)
  • go run ./cmd/mecademo — green offline smoke

Panel review (spec / standards / secure-code / architecture / duplication / library-reuse) ran clean; the two findings (a stale internal/adapter location comment, a test-adequacy gap on framing-header redaction through the tool) are fixed in this PR.

Follow-up (not in this PR)

#380 — relocate the fence primitives (FenceUntrusted/NeutraliseFraming) from engine/agent to engine/governance to shrink the engine/adapter/search dep cone.

…#363)

The engine module shipped the web-search PORT (tool.SearchProvider and its
sentinels) but no tool body and no concrete provider — both lived in the root
module's internal/, unimportable. Engine consumers had to reimplement the
correctness- and security-critical logic (LLM01 fencing, the
ErrSearchUnavailable-vs-ErrSearchBackendDown degradation, result clamping) and
re-derive the per-backend HTTP glue (Exa / generic HTTP / SearXNG / Brave).

Graduate both halves into engine/adapter/search/, following the #269 fstools
precedent:

- websearch.go (tool body) — imports engine/agent for agent.FenceUntrusted
  (the single-source-of-truth untrusted-content fence) and carries the small
  toolkit helpers locally (fstools carry pattern), so the engine module never
  imports the root module.
- exasearch.go + httpsearch.go (providers) — verbatim; stdlib +
  x/sync/semaphore + engine/tool only, so engine/go.mod's require block does
  not grow.
- internal/adapter/tools keeps a thin WebSearchTool/NewWebSearchTool alias so
  existing callers compile unchanged; internal/adapter/search/ is deleted and
  internal/app now imports engine/adapter/search directly.

The depguard engine-adapter-search rule is widened (engine/agent +
engine/session + x/sync/semaphore) with a NOTE recording the accepted dep-cone
cost of importing the agent loop for the fence, and a follow-up to relocate the
fence primitives to engine/governance. Docs citations, engine/CHANGELOG, and
engine/COMPATIBILITY updated; a framing-header whole-line-prevention assertion
added to the adversarial injection test.

Co-Authored-By: Juan Antonio Osorio <[email protected]>
@JAORMX
JAORMX merged commit f67fcb1 into main Aug 4, 2026
14 checks passed
@JAORMX
JAORMX deleted the feat/363-websearch-graduate branch August 4, 2026 21:55
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.

Graduate the WebSearch tool and its provider adapters into engine/adapter so engine importers don't reimplement them

1 participant