There are two ways of creating a CrewAI project:
- using YAML files or
- not using YAML files.
When you use YAML files, you create an agent and a task with the @agent
and @task
decorators as follows (Note: You need to use Poetry.):
agents.yaml
researcher:
role: >
Researcher
goal: >
Write goal here.
backstory: >
Write backstory here.
tasks.yaml
research_task:
agent: researcher
description: >
Write description here.
expected_output: >
Write expected output here.
crew.py
@agent
def researcher(self) -> Agent:
return Agent(
config=self.agents_config['researcher'],
verbose=True,
tools=[SerperDevTool()]
)
@task
def research_task(self) -> Task:
return Task(
config=self.tasks_config['research_task'],
)
When you don’t use YAML files, you create an agent and a task as follows:
main.py
researcher = Agent(
role='Researcher',
goal='Write goal here.',
backstory='Write backstory here.',
tools=[SerperDevTool()],
)
research_task = Task(
agent: researcher,
description: 'Write description here.',
expected_output: 'Write expected output here.',
Which way of creating a CrewAI project should you choose? I would strongly recommend you use YAML files.
Why?
- YAML provides a clear, organized way to configure agents and tasks. This structure makes it easier to manage and update your project configuration.
- You’ll pick up the Flows, which where introduced just a few days ago, way quicker since it uses YAML files for agent and task configuration.
If you choose using YAML files, please take a look at the Quickstart page or Flows page (Note: If you don’t want to use Flows, just see this page as another example of YAML files and pay attention to the @agent
and @task
decorators.).