Build a Crew that finds the best roundtrip flights on the given dates.
Crew
is a team of Agents
working together to accomplish some tasks.Task
, such as “Search flights according to criteria”, is a goal assigned to a specialized Agent
(e.g., a Flight Booking Agent).Agent
can be seen as a specialized text-only GPT that receives a set of Tools
to perform actions (e.g., search on Google, navigate to this URL).role
that helps the Crew
select the best Agent for a given Task
.goal
that frames the Agent
decision-making process when iterating on a Task
.backstory
providing context to the Agent
’s role
and goal
.search_tool
(SerperDevTool
instance) to perform searches with Google Search.
The Tasks: writing and researching
Let’s now define 2 tasks: researching a topic and writing an article.
description
can be compared to a prompt, while the expected_output
helps format the result of the Task
.
As expected, the write_task
gets assigned to the writer
Agent and the research_task
to the researcher
Agent.
Agent
and Task
look alike. In real-world applications, an Agent
gets to
perform multiple tasks. Then, an Agent
represents the expertise (goal
, backstory
) with a set of skills (tools
), while a Task
is a goal to accomplish.Crew
defines a set of Task
to be performed sequentially by a team of Agents
.
Note that Tasks
share a context, explaining why the research task comes before the writing task.
Kayak
tool to translate the user input into a valid Kayak search URLOur Crew comprises 2 Agents, 2 Tools, and 2 Tasks.
.env
file with the following variables and their respective values:
Kayak
tool to assemble a valid Kayak search URLThe page is fully loaded, however the flights are still being searched.
Tool
is composed of 3 elements:
@tool("name")
decoratorTool
to help complete a given Task
.
A description can also provide instructions on the parameters. Here, we instruct that the unique url
parameter should be a URL.
Browserbase Tool Logic
The Browserbase tool utilizes the playwright
library along with the Browserbase Connect API to initiate a headless browser session. This setup allows interaction with web pages as follows:
html2text
library to convert the webpage’s content to text and return it to the Agent for processing.
date: The date of the flight in the format 'YYYY-MM-DD'
This illustrates the flexibility of Tools that can rely on the Agents
powerful reasoning capabilities to solve formatting challenges that generally require some preprocessing.
Agent
needs 3 properties: a role
, a goal
, and a backstory
.
The role of our two Agents is to orchestrate the tools (build the URL, then navigate to it) and
extract the information from the webpages’ text. For this reason, their definition is straightforward.
Tasks
.
From a given flight criteria, our Crew should print the 5 first available flights with their associated booking link.
To achieve such a result, our Crew needs to:
description
will be provided to the Flights Agent who will call:
output_search_example
and with the help of the Summarize Agent, it will return a list of 5 flightscurrent_year
?Most users will prompt a relative date, for example: “San Francisco to New York one-way on 21st September”.An Agent’s reasoning relies on OpenAI that lacks some intuition on relative date (OpenAI will always think we are in 2022).For this reason, we need to specify the current year in the prompt (Task’s description
).Agent
reasoning capabilities:
output_providers_example
.
Task
in the correct order (search flights, then gather providers and booking links):
Crew
- not to a Task
- to help consolidate the flights and providers into a simple list.
Let the Crew kick off!
A Crew
process starts by calling the kickoff()
method.
Our Crew needs 2 inputs: the user input (“San Francisco to New York one-way on 21st September”) and the current year.
1. Kickoff the first tasks: Search flights
1.1 Use the Kayak tool to generate a valid search URL
1.2 Use the Browserbase tool to extract the flights list
Task
(“Search for flights”) as completed (“Finished chain.”) and moves to the next one.2.x Iterate on each flight to extract provider and booking link
Task
is impressive as the Agent
realizes that it needs to loop over the 5 flights to retrieve the booking provider:3. Format the consolidated list of 5 flights
Crew
:
Agent
’s reasoning capabilities.
As we covered in this example, the Agents are capable of completing Tasks
defined with high-level instructions (ex: “Load every flight individually and find available booking providers”)
Combined with Browserbase headless browsers, crewAI helps create powerful AI Agents that automate human tasks or provide support in accessing data not accessible through public APIs.