Skip to content

feat(tools): add SearchApi tool with multi-engine support#6434

Open
axiom-of-choice wants to merge 3 commits into
crewAIInc:mainfrom
axiom-of-choice:feat/searchapi-tool
Open

feat(tools): add SearchApi tool with multi-engine support#6434
axiom-of-choice wants to merge 3 commits into
crewAIInc:mainfrom
axiom-of-choice:feat/searchapi-tool

Conversation

@axiom-of-choice

Copy link
Copy Markdown

Summary

Adds SearchApiSearchTool — a single tool class that supports 7 search engines (google, google_news, google_shopping, google_jobs, youtube, bing, baidu) via SearchApi.io's unified SERP API.

Design

One configurable tool instead of one class per engine. Users pick the engine at init time:

from crewai_tools import SearchApiSearchTool

google = SearchApiSearchTool()  # default: google
news = SearchApiSearchTool(engine="google_news")
shopping = SearchApiSearchTool(engine="google_shopping")
youtube = SearchApiSearchTool(engine="youtube")

Location can be passed per-query at runtime for maximum flexibility.

Why a single tool class?

SearchApi's differentiator is one endpoint for 100+ engines — the tool design should reflect that. Separate classes per engine would mean adding a new file every time you want to support a new engine. With this design, adding a new engine is one line in SUPPORTED_ENGINES.

Relation to #6378

I'm aware of the existing PR. This takes a different architectural approach (single configurable class vs. separate per-engine classes) and adds:

  • 7 engines vs 2
  • Runtime location parameter in the schema (agents can pass location per-query)
  • country, language, and n_results configuration
  • Comprehensive test suite (19 tests across 4 categories)
  • API key stored as PrivateAttr to prevent serialization leaks
  • Passes ruff, mypy, and the 80% docstring coverage threshold

Test results

19 passed in 11.06s

Tests cover:

  • Initialization (defaults, custom params, all engines, invalid engine, missing key, serialization safety)
  • Search execution (google, google_news, google_shopping, youtube)
  • Request construction (params, location, country/language, absence of optional params)
  • Error handling (timeout, connection error, HTTP error, missing query)

Checklist

  • Follows conventional commit format
  • Branch named feat/searchapi-tool
  • ruff check passes
  • ruff format passes
  • mypy passes with no issues
  • All 19 tests pass
  • Type annotations on all functions
  • Google-style docstrings
  • tool.specs.json updated
  • Package exports in both __init__.py files
  • README with usage examples

Add SearchApiSearchTool supporting 7 search engines (google, google_news,
google_shopping, google_jobs, youtube, bing, baidu) through a single
configurable tool class.

Key design decisions:
- Single tool with engine parameter vs separate classes per engine
- Bearer token auth with PrivateAttr to prevent key serialization leaks
- Per-query location parameter for runtime flexibility
- Comprehensive test suite (19 tests) covering initialization, request
  construction, multi-engine execution, and error handling
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d8f62445-fd74-4dfb-b724-78d857b6d7c4

📥 Commits

Reviewing files that changed from the base of the PR and between 42a6dc8 and 261481d.

📒 Files selected for processing (3)
  • lib/crewai-tools/src/crewai_tools/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/searchapi_tool/README.md
  • lib/crewai-tools/src/crewai_tools/tools/searchapi_tool/searchapi_search_tool.py
✅ Files skipped from review due to trivial changes (1)
  • lib/crewai-tools/src/crewai_tools/tools/searchapi_tool/README.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/crewai-tools/src/crewai_tools/init.py
  • lib/crewai-tools/src/crewai_tools/tools/searchapi_tool/searchapi_search_tool.py

📝 Walkthrough

Walkthrough

Adds a new SearchApiSearchTool CrewAI tool, wires it into package exports, and documents, specifies, and tests its SearchApi-backed search flow.

Changes

SearchApi Search Tool

Layer / File(s) Summary
SearchApiSearchTool implementation
lib/crewai-tools/src/crewai_tools/tools/searchapi_tool/searchapi_search_tool.py
Defines the input schema, tool configuration, engine/API-key validation, and _run logic that builds requests, calls SearchApi, strips metadata, and returns errors as strings.
Package export wiring
lib/crewai-tools/src/crewai_tools/tools/__init__.py, lib/crewai-tools/src/crewai_tools/__init__.py
Imports SearchApiSearchTool into the tools package and top-level package, and adds it to __all__.
Documentation and tool spec
lib/crewai-tools/src/crewai_tools/tools/searchapi_tool/README.md, lib/crewai-tools/tool.specs.json
Adds README usage docs and a tool spec entry for configuration, runtime inputs, dependencies, and metadata.
Unit tests for SearchApiSearchTool
lib/crewai-tools/tests/tools/searchapi_tool_test.py
Adds tests for initialization, execution, request construction, error handling, validation, and a direct pytest entrypoint.

Suggested reviewers: lorenzejay, greysonlalonde

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a SearchApi tool with support for multiple engines.
Description check ✅ Passed The description is clearly related to the changeset and matches the new SearchApiSearchTool, engine support, exports, docs, and tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@axiom-of-choice

axiom-of-choice commented Jul 2, 2026

Copy link
Copy Markdown
Author

Per CONTRIBUTING.md: this PR was authored with AI assistance. Please apply the llm-generated label .

I don't have permission to add labels as an external contributor.

@axiom-of-choice

axiom-of-choice commented Jul 2, 2026

Copy link
Copy Markdown
Author

Live API Evidence

Tested against SearchApi.io with real API key across 4 engines:

Google Search

{
  "organic_results": [
    {
      "position": 1,
      "title": "CrewAI",
      "link": "https://crewai.com/",
      "snippet": "Build. Deploy. Manage. Enterprise Agents..."
    }
  ]
}

Google News

{
  "organic_results": [
    {
      "position": 1,
      "title": "Latin America and the Caribbean Consolidate a Regional Roadmap for...",
      "source": "UNESCO",
      "date": "4 hours ago"
    }
  ]
}

Google Shopping

{
  "shopping_results": [
    {
      "title": "Keychron Q1 HE...",
      "price": "$219.00",
      "source": "Keychron"
    }
  ]
}

YouTube

{
  "videos": [
    {
      "position": 1,
      "title": "Python Full Course for Beginners",
      "link": "https://www.youtube.com/watch?v=K5KVEU3aaeQ",
      "views": 6769124,
      "channel": {"title": "Programming with Mosh"}
    }
  ]
}

All 4 engines return structured, clean results. Metadata fields (search_metadata, search_parameters, pagination) are stripped as expected.

Unit tests: 19/19 passing (ruff, mypy, pytest all green).

Test evidence:
image

Working evidence:
image

@axiom-of-choice

axiom-of-choice commented Jul 2, 2026

Copy link
Copy Markdown
Author

Hey @lorenzejay @vinibrsl — would appreciate a review when you get a chance. This is an alternative approach to #6378 with multi-engine support (7 engines via a single class) and comprehensive tests. Happy to adjust anything.

Feel free to also tag another maintainer to review and untag yourself

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/crewai-tools/src/crewai_tools/__init__.py`:
- Around line 163-165: `SearchApiSearchTool` is imported in
`crewai_tools/__init__.py` but not exposed in the module’s `__all__`, so update
the `__all__` list in that same file to include `SearchApiSearchTool` in the
existing alphabetical order. Keep the import and public export definitions
aligned with `tools/__init__.py` so `from crewai_tools import *` and
`__all__`-based tooling include this symbol.

In `@lib/crewai-tools/src/crewai_tools/tools/searchapi_tool/README.md`:
- Around line 13-14: The README tables under the Supported Engines and other
headings are missing the required blank line before the table, triggering MD058.
Update the markdown in this README so each table is separated from its preceding
heading by a single empty line, keeping the table content unchanged. Use the
nearby heading/table pairs in the SearchAPI tool README to locate and fix all
affected spots, including the other referenced table sections.

In
`@lib/crewai-tools/src/crewai_tools/tools/searchapi_tool/searchapi_search_tool.py`:
- Around line 66-86: The engine check in SearchApiTool is only happening inside
__init__, so assignment-time validation is bypassed even though
validate_assignment=True is enabled. Move the engine membership check into a
field_validator for the engine field in SearchApiTool so it runs on both
construction and later assignments, and keep the same ValueError text for
compatibility with existing tests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d2887d4f-2e7b-484c-af9e-34675125387c

📥 Commits

Reviewing files that changed from the base of the PR and between 559a9c6 and 42a6dc8.

📒 Files selected for processing (7)
  • lib/crewai-tools/src/crewai_tools/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/searchapi_tool/README.md
  • lib/crewai-tools/src/crewai_tools/tools/searchapi_tool/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/searchapi_tool/searchapi_search_tool.py
  • lib/crewai-tools/tests/tools/searchapi_tool_test.py
  • lib/crewai-tools/tool.specs.json

Comment thread lib/crewai-tools/src/crewai_tools/__init__.py
Comment thread lib/crewai-tools/src/crewai_tools/tools/searchapi_tool/README.md
- Add SearchApiSearchTool to __all__ in crewai_tools/__init__.py
- Fix MD058: add blank lines before tables in README
- Move engine validation to field_validator for assignment-time checks
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.

1 participant