CrewAI lets you define agents and tasks in YAML files instead of hard-coding them, which separates configuration from code and makes the crew easier to change. Each agent gets a role, a goal and a backstory; each task gets a description, an expected output and the agent that runs it.
Before you start
You need a scaffolded CrewAI project from crewai create crew. Decide the crew job first and split it into two or three tasks, one per agent, before you write any YAML.
Write the agents in agents.yaml
Open src/<project>/config/agents.yaml and define each agent with a role, a goal and a backstory. Keep the role to one job, for example Senior Data Researcher, and write the goal as the outcome that agent must produce, not as a list of steps. The backstory sets the expertise the agent draws on.
Write the tasks in tasks.yaml
Open src/<project>/config/tasks.yaml and define each task with a description, an expected output and the agent that runs it. The description should name the topic, the sources to use and the shape of the result. The expected output is the contract: a list of ten bullet points, or a three-paragraph briefing, not a vague summary.
Worked example: YAML config for a fictional research crew
Maple Research is a fictional research desk. Its crew has a researcher and a reporting analyst. The table shows the two agents and their tasks.
| Agent | Role | Task |
|---|---|---|
| researcher | Senior Data Researcher | Research the topic and list the key developments |
| reporting_analyst | Reporting Analyst | Turn the research into a short briefing |
Expected result (UNTESTED): the crew runs with the researcher finishing first and the analyst writing the briefing from the research output. We checked the CrewAI blog, which shows the agents.yaml and tasks.yaml shapes, but we did not run the crew on this machine.
Limits
YAML is strict about indentation: a misaligned line can silently change which agent a task belongs to. Keep roles narrow, because an agent with two jobs does neither well. Check the expected output of each task before you add a third agent.
