Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Bug: FirecrawlSearchTool Fails at Initialization #226

@bdobre

Description

@bdobre

Description

Initializing FirecrawlSearchTool fails due to an UnboundLocalError caused by local scoping of FirecrawlApp.

Steps to Reproduce

Run the following code:

import os
from dotenv import load_dotenv
from crewai_tools import FirecrawlSearchTool

load_dotenv()

api_key = os.getenv("FIRECRAWL_API_KEY")
tool = FirecrawlSearchTool(api_key=api_key)  # Fails here

Error message

Traceback (most recent call last):
File "/home/bdobre/dev/crewai_bugfix/firecrawl_search_tool_test.py", line 8, in
tool = FirecrawlSearchTool(api_key=api_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bdobre/miniconda3/envs/crewai_tools_firecrawl_issue/lib/python3.12/site-packages/crewai_tools/tools/firecrawl_search_tool/firecrawl_search_tool.py", line 55, in init
self._initialize_firecrawl()
File "/home/bdobre/miniconda3/envs/crewai_tools_firecrawl_issue/lib/python3.12/site-packages/crewai_tools/tools/firecrawl_search_tool/firecrawl_search_tool.py", line 60, in _initialize_firecrawl
self._firecrawl = FirecrawlApp(api_key=self.api_key)
^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'FirecrawlApp' where it is not associated with a value

Proposed fix

I think the issue is at line 73 in firecrawl_search_tool.py:
from firecrawl import FirecrawlApp
this makes FirecrawlApp local in scope, voiding the module level initialization when the firecrawl package is actually installed.

Replacing that with

from firecrawl import FirecrawlAppTemp
self.firecrawl = FirecrawlAppTemp(api_key=self.api_key)

fixes the issue.

Additional issues

  • Variable Inconsistency: _firecrawl and firecrawl should be unified in firecrawl_search_tool.py
  • Also, at line 106, self.firecrawl.search(**options) omits the query argument.

I can put a PR together with these few fixes if maintainers agree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions