CrewAI is a framework for orchestrating AI agents that work together to accomplish complex tasks. In this guide, we’ll create a crew of two agents that generate a newsletter based on Exa’s search results. We’ll go over how to:
- Create a custom Exa-powered CrewAI tool
- Set up agents and assign them specific roles that use the Exa-powered search tool
- Organize the agents into a crew that will write a newsletter
Get Started
1
Pre-requisites and installation
Install the crewAI core, crewAI tools and Exa Python SDK libraries.
Python
2
Defining a custom Exa-based tool in crewAI
We set up a custom tool using the crewAI @tool decorator . Within the tool, we can initialize the Exa class from the Exa Python SDK, make a request, and return a parsed out result.
Python
Make sure your API keys are initialized properly. For this demonstration, the environment variable names are
OPENAI_API_KEY
and EXA_API_KEY
for OpenAI and Exa keys respectively. Get your Exa API key
3
Setting up CrewAI agent
Import the relevant crewAI modules. Then, define We then set up two agents and place them in a crew together:
exa_tools
to reference the custom search method we defined above.Python
- One to research with Exa (providing the custom tool defined above)
- Another to write a newsletter as an output (using an LLM)
Python
4
Defining tasks for the agents
Next, we’ll define tasks for each agent and create the crew overall using all of the components we’ve set up above.
Python
5
Kicking off the crew
Finally, we kick off the crew by providing a research topic as our input query.
Python
6
Output
As you can see, Exa’s search results enriched the output generation!
Stdout