Installation vs Documentation Syntax

I’m a little confused by the different structures between what we are given as default in the installation process (crewai install, resulting in the file structure listed here) versus a structure largely to our own making.

For example, following the Quickstart guidance we create an Agent this way:

	@agent
	def researcher(self) -> Agent:
		return Agent(
			config=self.agents_config['researcher'],
			#tools=[search_tool],
			verbose=True
		)

But the Documentation describes it like this:

agent1 = CustomAgent(
    role="agent role",
    goal="who is {input}?",
    backstory="agent backstory",
    verbose=True,
)

In this example, it’s pretty simple to translate between the two, but when I attempt to do anything a little more advanced than what is given in the pre-installed example I keep getting errors. (How do I create a manager agent, for example?)

Am I missing something? Should I just scrap the structure provided during the crewai create crew [project] process and make my own?

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?

  1. YAML provides a clear, organized way to configure agents and tasks. This structure makes it easier to manage and update your project configuration.
  2. 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.).

Thanks, Flows look pretty powerful! I’ll have to dig into them.

So if I’m understanding the process correctly, even if I use a YAML structure, I should be able to utilize any of the syntax structure as outlined in the documentation?

@Naxio Nothing you see in the docs is incorrect. It’s just a different way of creating a CrewAI project. The only thing you need to be careful about is not to mix both ways.