Quickstart
Build your first AI agent with CrewAI in under 5 minutes.
Build your first CrewAI Agent
Let’s create a simple crew that will help us research
and report
on the latest AI developments
for a given topic or subject.
Before we proceed, make sure you have crewai
and crewai-tools
installed.
If you haven’t installed them yet, you can do so by following the installation guide.
Follow the steps below to get crewing! 🚣♂️
Create your crew
Create a new crew project by running the following command in your terminal.
This will create a new directory called latest-ai-development
with the basic structure for your crew.
Modify your `agents.yaml` file
You can also modify the agents as needed to fit your use case or copy and paste as is to your project.
Any variable interpolated in your agents.yaml
and tasks.yaml
files like {topic}
will be replaced by the value of the variable in the main.py
file.
Modify your `tasks.yaml` file
Modify your `crew.py` file
Feel free to pass custom inputs to your crew
For example, you can pass the topic
input to your crew to customize the research and reporting.
Set your environment variables
Before running your crew, make sure you have the following keys set as environment variables in your .env
file:
- An OpenAI API key (or other LLM API key):
OPENAI_API_KEY=sk-...
- A Serper.dev API key:
SERPER_API_KEY=YOUR_KEY_HERE
Lock and install the dependencies
Lock the dependencies and install them by using the CLI command but first, navigate to your project directory:
Run your crew
To run your crew, execute the following command in the root of your project:
View your final report
You should see the output in the console and the report.md
file should be created in the root of your project with the final report.
Here’s an example of what the report should look like:
Note on Consistency in Naming
The names you use in your YAML files (agents.yaml
and tasks.yaml
) should match the method names in your Python code.
For example, you can reference the agent for specific tasks from tasks.yaml
file.
This naming consistency allows CrewAI to automatically link your configurations with your code; otherwise, your task won’t recognize the reference properly.
Example References
Note how we use the same name for the agent in the agents.yaml
(email_summarizer
) file as the method name in the crew.py
(email_summarizer
) file.
Note how we use the same name for the agent in the tasks.yaml
(email_summarizer_task
) file as the method name in the crew.py
(email_summarizer_task
) file.
Use the annotations to properly reference the agent and task in the crew.py
file.
Annotations include:
@agent
@task
@crew
@tool
@callback
@output_json
@output_pydantic
@cache_handler
In addition to the sequential process, you can use the hierarchical process, which automatically assigns a manager to the defined crew to properly coordinate the planning and execution of tasks through delegation and validation of results. You can learn more about the core concepts here.
Replay Tasks from Latest Crew Kickoff
CrewAI now includes a replay feature that allows you to list the tasks from the last run and replay from a specific one. To use this feature, run.
Replace <task_id>
with the ID of the task you want to replay.
Reset Crew Memory
If you need to reset the memory of your crew before running it again, you can do so by calling the reset memory feature:
This will clear the crew’s memory, allowing for a fresh start.
Deploying Your Project
The easiest way to deploy your crew is through CrewAI Enterprise, where you can deploy your crew in a few clicks.
Was this page helpful?