CrewAI agents with Exa
Learn how to add Exa retrieval capabilities to your CrewAI agents.
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
Pre-requisites and installation
Install the crewAI core, crewAI tools and Exa Python SDK libraries.
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.
OPENAI_API_KEY
and EXA_API_KEY
for OpenAI and Exa keys respectively. Get your Exa API key
Setting up CrewAI agent
Import the relevant crewAI modules. Then, define exa_tools
to reference the custom search method we defined above.
We then set up two agents and place them in a crew together:
- One to research with Exa (providing the custom tool defined above)
- Another to write a newsletter as an output (using an LLM)
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.
Kicking off the crew
Finally, we kick off the crew by providing a research topic as our input query.
Output
As you can see, Exa’s search results enriched the output generation!