5
Creating a Crew and kick it off
João Moura edited this page 2023-11-14 13:42:53 -03:00

Get a crew working

Assembling a Crew in CrewAI is like casting characters for a play. Each agent you create is a cast member with a unique part to play. When your crew is assembled, you'll give the signal, and they'll spring into action, each performing their role in the grand scheme of your project.

Step 1: Assemble Your Agents

Start by creating your agents, each with its own role and backstory. These backstories add depth to the agents, influencing how they approach their tasks and interact with one another.

from crewai import Agent

# Create a researcher agent
researcher = Agent(
  role='Senior Researcher',
  goal='Discover groundbreaking technologies',
  verbose=True,
  backstory='A curious mind fascinated by cutting-edge innovation and the potential to change the world, you know everything about tech.'
)

# Create a writer agent
writer = Agent(
  role='Writer',
  goal='Craft compelling stories about tech discoveries',
  verbose=True,
  backstory='A creative soul who translates complex tech jargon into engaging narratives for the masses, you write using simple words in a friendly and inviting tone that does not sounds like AI.'
)

Step 2: Define the Tasks

Outline the tasks that your agents need to tackle. These tasks are their missions, the specific objectives they need to achieve.

from crewai import Task

# Task for the researcher
research_task = Task(
  description='Identify the next big trend in AI',
  agent=researcher  # Assigning the task to the researcher
)

# Task for the writer
write_task = Task(
  description='Write an article on AI advancements leveraging the research made.',
  agent=writer  # Assigning the task to the writer
)

Step 3: Form the Crew

Bring your agents together into a crew. This is where you define the process they'll follow to complete their tasks.

from crewai import Crew, Process

# Instantiate your crew
tech_crew = Crew(
  agents=[researcher, writer],
  tasks=[research_task, write_task],
  process=Process.sequential  # Tasks will be executed one after the other
)

Step 4: Kick It Off

With the crew formed and the stage set, it's time to start the show. Kick off the process and watch as your agents collaborate to achieve their goals.

# Begin the task execution
tech_crew.kickoff()

Conclusion

Creating a crew and setting it into motion is a straightforward process in CrewAI. With each agent playing their part and a clear set of tasks, your AI ensemble is ready to take on any challenge. Remember, the richness of their backstories and the clarity of their goals will greatly enhance their performance and the outcomes of their collaboration.