|
2 | 2 | title: Apify
|
3 | 3 | ---
|
4 | 4 |
|
5 |
| -**ApifyTools** enable an Agent to access the Apify API and run actors. |
| 5 | +This guide demonstrates how to integrate and use [Apify](https://apify.com/actors) Actors within the Agno framework to enhance your AI agents with web scraping, crawling, data extraction, and web automation capabilities. |
| 6 | + |
| 7 | +## What is Apify? |
| 8 | + |
| 9 | +[Apify](https://apify.com/) is a platform that provides: |
| 10 | +- Data collection services for AI Agents, specializing in extracting data from social media, search engines, online maps, e-commerce sites, travel portals, or general websites |
| 11 | +- A marketplace of ready-to-use Actors (specialized tools) for various data tasks |
| 12 | +- Infrastructure to run and monetize our own AI Agents |
6 | 13 |
|
7 | 14 | ## Prerequisites
|
8 | 15 |
|
9 |
| -The following example requires the `apify-client` library and an API token which can be obtained from [Apify](https://apify.com/). |
| 16 | +1. Sign up for an [Apify account](https://console.apify.com/sign-up) |
| 17 | +2. Obtain your Apify API token (can be obtained from [Apify](https://docs.apify.com/platform/integrations/api)) |
| 18 | +3. Install the required packages: |
10 | 19 |
|
11 |
| -```shell |
12 |
| -pip install -U apify-client |
| 20 | +```bash |
| 21 | +pip install agno apify-client |
13 | 22 | ```
|
14 | 23 |
|
15 |
| -```shell |
16 |
| -export MY_APIFY_TOKEN=*** |
| 24 | +## Basic Usage |
| 25 | + |
| 26 | +The Agno framework makes it easy to integrate Apify Actors into your agents. Here's a simple example: |
| 27 | + |
| 28 | +```python |
| 29 | +from agno.agent import Agent |
| 30 | +from agno.tools.apify import ApifyTools |
| 31 | + |
| 32 | +# Create an agent with ApifyTools |
| 33 | +agent = Agent( |
| 34 | + tools=[ |
| 35 | + ApifyTools( |
| 36 | + actors=["apify/rag-web-browser"], # Specify which Apify Actors to use, use multiple ones if needed |
| 37 | + apify_api_token="your_apify_api_key" # Or set the APIFY_API_TOKEN environment variable |
| 38 | + ) |
| 39 | + ], |
| 40 | + show_tool_calls=True, |
| 41 | + markdown=True |
| 42 | +) |
| 43 | + |
| 44 | +# Use the agent to get website content |
| 45 | +agent.print_response("What information can you find on https://docs.agno.com/introduction ?", markdown=True) |
17 | 46 | ```
|
18 | 47 |
|
19 |
| -## Example |
| 48 | +## Available Apify Tools |
| 49 | + |
| 50 | +You can easily integrate any Apify Actor as a tool. Here are some examples: |
| 51 | + |
| 52 | +### 1. RAG Web Browser |
20 | 53 |
|
21 |
| -The following agent will use Apify to crawl the webpage: https://docs.agno.com/introduction and summarize it. |
| 54 | +The [RAG Web Browser](https://apify.com/apify/rag-web-browser) Actor is specifically designed for AI and LLM applications. It searches the web for a query or processes a URL, then cleans and formats the content for your agent. This tool is enabled by default. |
22 | 55 |
|
23 |
| -```python cookbook/tools/apify_tools.py |
| 56 | +```python |
24 | 57 | from agno.agent import Agent
|
25 | 58 | from agno.tools.apify import ApifyTools
|
26 | 59 |
|
27 |
| -agent = Agent(tools=[ApifyTools()], show_tool_calls=True) |
28 |
| -agent.print_response("Tell me about https://docs.agno.com/introduction", markdown=True) |
| 60 | +agent = Agent( |
| 61 | + tools=[ |
| 62 | + ApifyTools(actors=["apify/rag-web-browser"]) |
| 63 | + ], |
| 64 | + show_tool_calls=True, |
| 65 | + markdown=True |
| 66 | +) |
| 67 | + |
| 68 | +# Search for information and process the results |
| 69 | +agent.print_response("What are the latest developments in large language models?", markdown=True) |
29 | 70 | ```
|
30 | 71 |
|
31 |
| -## Toolkit Params |
| 72 | +### 2. Website Content Crawler |
32 | 73 |
|
33 |
| -| Parameter | Type | Default | Description | |
34 |
| -| ------------------------- | ------ | ------- | --------------------------------------------------------------------------------- | |
35 |
| -| `api_key` | `str` | - | API key for authentication purposes. | |
36 |
| -| `website_content_crawler` | `bool` | `True` | Enables the functionality to crawl a website using website-content-crawler actor. | |
37 |
| -| `web_scraper` | `bool` | `False` | Enables the functionality to crawl a website using web_scraper actor. | |
| 74 | +This tool uses Apify's [Website Content Crawler](https://apify.com/apify/website-content-crawler) Actor to extract text content from websites, making it perfect for RAG applications. |
38 | 75 |
|
39 |
| -## Toolkit Functions |
| 76 | +```python |
| 77 | +from agno.agent import Agent |
| 78 | +from agno.tools.apify import ApifyTools |
40 | 79 |
|
41 |
| -| Function | Description | |
42 |
| -| ------------------------- | ------------------------------------------------------------- | |
43 |
| -| `website_content_crawler` | Crawls a website using Apify's website-content-crawler actor. | |
44 |
| -| `web_scrapper` | Scrapes a website using Apify's web-scraper actor. | |
| 80 | +agent = Agent( |
| 81 | + tools=[ |
| 82 | + ApifyTools(actors=["apify/website-content-crawler"]) |
| 83 | + ], |
| 84 | + markdown=True |
| 85 | +) |
| 86 | + |
| 87 | +# Ask the agent to process web content |
| 88 | +agent.print_response("Summarize the content from https://docs.agno.com/introduction", markdown=True) |
| 89 | +``` |
| 90 | + |
| 91 | +### 3. Google Places Crawler |
| 92 | + |
| 93 | +The [Google Places Crawler](https://apify.com/compass/crawler-google-places) extracts data about businesses from Google Maps and Google Places. |
| 94 | + |
| 95 | +```python |
| 96 | +from agno.agent import Agent |
| 97 | +from agno.tools.apify import ApifyTools |
| 98 | + |
| 99 | +agent = Agent( |
| 100 | + tools=[ |
| 101 | + ApifyTools(actors=["compass/crawler-google-places"]) |
| 102 | + ], |
| 103 | + show_tool_calls=True |
| 104 | +) |
| 105 | + |
| 106 | +# Find business information in a specific location |
| 107 | +agent.print_response("What are the top-rated restaurants in San Francisco?", markdown=True) |
| 108 | +agent.print_response("Find coffee shops in Prague", markdown=True) |
| 109 | +``` |
| 110 | + |
| 111 | +## Example Scenarios |
| 112 | + |
| 113 | +### RAG Web Browser + Google Places Crawler |
| 114 | +This example combines web search with local business data to provide comprehensive information about a topic: |
| 115 | + |
| 116 | +```python |
| 117 | +from agno.agent import Agent |
| 118 | +from agno.tools.apify import ApifyTools |
| 119 | + |
| 120 | +agent = Agent( |
| 121 | + tools=[ |
| 122 | + ApifyTools(actors=[ |
| 123 | + "apify/rag-web-browser", |
| 124 | + "compass/crawler-google-places" |
| 125 | + ]) |
| 126 | + ], |
| 127 | + show_tool_calls=True |
| 128 | +) |
| 129 | + |
| 130 | +# Get general information and local businesses |
| 131 | +agent.print_response( |
| 132 | + """ |
| 133 | + I'm traveling to Tokyo next month. |
| 134 | + 1. Research the best time to visit and major attractions |
| 135 | + 2. Find one good rated sushi restaurants near Shinjuku |
| 136 | + Compile a comprehensive travel guide with this information. |
| 137 | + """, |
| 138 | + markdown=True |
| 139 | +) |
| 140 | +``` |
| 141 | + |
| 142 | +## Toolkit Params |
| 143 | + |
| 144 | +| Parameter | Type | Default | Description | |
| 145 | +| ---------------------------- | ------------------- | ------- | ------------------------------------------------------------------ | |
| 146 | +| `apify_api_token` | `str` | `None` | Apify API token (or set via APIFY_API_TOKEN environment variable) | |
| 147 | +| `actors` | `str` or `List[str]`| `None` | Single Actor ID or list of Actor IDs to register | |
45 | 148 |
|
46 | 149 | ## Developer Resources
|
47 | 150 |
|
48 | 151 | - View [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/apify.py)
|
49 | 152 | - View [Cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/tools/apify_tools.py)
|
| 153 | + |
| 154 | +## Resources |
| 155 | + |
| 156 | +- [Apify Actor Documentation](https://docs.apify.com/Actors) |
| 157 | +- [Apify Store - Browse available Actors](https://apify.com/store) |
| 158 | +- [How to build and monetize an AI agent on Apify](https://blog.apify.com/how-to-build-an-ai-agent/) |
0 commit comments