The RIGHT WAY To Build AI Agents with CrewAI (BONUS: 100% Local)
Optimal Setup for Crew AI Team
In this section, the speaker introduces the optimal way to set up a crew AI team using Lightning AI, a cloud-based code editor. The focus is on building a crew AI code framework and structuring the team efficiently.
Building the Crew AI Code Framework
- To begin, create a new studio in Lightning by signing up for an account and accessing free credits.
- Set up a code Studio within Lightning to leverage its cloud environment, eliminating python environment management issues.
- Structure the crew in a modular way with separate areas for tools and yaml files defining agents and tasks.
Creating Task Definitions
- Establish a source folder within which specific crews are named; e.g., "financial analyst crew."
- Create subfolders like "config" to organize task definitions effectively.
- Define agents and tasks by creating agent.yml and task.yml files respectively.
Defining Tasks for Crew AI
- Structuring tasks like researching specific companies (e.g., research company task).
- Detailing parameters such as descriptions and expected outputs for each task.
- Crafting tasks like analyzing company data with specified metrics for financial analysis.
Setting Up Agents
Financial Researcher Agent Setup
In this section, the setup for a financial researcher agent is discussed, including naming conventions, roles, and goals.
Naming Conventions and Roles
- The name of the agent is "Company Researcher," with the role named as "Financial Researcher." Explicit mention of using search tools is made to enhance efficiency.
Delegation and Verbose Settings
- Delegation is set to false to prevent task delegation. Verbose setting is enabled to view all agent activities.
Agent Modification
- The second agent is created by modifying the first one. The new agent is named "Company Analyst" with a goal to create detailed financial reports based on provided company information.
Agent File Creation and Setup
This part covers creating a main file that integrates agents and tasks together for a cohesive project setup.
Importing Libraries
- Relevant libraries such as
agent,crew,process, andtaskare imported from Crew AI project for file creation.
Grock Integration
- Grock integration through Lang chain is emphasized for powering the project. Installation instructions are provided if needed.
Creating Crew Base and Definitions
Setting up crew base, defining agents, tasks, and crew for seamless project execution.
Crew Base Creation
- A class named "Financial Analyst Crew" is created under crew base to manage agents and tasks efficiently.
Agent Definitions
- Definition of agents like "Company Researcher" and "Company Analyst" are outlined with configurations linked to specific models for varied sources usage.
Task Definitions and Crew Formation
Defining tasks such as company research task and analyze company task along with forming the crew structure.
Task Definition
- Tasks like company research task and analyze company task are defined linking them to respective agents for execution.
Crew Formation
- The crew formation process involves integrating all agents, tasks, setting sequential processing mode, and enabling verbose output for comprehensive results.
Financial Analyst Crew Setup
In this section, the speaker demonstrates how to set up the financial analyst crew by importing necessary modules and defining the main file.
Importing Modules and Defining Main File
- Import
financialanalystcrewmodule.
- Define the main file by passing in inputs, such as the company name (Tesla).
- Obtain a Grock API key for further setup.
Setting Up Tools and Libraries
This part focuses on utilizing existing tools within the financialanalystcrew library and setting up SEC tools for analysis.
Utilizing Existing Tools
- Copying SEC tools from examples library.
- Creating a new file named
SECtools.pyand pasting existing code for functionality.
Poetry Integration and Project Execution
The speaker demonstrates integrating Poetry for project management and running the financial analyst crew project.
Poetry Integration Steps
- Installing Poetry using
pip install poetry.
- Customizing Poetry settings with financial analyst crew name.
- Locking dependencies with
poetry lockand installing them withpoetry install.
Running Financial Analyst Crew Project
This segment covers running the financial analyst crew project, resolving module issues, and observing successful execution.
Running the Project
- Resolving module not found issue by installing LinkChain Grock.
- Successfully running the project, obtaining information about Tesla's stock price, market cap, news, calculations, ratios, and metrics.
Exploring OpenAI Models
Exploring open-source models powered by Lightning AI to enhance capabilities beyond Grock integration.
OpenAI Model Exploration
- Accessing Lightning Studios templates page for preconfigured models.
- Observing GPU usage options for different model requirements like Mixol.
API Integration and Model Execution
In this section, the speaker demonstrates how to integrate an API into the code and execute a model.
Integrating API and Executing Model
- To integrate the API into the code, import
oamafrom Lang chain.llms.
- Comment out a line of code and create a new instance called
olama_mixol.
- Running the model might be slow due to its size, but it shows that the integration is working.