From 9c7c7d3d75ea21632b6e7f786001bc58d9f576b6 Mon Sep 17 00:00:00 2001 From: MQ Date: Tue, 4 Mar 2025 11:10:41 +0100 Subject: [PATCH] apify_actors -> apify_actors_tool, refactor readme --- src/crewai_tools/tools/__init__.py | 2 +- src/crewai_tools/tools/apify_actors/README.md | 101 ------------------ .../tools/apify_actors_tool/README.md | 86 +++++++++++++++ .../apify_actors_tool.py} | 42 ++++---- 4 files changed, 108 insertions(+), 123 deletions(-) delete mode 100644 src/crewai_tools/tools/apify_actors/README.md create mode 100644 src/crewai_tools/tools/apify_actors_tool/README.md rename src/crewai_tools/tools/{apify_actors/apify_actors.py => apify_actors_tool/apify_actors_tool.py} (65%) diff --git a/src/crewai_tools/tools/__init__.py b/src/crewai_tools/tools/__init__.py index 34b200c7a..b1c3b6d68 100644 --- a/src/crewai_tools/tools/__init__.py +++ b/src/crewai_tools/tools/__init__.py @@ -1,5 +1,5 @@ from .ai_mind_tool.ai_mind_tool import AIMindTool -from .apify_actors.apify_actors import ApifyActorsTool +from .apify_actors_tool.apify_actors_tool import ApifyActorsTool from .brave_search_tool.brave_search_tool import BraveSearchTool from .browserbase_load_tool.browserbase_load_tool import BrowserbaseLoadTool from .code_docs_search_tool.code_docs_search_tool import CodeDocsSearchTool diff --git a/src/crewai_tools/tools/apify_actors/README.md b/src/crewai_tools/tools/apify_actors/README.md deleted file mode 100644 index 9260215cd..000000000 --- a/src/crewai_tools/tools/apify_actors/README.md +++ /dev/null @@ -1,101 +0,0 @@ -# ApifyActorsTool - -Integrate [Apify Actors](https://apify.com/) into your CrewAI workflows with ease. - -## Description - -The `ApifyActorsTool` seamlessly integrates [Apify Actors](https://apify.com/) - cloud-based web scraping and automation programs—into your CrewAI workflows. Whether you need to extract data, crawl websites, or automate tasks, this tool simplifies the process without requiring infrastructure management. - -Key features: -- **Run Actors Directly**: Execute Actors like the [RAG Web Browser](https://apify.com/apify/rag-web-browser) within CrewAI agents. -- **Real-Time Data**: Ideal for tasks requiring up-to-date web data or automation. -- **Explore More**: Discover additional Actors in the [Apify Store](https://apify.com/store). - -For detailed integration guidance, see the [Apify CrewAI documentation](https://docs.apify.com/platform/integrations/crewai). - -## Installation - -To use `ApifyActorsTool`, install the required packages and configure your Apify API token. You’ll need an API token from Apify - see the [Apify API documentation](https://docs.apify.com/platform/integrations/api) for instructions. - -### Steps - -1. **Install Dependencies** - Use pip to install `crewai[tools]` and `langchain-apify`: - ```bash - pip install 'crewai[tools]' langchain-apify - ``` - Alternatively, with `uv`: - ```bash - uv pip install 'crewai[tools]' langchain-apify - ``` - -2. **Set Your API Token** - Export the token as an environment variable: - - On Linux/macOS: - ```bash - export APIFY_API_TOKEN='your-api-token-here' - ``` - - On Windows (Command Prompt): - ```cmd - set APIFY_API_TOKEN=your-api-token-here - ``` - - Or add it to your `.env` file and load it with a library like `python-dotenv`. - -3. **Verify Installation** - Run `python -c "import langchain_apify; print('Setup complete')"` to ensure dependencies are installed. - -## Usage example - -Here’s how to use `ApifyActorsTool` to run the [RAG Web Browser Actor](https://apify.com/apify/rag-web-browser) for web searching within a CrewAI workflow: - -```python -from crewai_tools import ApifyActorsTool - -# Initialize the tool with an Apify Actor -tool = ApifyActorsTool(actor_name="apify/rag-web-browser") - -# Run the tool with input parameters -results = tool.run(run_input={"query": "What is CrewAI?", "maxResults": 5}) - -# Process the results -for result in results: - print(f"URL: {result['metadata']['url']}") - print(f"Content: {result.get('markdown', 'N/A')[:100]}...") # Snippet of markdown content -``` - -### Expected output - -```text -URL: https://www.example.com/crewai-intro -Content: CrewAI is a framework for building AI-powered workflows... -URL: https://docs.crewai.com/ -Content: Official documentation for CrewAI... -``` - -For a more comprehensive example with tool-agent, see [CrewAI Apify Actor template](https://apify.com/templates/python-crewai). - -Try other Actors from the [Apify Store](https://apify.com/store) by changing `actor_name` and adjusting `run_input` per the Actor's input schema. - -## Configuration - -The `ApifyActorsTool` requires specific inputs to operate: - -- **`actor_name` (str, required)** - The ID of the Apify Actor to run (e.g., `"apify/rag-web-browser"`). Find Actors in the [Apify Store](https://apify.com/store). -- **`run_input` (dict, required at runtime)** - A dictionary of input parameters for the Actor. Examples: - - For `apify/rag-web-browser`: `{"query": "search term", "maxResults": 5}` - - Check each Actor’s [input schema](https://apify.com/apify/rag-web-browser/input-schema) for details. - -The tool adapts dynamically to the chosen [Actor](https://docs.apify.com/platform/actors). - -## Resources - -- **[Apify Platform](https://apify.com/)**: Explore the Apify ecosystem. -- **[RAG Web Browser Actor](https://apify.com/apify/rag-web-browser)**: Try this popular Actor for web data retrieval. -- **[Apify Actors Documentation](https://docs.apify.com/platform/actors)**: Learn how to use and create Actors. -- **[CrewAI Integration Guide](https://docs.apify.com/platform/integrations/crewai)**: Official guide for Apify and CrewAI. - ---- - -Streamline your CrewAI workflows with `ApifyActorsTool` - combine the power of Apify’s web scraping and automation with agent-based intelligence. diff --git a/src/crewai_tools/tools/apify_actors_tool/README.md b/src/crewai_tools/tools/apify_actors_tool/README.md new file mode 100644 index 000000000..f075a896a --- /dev/null +++ b/src/crewai_tools/tools/apify_actors_tool/README.md @@ -0,0 +1,86 @@ +# ApifyActorsTool + +Integrate [Apify Actors](https://apify.com/) into your CrewAI workflows. + +## Description + +ApifyActorsTool connects [Apify Actors](https://apify.com/), cloud-based programs for web scraping and automation, to your CrewAI workflows. You can extract data, crawl websites, and automate tasks, all without requiring infrastructure management. + +**Key features**: +- **Run Actors** directly, like the [RAG Web Browser](https://apify.com/apify/rag-web-browser), with CrewAI agents. +- **Access real-time data** for tasks that need fresh web content or automation. + +See the [Apify CrewAI documentation](https://docs.apify.com/platform/integrations/crewai) for a detailed integration guide. + +## Installation + +To use ApifyActorsTool, install the necessary packages and set up your Apify API token. Follow the [Apify API documentation](https://docs.apify.com/platform/integrations/api) for steps to obtain the token. + +### Steps + +1. **Install dependencies** + Use pip to install `crewai[tools]` and `langchain-apify`: + ```bash + pip install 'crewai[tools]' langchain-apify + ``` + Or, with `uv`: + ```bash + uv pip install 'crewai[tools]' langchain-apify + ``` + +2. **Set your API token** + Export the token as an environment variable: + ```bash + export APIFY_API_TOKEN='your-api-token-here' + ``` + +## Usage example + +Use ApifyActorsTool to run the [RAG Web Browser Actor](https://apify.com/apify/rag-web-browser) and perform a web search: + +```python +from crewai_tools import ApifyActorsTool + +# Initialize the tool with an Apify Actor +tool = ApifyActorsTool(actor_name="apify/rag-web-browser") + +# Run the tool with input parameters +results = tool.run(run_input={"query": "What is CrewAI?", "maxResults": 5}) + +# Process the results +for result in results: + print(f"URL: {result['metadata']['url']}") + print(f"Content: {result.get('markdown', 'N/A')[:100]}...") +``` + +### Expected output + +Here is the output from running the code above: + +```text +URL: https://www.example.com/crewai-intro +Content: CrewAI is a framework for building AI-powered workflows... +URL: https://docs.crewai.com/ +Content: Official documentation for CrewAI... +``` + +Experiment with other Actors from the [Apify Store](https://apify.com/store) by updating `actor_name` and `run_input` based on each Actor's input schema. + +For an example of usage with agents, see the [CrewAI Apify Actor template](https://apify.com/templates/python-crewai). + +## Configuration + +ApifyActorsTool requires these inputs to work: + +- **`actor_name`** + The ID of the Apify Actor to run, e.g., `"apify/rag-web-browser"`. Browse options in the [Apify Store](https://apify.com/store). +- **`run_input`** + A dictionary of input parameters for the Actor. Examples: + - For `apify/rag-web-browser`: `{"query": "search term", "maxResults": 5}` + - See each Actor's [input schema](https://apify.com/apify/rag-web-browser/input-schema) for details. + +## Resources + +- **[Apify Platform](https://apify.com/)**: Dive into the Apify ecosystem. +- **[RAG Web Browser Actor](https://apify.com/apify/rag-web-browser)**: Test this popular Actor for web data retrieval. +- **[CrewAI Integration Guide](https://docs.apify.com/platform/integrations/crewai)**: Follow the official guide for Apify and CrewAI. diff --git a/src/crewai_tools/tools/apify_actors/apify_actors.py b/src/crewai_tools/tools/apify_actors_tool/apify_actors_tool.py similarity index 65% rename from src/crewai_tools/tools/apify_actors/apify_actors.py rename to src/crewai_tools/tools/apify_actors_tool/apify_actors_tool.py index 9fc2d965b..37ae7312b 100644 --- a/src/crewai_tools/tools/apify_actors/apify_actors.py +++ b/src/crewai_tools/tools/apify_actors_tool/apify_actors_tool.py @@ -9,34 +9,34 @@ if TYPE_CHECKING: class ApifyActorsTool(BaseTool): """Tool that runs Apify Actors. - To use, you should have the environment variable `APIFY_API_TOKEN` set - with your API key. + To use, you should have the environment variable `APIFY_API_TOKEN` set + with your API key. - For details, see https://docs.apify.com/platform/integrations/crewai + For details, see https://docs.apify.com/platform/integrations/crewai - Args: - actor_name (str): The name of the Apify Actor to run. - *args: Variable length argument list passed to BaseTool. - **kwargs: Arbitrary keyword arguments passed to BaseTool. + Args: + actor_name (str): The name of the Apify Actor to run. + *args: Variable length argument list passed to BaseTool. + **kwargs: Arbitrary keyword arguments passed to BaseTool. - Returns: - List[Dict[str, Any]]: Results from the Actor execution. + Returns: + List[Dict[str, Any]]: Results from the Actor execution. - Raises: - ValueError: If `APIFY_API_TOKEN` is not set or if the tool is not initialized. - ImportError: If `langchain_apify` package is not installed. + Raises: + ValueError: If `APIFY_API_TOKEN` is not set or if the tool is not initialized. + ImportError: If `langchain_apify` package is not installed. - Example: - .. code-block:: python - from crewai_tools import ApifyActorsTool + Example: + .. code-block:: python + from crewai_tools import ApifyActorsTool - tool = ApifyActorsTool(actor_name="apify/rag-web-browser") + tool = ApifyActorsTool(actor_name="apify/rag-web-browser") - results = tool.run(run_input={"query": "What is CrewAI?", "maxResults": 5}) - for result in results: - print(f"URL: {result['metadata']['url']}") - print(f"Content: {result.get('markdown', 'N/A')[:100]}...") - """ + results = tool.run(run_input={"query": "What is CrewAI?", "maxResults": 5}) + for result in results: + print(f"URL: {result['metadata']['url']}") + print(f"Content: {result.get('markdown', 'N/A')[:100]}...") + """ actor_tool: '_ApifyActorsTool' = Field(description="Apify Actor Tool") def __init__(