-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Upgrade Firecrawl tools to firecrawl-py v2 SDK + add Firecrawl Interact tool #6051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rakshith48
wants to merge
7
commits into
crewAIInc:main
Choose a base branch
from
rakshith48:firecrawl-v2-upgrade
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e52fc62
Upgrade Firecrawl tools to firecrawl-py v2 SDK (v4)
rakshith48 753d994
docs: refresh Firecrawl tool docs for the v2 config API
rakshith48 77701b8
docs: refresh Firecrawl tool docs for the v2 config API
rakshith48 7d62599
docs: refresh Firecrawl tool docs for the v2 config API
rakshith48 490cb56
Add Firecrawl Interact tool (agentic browser) to the bundle
rakshith48 6569284
Merge branch 'main' into firecrawl-v2-upgrade
rakshith48 4750ab1
chore(firecrawl): pin runtime uv-add, add docstrings, tag README fence
rakshith48 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| --- | ||
| title: Firecrawl Interact | ||
| description: The `FirecrawlInteractTool` runs an autonomous Firecrawl browser agent that navigates and interacts with web pages to accomplish a task. | ||
| icon: fire-flame | ||
| mode: "wide" | ||
| --- | ||
|
|
||
| # `FirecrawlInteractTool` | ||
|
|
||
| ## Description | ||
|
|
||
| [Firecrawl](https://firecrawl.dev) is a platform for crawling and converting any website into clean markdown or structured data. The interact tool runs an autonomous browser **agent** that navigates and interacts with pages to accomplish a natural-language task, then returns the result. | ||
|
|
||
| ## Installation | ||
|
|
||
| - Get an API key from [firecrawl.dev](https://firecrawl.dev) and set it in environment variables (`FIRECRAWL_API_KEY`). | ||
| - Install the [Firecrawl SDK](https://github.com/firecrawl/firecrawl) along with `crewai[tools]` package: | ||
|
|
||
| ```shell | ||
| pip install firecrawl-py 'crewai[tools]' | ||
| ``` | ||
|
|
||
| ## Example | ||
|
|
||
| Utilize the FirecrawlInteractTool as follows to let your agent act on the web: | ||
|
|
||
| ```python Code | ||
| from crewai_tools import FirecrawlInteractTool | ||
|
|
||
| tool = FirecrawlInteractTool() | ||
| result = tool.run( | ||
| prompt="Go to news.ycombinator.com and return the titles of the top 3 stories", | ||
| ) | ||
| ``` | ||
|
|
||
| ## Arguments | ||
|
|
||
| - `prompt`: Required. A natural-language description of the task for the agent to carry out. | ||
| - `urls`: Optional. A list of URLs to start from or constrain the agent to. | ||
| - `config`: Optional. A dictionary of [Firecrawl v2 agent options](https://docs.firecrawl.dev/api-reference/endpoint/agent) passed directly to the SDK — for example `model` (`spark-1-mini` / `spark-1-pro`), `max_credits`, `strict_constrain_to_urls`, `poll_interval`, and `timeout`. | ||
| - `api_key`: Optional. Your Firecrawl API key. Defaults to the `FIRECRAWL_API_KEY` environment variable. |
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
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
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
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
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
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
44 changes: 44 additions & 0 deletions
44
lib/crewai-tools/src/crewai_tools/tools/firecrawl_interact_tool/README.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # FirecrawlInteractTool | ||
|
|
||
| ## Description | ||
|
|
||
| [Firecrawl](https://firecrawl.dev) is a platform for crawling and converting any website into clean markdown or structured data. This tool runs an autonomous browser **agent** that navigates and interacts with web pages to accomplish a natural-language task, then returns the result. | ||
|
|
||
| ## Installation | ||
|
|
||
| - Get an API key from [firecrawl.dev](https://firecrawl.dev) and set it in environment variables (`FIRECRAWL_API_KEY`). | ||
| - Install the [Firecrawl SDK](https://github.com/firecrawl/firecrawl) along with `crewai[tools]` package: | ||
|
|
||
| ``` | ||
| pip install firecrawl-py 'crewai[tools]' | ||
| ``` | ||
|
|
||
| ## Example | ||
|
|
||
| Utilize the FirecrawlInteractTool as follows to let your agent act on the web: | ||
|
|
||
| ```python | ||
| from crewai_tools import FirecrawlInteractTool | ||
|
|
||
| tool = FirecrawlInteractTool(config={"model": "spark-1-mini"}) | ||
| tool.run(prompt="Find the pricing page on firecrawl.dev and return the plan names") | ||
| ``` | ||
|
|
||
| ## Arguments | ||
|
|
||
| - `prompt`: Required. A natural-language description of the task for the agent to carry out. | ||
| - `urls`: Optional. A list of URLs to start from or constrain the agent to. | ||
| - `api_key`: Optional. Specifies the Firecrawl API key. Defaults to the `FIRECRAWL_API_KEY` environment variable. | ||
| - `config`: Optional. It contains Firecrawl v2 agent parameters. | ||
|
|
||
| This is the default configuration | ||
|
|
||
| ```python | ||
| { | ||
| "model": "spark-1-mini", | ||
| "max_credits": None, | ||
| "strict_constrain_to_urls": None, | ||
| "poll_interval": 2, | ||
| "timeout": None, | ||
| } | ||
| ``` | ||
Empty file.
117 changes: 117 additions & 0 deletions
117
lib/crewai-tools/src/crewai_tools/tools/firecrawl_interact_tool/firecrawl_interact_tool.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from crewai.tools import BaseTool, EnvVar | ||
| from pydantic import BaseModel, ConfigDict, Field, PrivateAttr | ||
|
|
||
| from crewai_tools.security.safe_path import validate_url | ||
|
|
||
|
|
||
| try: | ||
| from firecrawl import Firecrawl # type: ignore[import-untyped] | ||
|
|
||
| FIRECRAWL_AVAILABLE = True | ||
| except ImportError: | ||
| FIRECRAWL_AVAILABLE = False | ||
|
|
||
|
|
||
| class FirecrawlInteractToolSchema(BaseModel): | ||
| prompt: str = Field( | ||
| description="Natural-language description of the task for the Firecrawl agent to carry out by navigating and interacting with web pages" | ||
| ) | ||
| urls: list[str] | None = Field( | ||
| default=None, | ||
| description="Optional list of URLs to start from or constrain the agent to", | ||
| ) | ||
|
|
||
|
|
||
| class FirecrawlInteractTool(BaseTool): | ||
| """Tool for running an autonomous Firecrawl browser agent using the Firecrawl v2 API. To run this tool, you need to have a Firecrawl API key. | ||
|
|
||
| The agent navigates and interacts with web pages to accomplish a natural-language | ||
| task, then returns the result. | ||
|
|
||
| Args: | ||
| api_key (str): Your Firecrawl API key. | ||
| config (dict): Optional. It contains Firecrawl v2 agent parameters. | ||
|
|
||
| Default configuration options (Firecrawl v2 API): | ||
| model (str): Agent model to use ("spark-1-mini" or "spark-1-pro"). Default: "spark-1-mini" | ||
| max_credits (int): Maximum credits the agent may spend. Default: None (no cap) | ||
| strict_constrain_to_urls (bool): Restrict the agent to the provided urls only. Default: None | ||
| poll_interval (int): Seconds between status polls while the agent runs. Default: 2 | ||
| timeout (int): Overall timeout in seconds. Default: None | ||
| """ | ||
|
|
||
| model_config = ConfigDict( | ||
| arbitrary_types_allowed=True, validate_assignment=True, frozen=False | ||
| ) | ||
| name: str = "Firecrawl web interact tool" | ||
| description: str = ( | ||
| "Run an autonomous Firecrawl browser agent that navigates and interacts with " | ||
| "web pages to accomplish a task, then returns the result" | ||
| ) | ||
| args_schema: type[BaseModel] = FirecrawlInteractToolSchema | ||
| api_key: str | None = None | ||
| config: dict[str, Any] = Field( | ||
| default_factory=lambda: { | ||
| "model": "spark-1-mini", | ||
| "max_credits": None, | ||
| "strict_constrain_to_urls": None, | ||
| "poll_interval": 2, | ||
| "timeout": None, | ||
| } | ||
| ) | ||
|
|
||
| _firecrawl: Any = PrivateAttr(None) | ||
| package_dependencies: list[str] = Field(default_factory=lambda: ["firecrawl-py"]) | ||
| env_vars: list[EnvVar] = Field( | ||
| default_factory=lambda: [ | ||
| EnvVar( | ||
| name="FIRECRAWL_API_KEY", | ||
| description="API key for Firecrawl services", | ||
| required=True, | ||
| ), | ||
| ] | ||
| ) | ||
|
|
||
| def __init__(self, api_key: str | None = None, **kwargs: Any) -> None: | ||
| super().__init__(**kwargs) | ||
| try: | ||
| from firecrawl import Firecrawl | ||
| except ImportError: | ||
| import click | ||
|
|
||
| if click.confirm( | ||
| "You are missing the 'firecrawl-py' package. Would you like to install it?" | ||
| ): | ||
| import subprocess | ||
|
|
||
| subprocess.run(["uv", "add", "firecrawl-py"], check=True) # noqa: S607 | ||
| from firecrawl import ( | ||
| Firecrawl, | ||
| ) | ||
| else: | ||
| raise ImportError( | ||
| "`firecrawl-py` package not found, please run `uv add firecrawl-py`" | ||
| ) from None | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| self._firecrawl = Firecrawl(api_key=api_key) | ||
|
|
||
| def _run(self, prompt: str, urls: list[str] | None = None) -> Any: | ||
| if not self._firecrawl: | ||
| raise RuntimeError("Firecrawl client not properly initialized") | ||
|
|
||
| validated_urls = [validate_url(u) for u in urls] if urls else None | ||
| return self._firecrawl.agent(urls=validated_urls, prompt=prompt, **self.config) | ||
|
|
||
|
|
||
| try: | ||
| from firecrawl import Firecrawl # noqa: F401 | ||
|
|
||
| if not getattr(FirecrawlInteractTool, "_model_rebuilt", False): | ||
| FirecrawlInteractTool.model_rebuild() | ||
| FirecrawlInteractTool._model_rebuilt = True # type: ignore[attr-defined] | ||
| except ImportError: | ||
| pass | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.