Repository navigation
feat(search): graduate WebSearch tool + providers into engine/adapter (#363) - #366
Merged
Merged
Conversation
…#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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 underengine/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 concreteSearchProvider— both were locked ininternal/. An engine consumer had to re-derive two things that have exactly one correct answer and fail silently when wrong:ErrSearchUnavailable(operator-disabled) vsErrSearchBackendDown(backend failed) degradation mapped to honest model-facing messages, and result-limit clamping;This is the same failure mode #269 eliminated for the filesystem tools — same role, same place.
How (the #269 fstools precedent)
internal/adapter/tools/websearch.goengine/adapter/search/websearch.goengine/agentforagent.FenceUntrusted; carries the small toolkit helpers locally (fstools carry pattern) so the engine module never imports the root moduleinternal/adapter/search/{exasearch,httpsearch}.goengine/adapter/search/x/sync/semaphore+engine/toolonlyengine/adapter/search/fakesearch.gointernal/adapter/tools/alias.goWebSearchTool/NewWebSearchToolre-export so existing callers compile unchangedinternal/adapter/search/internal/appnow importsengine/adapter/searchdirectlyengine/go.mod's require block does not grow —golang.org/x/syncwas already a direct require (forengine/agent's errgroup); the providers only add thesemaphoresub-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:framingHeaderSurfaces), with real drift risk, against AGENTS.md's "exactly one fence implementation".engine/agent— chosen: smallest correct change, honours single-source-of-truth. The dep-cone cost is recorded in a NOTE on the widenedengine-adapter-searchdepguard rule. This is the firstengine/adapterpackage to import the agent loop.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-standaloneGOWORK=off proof)task api:check— green (unaffected;engine/adapter/searchis excluded from the guarded surface)go run ./cmd/mecademo— green offline smokePanel review (spec / standards / secure-code / architecture / duplication / library-reuse) ran clean; the two findings (a stale
internal/adapterlocation 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) fromengine/agenttoengine/governanceto shrink theengine/adapter/searchdep cone.