The RIGHT WAY To Build AI Agents with CrewAI (BONUS: 100% Local)

Matthew Berman
15 Apr 202419:46

TLDRThis video tutorial demonstrates the optimal setup for a Crew AI team using Lightning AI, a cloud-based code editor that facilitates collaboration and supports open-source models. The presenter, with guidance from Crew AI's founder, outlines the future of AI codebases and showcases how to build a modular Crew AI framework. The process involves creating a new studio, defining tasks and agents in YAML files, and leveraging the power of Lightning AI's GPUs. The video also covers how to structure the code for a financial analyst crew, integrate tasks, and swap out models like GPT-4 with open-source alternatives like Mixol, all powered by Lightning AI's infrastructure.

Takeaways

  • 🌟 The video demonstrates the optimal setup for a Crew AI team, utilizing Lightning AI, a cloud-based code editor that facilitates collaboration and open-source model integration.
  • 🛠️ The presenter introduces a modular structure for the Crew AI code framework, using YAML to define agents and tasks, which simplifies the main.py file.
  • 📁 The process involves creating a new studio in Lightning AI, setting up a source folder, and organizing tasks and agents within a 'config' subfolder.
  • 🔍 The 'research company task' is defined to gather stock information using a search tool, aiming to prepare for an informed analysis of a company's stock performance.
  • 📊 The 'analyze company task' is designed to perform a financial analysis, including various financial metrics such as profitability, liquidity, and solvency ratios.
  • 👥 Two agents are created: 'company researcher' and 'company analyst', each with specific roles and goals related to financial analysis.
  • 🔗 The agents are configured not to delegate tasks and to provide verbose output for transparency and detailed insight into their processes.
  • 🔧 The main file 'crew.py' integrates all the agents and tasks, setting up the crew with a sequential process and verbose output.
  • 🔗 The video includes the use of an external tool, 'SEC tools', to assist with financial data gathering without building from scratch.
  • 🚀 The project is managed using Poetry, which is used to install dependencies and run the project, showcasing the ease of working with Lightning AI's environment.
  • 🔌 The video concludes with the successful execution of the Crew AI team, demonstrating the integration of an open-source model powered by Lightning AI's GPUs, and the exposure of an API endpoint for further integration.

Q & A

  • What is the main topic of the video?

    -The main topic of the video is to demonstrate the optimal way to set up a Crew AI team using Lightning AI, a cloud-based code editor, and how to build and power AI agents with open-source models.

  • What is Lightning AI and how does it help in building AI teams?

    -Lightning AI is a cloud-based code editor that facilitates collaboration on code in the cloud. It also allows users to power open-source models, making it easier to build and manage AI teams and projects.

  • What is the significance of using YAML to define agents and tasks in the Crew AI framework?

    -Using YAML to define agents and tasks helps in structuring the Crew AI framework in a modular way, making it easier to manage and maintain. It also potentially allows for the automatic creation of an API to control the Crew based on this structure.

  • Can you explain the concept of 'modular' in the context of the Crew AI code framework mentioned in the video?

    -In the context of the Crew AI code framework, 'modular' refers to the approach of breaking down the code into separate, interchangeable components or modules. This makes the system more organized, easier to update, and simplifies collaboration.

  • What is the purpose of the 'main.py' file in the Crew AI code framework?

    -The 'main.py' file serves as the central point where all the different components or modules of the Crew AI code framework come together. It is a short file that orchestrates the flow of tasks and agents within the system.

  • What is the role of the 'config' folder in the Crew AI code framework?

    -The 'config' folder is used to store the definitions of tasks and agents in the Crew AI code framework. It contains YAML files that describe the structure and behavior of the agents and tasks.

  • What are the two tasks defined in the video script and what are their purposes?

    -The two tasks defined are 'research company task' and 'analyze company task'. The first task is for researching a specific company's stock information using a search tool, while the second task involves analyzing the financial information of a company to provide a thorough financial analysis.

  • How does the video script guide the creation of agents in the Crew AI framework?

    -The script guides the creation of agents by showing how to define them in a YAML file, specifying their roles, goals, and other attributes. It also demonstrates how to match each agent to an individual task and set properties like 'allow delegation' and 'verbose'.

  • What is the purpose of the 'financial analyst crew' folder created in the video?

    -The 'financial analyst crew' folder is created to organize and contain all the relevant files and configurations for a specific Crew AI team that focuses on financial analysis tasks.

  • How does the video demonstrate the integration of an open-source model with Lightning AI?

    -The video demonstrates the integration by showing how to set up an open-source model like Mixol or Mistral with Lightning AI's GPU power. It also shows how to expose an API endpoint from the model and plug it into the Crew AI framework.

Outlines

00:00

🚀 Introduction to Setting Up a Crew AI Team with Lightning AI

The video begins with an introduction to the process of setting up a Crew AI team using Lightning AI, a cloud-based code editor that facilitates collaboration and supports open-source models. The presenter shares insights from the Crew AI founder about the future of AI codebases and demonstrates how to build a team using Lightning AI. The video is sponsored by Lightning AI, and the presenter expresses excitement about building the team on this platform. The first step involves creating a new studio in Lightning AI, which offers a fresh environment for each session, simplifying Python environment management. The overall structure of the Crew AI is modular, with separate areas for tools, YAML definitions for agents and tasks, and a streamlined main.py file.

05:01

📚 Building the Crew AI Code Framework and Task Definitions

The presenter proceeds to build the Crew AI code framework, starting with the creation of a 'source' folder and a 'financial analyst crew' subfolder. Inside this, a 'config' folder is created to house the YAML files defining agents and tasks. Two tasks are outlined: 'research company task' for gathering stock information using a search tool, and 'analyze company task' for performing a financial analysis based on provided metrics. The tasks are defined with descriptions, expected inputs, and expected outputs. The use of variables allows for flexibility in the tasks, and the structure is designed to potentially enable API creation for controlling the crew based on the defined structure.

10:02

👷‍♂️ Defining Agents and Setting Up the Main File for Crew AI

After defining the tasks, the video moves on to defining agents in the 'agents.yml' file. Two agents are created: 'company researcher' and 'company analyst', each with a specific role and goal related to the tasks. The agents are configured not to delegate tasks and to provide verbose output for transparency. The presenter then demonstrates the creation of the main file 'crew.py', which imports necessary libraries and integrates the agents and tasks. The file also sets up the Gradio information for using the model, which will be powered by Lightning AI GPUs.

15:02

🔧 Finalizing the Crew AI Setup and Testing with Lightning AI

The presenter wraps up the setup by defining the 'financial analyst crew' in the main file, which brings together all the agents and tasks with a specified process and verbosity level. The 'main.py' file is updated to include the crew kickoff with 'Tesla' as the input company name. The video then shows the use of Poetry to manage dependencies and run the project. After resolving some minor issues with module installation, the crew is successfully tested, demonstrating quick and efficient operation. The presenter also explores the possibility of running the crew with an open-source model powered by Lightning AI, showing how to expose an API endpoint and integrate it with the crew.

🌐 Exploring Open-Source Model Integration and API Endpoint Exposition

The final part of the video focuses on integrating an open-source model with Lightning AI and exposing an API endpoint. The presenter guides through accessing studio templates in Lightning AI, opening a pre-configured studio for running Mixture of Experts (MoE) models. The video demonstrates the process of installing API Builder and setting up an API endpoint for the MoE model. The presenter then shows how to modify the code to use the open-source model by importing the 'oama' library and updating the model configuration. The video concludes with a successful test run of the crew with the open-source model, confirming its functionality and showcasing the power of Lightning AI's GPU support.

Mindmap

Keywords

💡Crew AI

Crew AI refers to a team or framework of AI agents designed to work collaboratively on specific tasks. In the context of the video, Crew AI is used to build a modular system for financial analysis, where different agents perform specialized tasks such as researching and analyzing a company's financial performance.

💡Lightning AI

Lightning AI is a cloud-based code editor and platform that allows for collaboration and the execution of AI models. It is highlighted in the video for its ability to manage Python environments efficiently and for providing access to powerful GPUs to run complex AI models like Mixol.

💡YAML

YAML is a data serialization language used for configuration files. In the video, YAML is utilized to define the agents and tasks within the Crew AI framework, allowing for a structured and human-readable way to set up the workflow.

💡Main.py

Main.py is a primary Python script file from which a program execution begins. In the video, it is mentioned as a short file that orchestrates the execution of the Crew AI codebase by bringing together all the defined agents and tasks.

💡Financial Analyst

A financial analyst is a professional who performs analysis of financial data to make informed decisions. In the video, 'financial analyst' is used as a role for one of the AI agents within the Crew AI team, which is responsible for creating thorough financial reports based on provided company financial information.

💡API

API stands for Application Programming Interface, which is a set of rules and protocols that allows different software applications to communicate with each other. The video demonstrates how to expose an API endpoint from an open-source model, Mixol, to be integrated into the Crew AI system.

💡Mixol

Mixol, or Mixture of Experts, is a machine learning model that combines multiple experts to make predictions. In the video, Mixol is used as an open-source model powered by Lightning AI's GPUs to perform financial analysis tasks within the Crew AI framework.

💡Grok

Grok is an AI model mentioned in the video as a part of the LangChain library, which is used to power the AI agents within the Crew AI framework. It is noted for its ability to be customized with different models for various tasks.

💡Poetry

Poetry is a Python package management tool that is used to manage project dependencies. In the video, it is used to install and manage the necessary libraries and dependencies for running the Crew AI project.

💡Plugin

In the context of the video, a plugin refers to an additional software component that can be added to a program to extend its functionality. The video shows how to use the API Builder plugin within Lightning AI to create an API endpoint for the Mixol model.

💡GPU

GPU stands for Graphics Processing Unit, which is a type of processor designed for handling complex mathematical and graphical calculations. The video emphasizes the use of GPUs provided by Lightning AI to accelerate the execution of AI models like Mixol within the Crew AI framework.

Highlights

Introduction to the optimal way to set up a Crew AI team using Lightning AI.

Lightning AI is a cloud-based code editor that facilitates collaboration and open-source model powering.

Building a Crew AI team with gp4 and mixol or mistol, showcasing the future of Crew AI codebase.

Creating a new studio in Lightning AI to start the environment setup.

The benefits of using Lightning AI for Python environment management.

Structuring the Crew AI code framework with a modular approach using YAML for agents and tasks.

Creating a 'financial analyst crew' within the source folder for task-specific organization.

Defining tasks and agents in separate YAML files for structured project setup.

Description of the 'research company task' for stock information analysis.

Explanation of the 'analyze company task' including financial metrics for analysis.

Agent definitions for 'company researcher' and 'company analyst' with specific goals and roles.

The importance of setting 'allow delegation' to false and 'verbose' to true for task visibility.

Creating the main crew.py file to integrate agents and tasks.

Importing libraries and setting up the financial analyst crew class with grock information.

Using Lang chain and grock to power the Crew AI project.

Running the project with poetry for dependency management and execution.

Troubleshooting module not found issues and installing necessary packages.

Successfully running the financial analyst crew and obtaining stock information and metrics.

Switching to an open-source model powered by Lightning AI to demonstrate flexibility.

Using the Lightning AI studio templates to quickly set up an open-source model environment.

Exposing an API endpoint with the olama mixture of experts model.

Integrating the exposed API into the Crew AI project to replace the grock model.

Demonstration of the Crew AI project running with the open-source model, showcasing its functionality.