Your First Crew: The Quickstart Guide
Your First Crew: The Quickstart Guide
Section titled “Your First Crew: The Quickstart Guide”Theory is essential, but nothing beats running code. In this chapter, we will build a simple crew that researches a technology topic and writes a short blog post about it. We will use the CrewAI CLI to generate the project structure.
Scaffolding the Project
Section titled “Scaffolding the Project”Open your terminal and run the create command. We will name our project latest_ai_news.
crewai create crew latest_ai_newsThe CLI will ask you to select a provider (like OpenAI) and a model. Once completed, navigate into your new folder:
cd latest_ai_newsUnderstanding the Directory Structure
Section titled “Understanding the Directory Structure”CrewAI encourages a clean separation of concerns. Here is the layout of the generated project:
latest_ai_news/├── src/│ └── latest_ai_news/│ ├── config/│ │ ├── agents.yaml <-- Define your Agents' personas here│ │ └── tasks.yaml <-- Define the Tasks here│ ├── crew.py <-- The logic binding everything together│ └── main.py <-- Entry point to run the crew├── .env <-- API Keys (DON'T commit this)└── pyproject.toml <-- DependenciesStep 1: Configuring Agents
Section titled “Step 1: Configuring Agents”Open src/latest_ai_news/config/agents.yaml. This file allows you to define agents using natural language, keeping your code clean. Let’s define a Researcher and a Writer.
researcher: role: > Senior Data Researcher goal: > Uncover cutting-edge developments in {topic} backstory: > You are a veteran tech journalist with an instinct for finding the most important news. You prioritize facts over hype.
writer: role: > Tech Content Strategist goal: > Craft compelling content on tech advancements backstory: > You are a famous writer, known for simplifying complex topics. You base your writing on the work of the Data Researcher.Notice the {topic} placeholder? We will pass this dynamic input when we run the crew.
Step 2: Configuring Tasks
Section titled “Step 2: Configuring Tasks”Next, open src/latest_ai_news/config/tasks.yaml. We define what the agents need to do.
research_task: description: > Conduct a thorough research about {topic}. Identify key trends and breakthrough technologies. expected_output: > A list of top 5 trends with brief descriptions. agent: researcher
writing_task: description: > Using the research findings, write a blog post about {topic}. expected_output: > A 4-paragraph blog post formatted in markdown. agent: writerStep 3: The Crew Logic
Section titled “Step 3: The Crew Logic”Look at src/latest_ai_news/crew.py. The CLI has already generated the Python code to load these YAML files. It uses decorators (@agent, @task, @crew) to map the YAML configurations to actual Python class instances.
Step 4: Running the Crew
Section titled “Step 4: Running the Crew”Before running, ensure your .env file contains your API key (e.g., OPENAI_API_KEY=sk-...).
Now, execute the crew using the command below. This invokes the logic in main.py.
crewai runYou will see the agents interacting in the console: the Researcher will generate the trends, and the Writer will pick that up and draft the post. Congratulations! You’ve just built your first multi-agent AI system.