Creating Your First Playbook - CrewAI
Introduction
Welcome to CrewAI! In this tutorial, we will guide you through the process of creating your first playbook. A playbook in CrewAI is a blueprint that defines a set of tasks or actions to be executed. This tutorial will cover everything from setting up your environment to writing and executing your playbook.
Setting Up Your Environment
Before we start creating our playbook, let's ensure that our environment is set up correctly. Please follow these steps:
- Install Python: CrewAI requires Python to run. Download and install the latest version of Python from the official website.
- Install CrewAI: Use the following command to install CrewAI:
pip install crewai
Creating a Simple Playbook
Now that our environment is set up, let's create our first playbook. A playbook in CrewAI is written in YAML format. Below is a simple example of a playbook:
--- name: My First Playbook tasks: - name: Print a welcome message crewai.print: msg: "Welcome to CrewAI!"
Save this content in a file named my_first_playbook.yml
.
Understanding the Playbook Structure
Let's break down the components of the playbook:
- name: This defines the name of the playbook.
- tasks: This is a list of tasks to be executed. Each task has:
- name: The name of the task.
- crewai.print: The module to be executed. In this case, it prints a message.
- msg: The message to be printed.
Executing the Playbook
To execute the playbook, use the following command:
crewai-playbook my_first_playbook.yml
If everything is set up correctly, you should see the following output:
PLAY [My First Playbook] ****************************************************** TASK [Print a welcome message] ************************************************ ok: [localhost] => { "msg": "Welcome to CrewAI!" } PLAY RECAP ********************************************************************* localhost : ok=1 changed=0 unreachable=0 failed=0
Conclusion
Congratulations! You've successfully created and executed your first playbook in CrewAI. This is just the beginning; CrewAI offers a wide range of functionalities to automate complex workflows. Explore the documentation to learn more about advanced features and capabilities.