crewAI Tools

repository·main·Indexed 23 days ago

https://github.com/crewaiinc/crewai-tools

A library of tools designed to extend crewAI agents with capabilities such as file management, web scraping, database access, and AI-powered tools. It includes native support for the Model Context Protocol (MCP) and specialized toolkits for AWS Bedrock (Browser, Code Interpreter, and Knowledge Base Retriever) and AWS S3 (S3ReaderTool and S3WriterTool).

Tokens
60K
Snippets
207
Records
284
Agent score
80%

What's inside crewai-tools

  1. Overview of BrightData Tools capabilities

    main

    The BrightData tool suite provides three main capabilities for CrewAI agents:

    1. BrightDataDatasetTool: Extracts structured data from popular data feeds (Amazon, LinkedIn, Instagram, etc.) using pre-built datasets.
    2. BrightDataSearchTool: Performs web searches across multiple search engines with geo-targeting and device simulation.
    3. BrightDataWebUnlockerTool: Scrapes website content while bypassing bot protection mechanisms.
  2. Use the FileCompressorTool to archive files and directories

    main

    The FileCompressorTool allows you to compress individual files or entire directories (including nested subdirectories) into various archive formats. It supports .zip, .tar, .tar.gz, .tar.bz2, and .tar.xz formats.

    Key features include:

    • Recursive compression: Automatically handles subdirectories.
    • Custom output paths: Define exactly where the archive should be saved.
    • Overwrite protection: A safety mechanism to prevent accidental data loss by checking the overwrite flag.
    from crewai_tools import FileCompressorTool
    
    tool = FileCompressorTool()
    
    # Example: Compress a directory into a zip archive
    result = tool._run(
        input_path="./data/project_docs",
        output_path="./output/project_docs.zip",
        overwrite=True
    )
    print(result)
  3. What is RagTool?

    main
    RagTool is a dynamic knowledge base tool designed for Retrieval-Augmented Generation (RAG). It leverages EmbedChain to allow CrewAI agents to answer questions by querying information retrieved from various data sources. It is highly versatile, supporting a wide range of inputs from local files and directories to web pages, YouTube content, and various SaaS platforms like Gmail, Slack, and GitHub.
  4. Configure SingleStoreSearchTool connection methods

    main

    The tool supports several ways to establish a connection to SingleStore:

    1. Standard Parameters: Pass host, user, password, database, and port individually.
    2. Connection URL: Pass a complete connection string to the host parameter (e.g., user:password@host:port/database).
    3. Environment Variables: Set SINGLESTOREDB_URL in your environment and initialize the tool without arguments.
    4. SSL/TLS: Provide paths to ssl_ca, ssl_cert, and ssl_key for secure connections.
    # Connection URL method
    tool = SingleStoreSearchTool(host='user:password@localhost:3306/database_name')
    
    # Environment Variable method (requires export SINGLESTOREDB_URL=...)
    tool = SingleStoreSearchTool()
    
    # SSL method
    tool = SingleStoreSearchTool(
        host='your_host',
        user='your_username',
        password='your_password',
        database='your_database',
        ssl_ca='/path/to/ca-cert.pem',
        ssl_cert='/path/to/client-cert.pem',
        ssl_key='/path/to/client-key.pem'
    )
  5. Understand SerperDevTool response format

    main

    The SerperDevTool returns structured data depending on the search_type used. The response includes:

    • General Search (search_type="search"): Search parameters, knowledge graph data, organic search results (with sitelinks), "People Also Ask" questions, and related searches.
    • News Search (search_type="news"): Search parameters and news results containing date, source, and image information.
  6. How StagehandTool works with CrewAI

    main

    The StagehandTool integrates the Stagehand framework into CrewAI, allowing agents to interact with websites using natural language. It operates via three core primitives:

    1. Act: Performs actions like clicking, typing, or navigating.
    2. Extract: Retrieves structured data from web pages.
    3. Observe: Identifies and analyzes elements on the page.

    It is highly recommended to use the tool within a context manager to ensure that browser resources are automatically cleaned up when the agent finishes its task.

    from crewai import Agent, Task, Crew
    from crewai_tools import StagehandTool
    from stagehand.schemas import AvailableModel
    
    # Use a context manager for automatic resource cleanup
    with StagehandTool(
        api_key="your-browserbase-api-key",
        project_id="your-browserbase-project-id",
        model_api_key="your-llm-api-key",
        model_name=AvailableModel.CLAUDE_3_7_SONNET_LATEST,
    ) as stagehand_tool:
        researcher = Agent(
            role="Web Researcher",
            goal="Find and summarize information",
            tools=[stagehand_tool],
            ...
        )
        # ... define tasks and crew
        crew.kickoff()
  7. Handle overwrite protection in FileCompressorTool

    main

    To prevent unintentional data loss, the tool uses an overwrite boolean flag.

    • If overwrite=True: The tool will replace any existing file at the output_path.
    • If overwrite=False (default): If a file already exists at the output_path, the tool will stop and return an error message indicating the file exists.
    from crewai_tools import FileCompressorTool
    
    tool = FileCompressorTool()
    
    # This will fail if ./backups/my_data_backup.zip already exists
    result = tool._run(
        input_path="./my_data", 
        output_path="./backups/my_data_backup.zip", 
        overwrite=False
    )
    # Output: Output zip './backups/my_data_backup.zip' already exists and overwrite is set to False.
  8. Handle errors when using SnowflakeSearchTool

    main

    The tool automatically handles common Snowflake errors including DatabaseError, OperationalError, ProgrammingError, network timeouts, and connection issues. These errors are logged and retried based on your max_retries configuration.

    It is a best practice to wrap your tool._run calls in try-except blocks to manage failures in your application logic.

    import logging
    
    # Configure logging
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
    )
    logger = logging.getLogger(__name__)
    
    async def main():
        try:
            # ... tool initialization ...
            results = await tool._run(query="SELECT * FROM table LIMIT 10")
            logger.info(f"Query completed successfully. Retrieved {len(results)} rows")
        except Exception as e:
            logger.error(f"Query failed: {str(e)}")
            raise
  9. MCP Integration limitations and safety

    main

    When using the Model Context Protocol (MCP):

    • Security: Only use trusted MCP servers. STDIO servers execute code on your local machine, and SSE servers can still be vulnerable to injection attacks.
    • Supported Primitives: Currently, only tools from the MCP server are supported. Prompts and resources are not yet supported.
    • Output: Only the first text output from the MCP server tool is returned (via .content[0].text).
  10. Authenticate with Databricks

    main

    The DatabricksQueryTool requires authentication credentials. You can authenticate using one of two methods:

    1. Databricks CLI Profile: Set the DATABRICKS_CONFIG_PROFILE environment variable to your profile name.
    2. Direct Credentials: Set the DATABRICKS_HOST and DATABRICKS_TOKEN environment variables.

    Example using direct credentials:

    export DATABRICKS_HOST="https://your-workspace.cloud.databricks.com"
    export DATABRICKS_TOKEN="dapi1234567890abcdef"
  11. Use AWS Bedrock Browser Tools in a CrewAI Agent

    main

    You can integrate browser automation into your CrewAI agents by using create_browser_toolkit. This function returns both a toolkit object (used for resource management) and a list of browser_tools that can be assigned directly to an Agent.

    Important: Always call toolkit.sync_cleanup() when your process is finished to release browser resources.

    from crewai import Agent, Task, Crew, LLM
    from crewai_tools.aws.bedrock.browser import create_browser_toolkit
    
    # Create the browser toolkit
    toolkit, browser_tools = create_browser_toolkit(region="us-west-2")
    
    # Create the Bedrock LLM
    llm = LLM(
        model="bedrock/us.anthropic.claude-3-7-sonnet-20250219-v1:0",
        region_name="us-west-2",
    )
    
    # Create a CrewAI agent that uses the browser tools
    research_agent = Agent(
        role="Web Researcher",
        goal="Research and summarize web content",
        backstory="You're an expert at finding information online.",
        tools=browser_tools,
        llm=llm
    )
    
    # ... define tasks and crew ...
    result = crew.kickoff()
    
    # Clean up browser resources when done
    toolkit.sync_cleanup()