Skip to content

Commit 0105bc1

Browse files
committed
add crewai integration docs
1 parent 443a94b commit 0105bc1

File tree

1 file changed

+209
-0
lines changed

1 file changed

+209
-0
lines changed
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
---
2+
title: 🤖🚀 CrewAI integration
3+
sidebar_label: CrewAI
4+
description: Learn how to build AI Agents with Apify and CrewAI 🤖🚀.
5+
sidebar_position: 1
6+
slug: /integrations/crewai
7+
---
8+
9+
**Learn how to build AI Agents with Apify and CrewAI.**
10+
11+
---
12+
13+
## What is CrewAI
14+
15+
[CrewAI](https://www.crewai.com/) is an open-source Python framework designed to orchestrate autonomous, role-playing AI agents that collaborate as a "crew" to tackle complex tasks. It enables developers to define agents with specific roles, assign tasks, and integrate tools—like Apify Actors—for real-world data retrieval and automation.
16+
17+
:::note Explore CrewAI
18+
19+
For more in-depth details on CrewAI, check out its [official documentation](https://docs.crewai.com/).
20+
21+
:::
22+
23+
## How to use Apify with CrewAI
24+
25+
This guide demonstrates how to integrate Apify Actors with CrewAI by building a crew of agents that uses the [RAG Web Browser](https://apify.com/apify/rag-web-browser) Actor to search Google for TikTok profiles and the [TikTok Data Extractor](https://apify.com/clockworks/free-tiktok-scraper) Actor to extract and analyze data from the TikTok profiles.
26+
27+
### Prerequisites
28+
29+
- **Apify API token**: To use Apify Actors in CrewAI, you need an Apify API token. Learn how to obtain it in the [Apify documentation](https://docs.apify.com/platform/integrations/api).
30+
31+
- **OpenAI API key**: To power the agents in CrewAI, you need an OpenAI API key. Get one from the [OpenAI platform](https://platform.openai.com/account/api-keys).
32+
33+
- **Python packages**: Install the following Python packages:
34+
35+
```bash
36+
pip install 'crewai[tools]' langchain-apify langchain-openai
37+
```
38+
39+
### Building the TikTok profile search and analysis crew
40+
41+
First, import all required packages:
42+
43+
```python
44+
import os
45+
from crewai import Agent, Task, Crew
46+
from crewai_tools import ApifyActorsTool
47+
from langchain_openai import ChatOpenAI
48+
```
49+
50+
Next, set the environment variables for the Apify API token and OpenAI API key:
51+
52+
```python
53+
os.environ["OPENAI_API_KEY"] = "Your OpenAI API key"
54+
os.environ["APIFY_API_TOKEN"] = "Your Apify API token"
55+
```
56+
57+
Instantiate the LLM and Apify Actors tools:
58+
59+
```python
60+
llm = ChatOpenAI(model="gpt-4o-mini")
61+
62+
browser_tool = ApifyActorsTool(actor_name="apify/rag-web-browser")
63+
tiktok_tool = ApifyActorsTool(actor_name="clockworks/free-tiktok-scraper")
64+
```
65+
66+
Define the agents with roles, goals, and tools:
67+
68+
```python
69+
search_agent = Agent(
70+
role="Web Search Specialist",
71+
goal="Find the TikTok profile URL on the web",
72+
backstory="Expert in web searching and data retrieval",
73+
tools=[browser_tool],
74+
llm=llm,
75+
verbose=True
76+
)
77+
78+
analysis_agent = Agent(
79+
role="TikTok Profile Analyst",
80+
goal="Extract and analyze data from the TikTok profile",
81+
backstory="Skilled in social media data extraction and analysis",
82+
tools=[tiktok_tool],
83+
llm=llm,
84+
verbose=True
85+
)
86+
```
87+
88+
Define the tasks for the agents:
89+
90+
```python
91+
search_task = Task(
92+
description="Search the web for the OpenAI TikTok profile URL.",
93+
agent=search_agent,
94+
expected_output="A URL linking to the OpenAI TikTok profile."
95+
)
96+
97+
analysis_task = Task(
98+
description="Extract data from the OpenAI TikTok profile URL and provide a profile summary and details about the latest post.",
99+
agent=analysis_agent,
100+
context=[search_task],
101+
expected_output="A summary of the OpenAI TikTok profile including followers and likes, plus details about their most recent post."
102+
)
103+
```
104+
105+
Create and run the crew:
106+
107+
```python
108+
crew = Crew(
109+
agents=[search_agent, analysis_agent],
110+
tasks=[search_task, analysis_task],
111+
process="sequential"
112+
)
113+
114+
result = crew.kickoff()
115+
print(result)
116+
```
117+
118+
:::note Search and analysis may take some time
119+
120+
The agent tasks may take some time as they search the web for the OpenAI TikTok profile and extract data from it.
121+
122+
:::
123+
124+
You will see the crew’s output in the console, showing the results of the search and analysis.
125+
126+
```text
127+
Profile Summary:
128+
- Username: OpenAI
129+
- Profile URL: [OpenAI TikTok Profile](https://www.tiktok.com/@openai)
130+
- Followers: 605,000
131+
- Likes: 3,400,000
132+
- Number of Videos: 152
133+
- Verified: Yes
134+
- Signature: low key research previews
135+
- Bio Link: [OpenAI Website](https://openai.com/)
136+
137+
Latest Post Details:
138+
- Post ID: 7474019216346287406
139+
- Post Text: "@Adeline Mai is a photographer..."
140+
- Creation Time: February 21, 2025
141+
- Number of Likes: 863
142+
- Number of Shares: 26
143+
- Number of Comments: 33
144+
- Number of Plays: 20,400
145+
- Number of Collects: 88
146+
- Music Used: Original Sound by OpenAI
147+
- Web Video URL: [Watch Here](https://www.tiktok.com/@openai/video/7474019216346287406)
148+
```
149+
150+
If you want to test the whole example, create a new file, `crewai_integration.py`, and copy the full code into it:
151+
152+
```python
153+
import os
154+
from crewai import Agent, Task, Crew
155+
from crewai_tools import ApifyActorsTool
156+
from langchain_openai import ChatOpenAI
157+
158+
os.environ["OPENAI_API_KEY"] = "Your OpenAI API key"
159+
os.environ["APIFY_API_TOKEN"] = "Your Apify API token"
160+
161+
llm = ChatOpenAI(model="gpt-4o-mini")
162+
163+
browser_tool = ApifyActorsTool(actor_name="apify/rag-web-browser")
164+
tiktok_tool = ApifyActorsTool(actor_name="clockworks/free-tiktok-scraper")
165+
166+
search_agent = Agent(
167+
role="Web Search Specialist",
168+
goal="Find the TikTok profile URL on the web",
169+
backstory="Expert in web searching and data retrieval",
170+
tools=[browser_tool],
171+
llm=llm,
172+
verbose=True
173+
)
174+
175+
analysis_agent = Agent(
176+
role="TikTok Profile Analyst",
177+
goal="Extract and analyze data from the TikTok profile",
178+
backstory="Skilled in social media data extraction and analysis",
179+
tools=[tiktok_tool],
180+
llm=llm,
181+
verbose=True
182+
)
183+
184+
search_task = Task(
185+
description="Search the web for the OpenAI TikTok profile URL.",
186+
agent=search_agent,
187+
expected_output="A URL linking to the OpenAI TikTok profile."
188+
)
189+
analysis_task = Task(
190+
description="Extract data from the OpenAI TikTok profile URL and provide a profile summary and details about the latest post.",
191+
agent=analysis_agent,
192+
context=[search_task],
193+
expected_output="A summary of the OpenAI TikTok profile including followers and likes, plus details about their most recent post."
194+
)
195+
196+
crew = Crew(
197+
agents=[search_agent, analysis_agent],
198+
tasks=[search_task, analysis_task],
199+
process="sequential"
200+
)
201+
202+
result = crew.kickoff()
203+
print(result)
204+
```
205+
206+
## Resources
207+
208+
- [Apify Actors](https://docs.apify.com/platform/actors)
209+
- [CrewAI Documentation](https://docs.crewai.com/)

0 commit comments

Comments
 (0)