Skip to content

Commit 31b5e43

Browse files
ohlavaMQ37jirispilkapritipsinghdirkbrnd
authored andcommitted
Add better Apify integration with examples (agno-agi#2566)
## Description - **Summary of changes**: This PR refactors the ApifyTools class replacing the previous custom implementation. - Implemented dynamic registration of any Apify Actor as a function - Added support for multiple actors through a single ApifyTools instance - Added comprehensive error handling and logging - Improved documentation with examples and configuration instructions - **Related issues**: This update is connected with [PR#183](agno-agi/agno-docs#183) in docs repo. - **Motivation and context**: The previous implementation only supported two hardcoded Apify actors (website-content-crawler and web-scraper). The new implementation allows users to utilize any of the 4000+ actors from the Apify ecosystem without modifying the core code. This significantly expands the tool's capabilities for web data extraction tasks. - **Environment or dependencies**: - langchain-apify: Required for ApifyActorsTool integration - apify-client: Required for direct API interactions - Now requires an APIFY_API_TOKEN environment variable or explicit API token parameter - **Impact on metrics**: - Increased flexibility with support for any Apify Actor - Improved documentation and error handling - Reduced code maintenance burden by leveraging LangChain's Actor interface - Better user experience through expanded examples in the demo script Fixes # (issue) --- ## Type of change Please check the options that are relevant: - [x] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Model update (Addition or modification of models) - [x] Other (please describe): Add better examples and start better integration with Apify. This update is connected with PR#183 in docs repo. --- ## Checklist - [x] Adherence to standards: Code complies with Agno’s style guidelines and best practices. - [x] Formatting and validation: You have run `./scripts/format.sh` and `./scripts/validate.sh` to ensure code is formatted and linted. - [x] Self-review completed: A thorough review has been performed by the contributor(s). - [x] Documentation: Docstrings and comments have been added or updated for any complex logic. - [x] Examples and guides: Relevant cookbook examples have been included or updated (if applicable). - [x] Tested in a clean environment: Changes have been tested in a clean environment to confirm expected behavior. - [ ] Tests (optional): Tests have been added or updated to cover any new or changed functionality. --- ## Additional Notes Include any deployment notes, performance implications, security considerations, or other relevant information (e.g., screenshots or logs if applicable). --------- Co-authored-by: Jakub Kopecký <[email protected]> Co-authored-by: Jiří Spilka <[email protected]> Co-authored-by: Priti <[email protected]> Co-authored-by: Dirk Brand <[email protected]> Co-authored-by: Ondřej Hlava <[email protected]>
1 parent 1dea1b5 commit 31b5e43

File tree

3 files changed

+398
-86
lines changed

3 files changed

+398
-86
lines changed

cookbook/tools/apify_tools.py

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,82 @@
11
from agno.agent import Agent
22
from agno.tools.apify import ApifyTools
33

4-
agent = Agent(tools=[ApifyTools()], show_tool_calls=True)
5-
agent.print_response("Tell me about https://docs.agno.com/introduction", markdown=True)
4+
# Apify Tools Demonstration Script
5+
"""
6+
This script showcases the power of web scraping and data extraction using Apify's Actors (serverless tools).
7+
The Apify ecosystem has 4000+ pre-built Actors for almost any web data extraction need!
8+
9+
---
10+
Configuration Instructions:
11+
1. Install required dependencies:
12+
pip install agno langchain-apify apify-client
13+
14+
2. Set the APIFY_API_TOKEN environment variable:
15+
Add a .env file with APIFY_API_TOKEN=your_apify_api_key
16+
---
17+
18+
Tip: Check out the Apify Store (https://apify.com/store) to find tools for almost any web scraping or data extraction task.
19+
"""
20+
21+
# Create an Apify Tools agent with versatile capabilities
22+
agent = Agent(
23+
name="Web Insights Explorer",
24+
instructions=[
25+
"You are a sophisticated web research assistant capable of extracting insights from various online sources. "
26+
"Use the available tools for your tasks to gather accurate, well-structured information."
27+
],
28+
tools=[
29+
ApifyTools(
30+
actors=[
31+
"apify/rag-web-browser",
32+
"compass/crawler-google-places",
33+
"clockworks/free-tiktok-scraper",
34+
]
35+
)
36+
],
37+
show_tool_calls=True,
38+
markdown=True,
39+
)
40+
41+
42+
def demonstrate_tools():
43+
print("Apify Tools Exploration 🔍")
44+
45+
# RAG Web Search Demonstrations
46+
print("\n1.1 🕵️ RAG Web Search Scenarios:")
47+
prompt = "Research the latest AI ethics guidelines from top tech companies. Compile a summary from at least 3 different sources comparing their approaches using RAG Web Browser."
48+
agent.print_response(prompt, show_full_reasoning=True)
49+
50+
print("\n1.2 🕵️ RAG Web Search Scenarios:")
51+
prompt = "Carefully extract the key introduction details from https://docs.agno.com/introduction" # Extract content from specific website
52+
agent.print_response(prompt)
53+
54+
# Google Places Demonstration
55+
print("\n2. Google Places Crawler:")
56+
prompt = "Find the top 5 highest-rated coffee shops in San Francisco with detailed information about each location"
57+
agent.print_response(prompt)
58+
59+
# Tiktok Scraper Demonstration
60+
print("\n3. Tiktok Profile Analysis:")
61+
prompt = "Analyze two profiles on Tiktok that lately added #AI (hashtag AI), extracting their statistics and recent content trends"
62+
agent.print_response(prompt)
63+
64+
65+
if __name__ == "__main__":
66+
demonstrate_tools()
67+
68+
"""
69+
Want to add a new tool? It's easy!
70+
- Browse Apify Store
71+
- Find an Actor that matches your needs
72+
- Add a new method to ApifyTools following the existing pattern
73+
- Register the method in the __init__
74+
75+
Examples of potential tools:
76+
- YouTube video info scraper
77+
- Twitter/X profile analyzer
78+
- Product price trackers
79+
- Job board crawlers
80+
- News article extractors
81+
- And SO MUCH MORE!
82+
"""

0 commit comments

Comments
 (0)