feat(plugins): add pluggable WebSearchTool with DuckDuckGo and Brave …#1514
Open
Alkamal01 wants to merge 1 commit intomofa-org:mainfrom
Open
feat(plugins): add pluggable WebSearchTool with DuckDuckGo and Brave …#1514Alkamal01 wants to merge 1 commit intomofa-org:mainfrom
Alkamal01 wants to merge 1 commit intomofa-org:mainfrom
Conversation
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.
📋 Summary
This PR implements a robust, pluggable
WebSearchToolwith support for multiple search providers (DuckDuckGo and Brave). It replaces the deprecated and non-compliantduck_searchimplementation, which relied on fragile HTML scraping and violated DuckDuckGo's Terms of Service.🔗 Related Issues
Closes #1446
🧠 Context
The previous
duck_search.rsimplementation was entirely commented-out dead code. It attempted to scrapeduckduckgo.com/html/directly, which is forbidden by their ToS and highly fragile.This PR introduces a vendor-neutral
SearchProvidertrait that allows MoFA to support multiple search backends while adhering to professional engineering standards and provider policies.🛠️ Changes
mofa-plugins
Implemented the
SearchProvidertrait and concrete providers:DuckDuckGoProviderBraveSearchProviderAdded
WebSearchToolas aToolExecutorRegistered the tool in the built-in tool plugin
mofa-foundation
WebSearchToolas aSimpleTooladapter for high-level agent interactionmofa-extra / mofa-sdk
cargo fmt) to ensure CI compliance🧪 How You Tested
1. Unit Tests (Mocks)
Added deterministic tests using a
MockSearchProviderto verify provider selection logic and error handling.2. Integration Tests (Manual)
Added ignored tests that perform real network calls to live APIs.
3. Linting
Verified that the workspace is clippy-clean and properly formatted.
📸 Screenshots / Logs (if applicable)
Mock Test Execution
🧹 Checklist
Code Quality
cargo fmtruncargo clippypasses without warningsTesting
cargo testpasses locally without any errorDocumentation
PR Hygiene
🚀 Deployment Notes
To use the Brave Search provider, the
BRAVE_SEARCH_API_KEYmust be set in the deployment environment.Otherwise, the tool will automatically fall back to DuckDuckGo.
🧩 Additional Notes for Reviewers
The
DuckDuckGoProvideruses the official public "Instant Answer" API, which is compliant with their Terms of Service and does not require an API key. This makes the tool immediately usable out-of-the-box.