Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CrewAIInc CrewAI Tavily Search Tool

From Leeroopedia
Revision as of 11:09, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/CrewAIInc_CrewAI_Tavily_Search_Tool.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Tools, Web_Search
Last Updated 2026-02-11 00:00 GMT

Overview

TavilySearchTool performs web searches using the Tavily Search API, returning structured JSON results with configurable search parameters and content truncation to prevent context window overflow.

Description

The TavilySearchTool extends BaseTool and initializes both synchronous and asynchronous Tavily clients from the tavily-python library. It exposes numerous configurable fields: search_depth (basic/advanced), topic (general/news/finance), time_range (day/week/month/year), days, max_results (default 5), domain inclusion/exclusion lists, include_answer, include_raw_content, include_images, and timeout. The _run and _arun methods accept a query string, perform the search, and truncate each result's content field to max_content_length_per_result (default 1000 characters) to avoid LLM context window issues. Results are returned as formatted JSON. If tavily-python is not installed, the constructor interactively prompts for installation.

Usage

Use this tool when a CrewAI agent needs to retrieve real-time web search results with fine-grained control over search depth, topic focus, time range, and domain filtering.

Code Reference

Source Location

  • Repository: CrewAI
  • File: lib/crewai-tools/src/crewai_tools/tools/tavily_search_tool/tavily_search_tool.py
  • Lines: 1-256

Signature

class TavilySearchToolSchema(BaseModel):
    query: str = Field(..., description="The search query string.")

class TavilySearchTool(BaseTool):
    name: str = "Tavily Search"
    description: str = "A tool that performs web searches using the Tavily Search API. ..."
    args_schema: type[BaseModel] = TavilySearchToolSchema
    api_key: str | None = Field(default_factory=lambda: os.getenv("TAVILY_API_KEY"))
    search_depth: Literal["basic", "advanced"] = "basic"
    topic: Literal["general", "news", "finance"] = "general"
    time_range: Literal["day", "week", "month", "year"] | None = None
    days: int = 7
    max_results: int = 5
    include_domains: Sequence[str] | None = None
    exclude_domains: Sequence[str] | None = None
    include_answer: bool | Literal["basic", "advanced"] = False
    include_raw_content: bool = False
    include_images: bool = False
    timeout: int = 60
    max_content_length_per_result: int = 1000
    env_vars: list[EnvVar]  # TAVILY_API_KEY

    def _run(self, query: str) -> str:
        ...
    async def _arun(self, query: str) -> str:
        ...

Import

from crewai_tools import TavilySearchTool

I/O Contract

Inputs

Name Type Required Description
query str Yes The search query string

Outputs

Name Type Description
_run() returns str JSON string containing search results with truncated content fields

Usage Examples

Basic Usage

from crewai_tools import TavilySearchTool

tool = TavilySearchTool(max_results=5, search_depth="basic")
result = tool._run(query="latest AI developments")

Advanced Configuration

from crewai_tools import TavilySearchTool

tool = TavilySearchTool(
    search_depth="advanced",
    topic="news",
    time_range="week",
    max_results=10,
    include_answer=True,
    include_domains=["arxiv.org", "nature.com"],
)
result = tool._run(query="transformer architecture research")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment