CrewAI Tutorial - Next Generation AI Agent Teams (Fully Local)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this is crew AI an awesome alternative to autogen that allows you to set up entire agent teams to execute tasks automatically it is completely open source and you can power it using olama and local models and it also has native support for Lang chain so you get a ton of functionality right out of the box so I'm going to show you how to install it I'm going to show you how to set it up and we're going to play around with it let's go crew aai was released not too long ago it already has 1300 Stars a bunch of forks more people contributing to it and the rate at which the author is adding functionality is tremendous so this is the GitHub page it's called crew. it's super easy to install I'll show you how in a moment here's some example code that we can do to set everything up I'll walk you through that and some of the key features role-based agent design so customize agents with specific roles goals and tools autonomous inter agent delegation which is what we talked about at the beginning agents can autonomously delegate tasks and inquire amongst themselves enhancing problem solving efficiency it has flexible task management and it is process driven it only supports sequential task execution but more complex processes like consensual and hierarchical being worked on and this is going to be an intro tutorial we're just going to get it set up and working with both gp4 and a local model and then I'm going to create a follow-up video showing you how to do more of the complex stuff like creating your own tools using lank chain tools caching and complex delegation this video is brought to you by monster API the best place to integrate the latest AI models at a fraction of the cost while it typically cost around $180 to generate 5,000 images using sdxl you could do so for only $39 with monster API check it out at monster api.ai so I opened up my vs code I have a new file that I just created called crew example.py I'm going to click this button in the top right to toggle panel and that'll open up my terminal within vs code down in the bottom right I've selected python version 3.1 1.6 and I'm going to try it without even creating an environment with cond so let's get started so the first step is to install crew AI pip install crew aai and then just hit enter okay it looks like that was successful great next we're going to import everything we need from the crew AI Library so from crew AI we're going to import agent task crew and process and all of these things will make sense as we go through the code and to start I'm going to show you how to do this using gp4 but and I'm going to show you how to power it using olama and a local model next we're going to import OS which will allow us to set our API key securely and here what we're going to do is actually set the API key so os. Environ and then open AI API key in quotes and then we're going to go grab our API key now so on the open aai API Keys page if you don't already have an open AI account and a developer account go ahead and sign up we're going to click create secret key right there I'm going to call it crew AI hit enter and I'm going to copy that right there and I am going to revoke this key before I publish the video so right here where it says your key we're going to replace that with our actual key and then save now the first thing we need to do is start defining the agents and it's so easy let me show you and so what we're going to do is we're going to create a team of agents to go out do research on the latest AI Trends and then write a blog post about it so first let's create a researcher so researcher equals and then capitalize agent and this just references this part of the library right there first we're going to assign in a role which is really just like a name so rooll equals researcher then we're going to give it a goal and for the goal we're going to say research new AI insights next we're going to give it a backstory which is basically just a system message but it's a better way to describe it you are an AI research assistant next we're going to set verbose is equal to true and that'll just give us more information as the agent is running and allow delegation and this is where you start to see the difference between crew Ai and autogen there's no real way to control delegation in autogen at least the last time I checked but now we can and we don't want the research assistant to delegate any of the work so we're going to say false and the last thing we could do is input an llm but by default it's going to use chat GPT so for now I'm going to remove that because we don't need it then I'm just going to save so now we have our researcher and actually I forgot to include the ER there so I'm going to go ahead and add that and save so now for our blog post we actually need an agent to do the writing so let's create a writer agent and then we're going to need the same things role equals writer goal equals write compelling and engaging blog posts about AI Trends and insights backstory you are an AI blog post writer who specializes in writing about AI topics for Boose we'll also keep that as true I want to see everything going on and allow delegation we're going to also say false because I don't want the writer to delegate any work and that's it we have a researcher and a writer and that should be good now let's create our tasks and we're going to create two tasks task one and task two for task one we assign it using capitalized task and that creates the task based on crew ai's definition and first we write a description so description equals investigate the latest AI Trends and for that task we can assign an agent so we say agent equals researcher now it's already easier than autogen in this way for each task we can actually Define which agent should be accomplishing that Tas task where for autogen what I've noticed is it's really hard to assign agents to specific tasks so this is great for task two of course we're going to want it to actually write a blog post so write a compelling blog post based on the latest AI Trends and then we're going to assign the agent to be the writer and I actually have to end the quote right there and there we go so we have task one investigate the latest AI trends task two write a compelling blog post based on the latest AI Trends all right now we actually have to instantiate the crew and again this is going to be a little bit different than you're used to with autogen so let's create the crew and we're going to use capitalize crew as the instantiation for it we're going to put our agents into the crew as an array so we're going to say researcher comma writer we're going to give it our task task one and task two verbose equals and we can either set it to one or two depending on how verbos we want it so I'm going to want it as a two and then we can set the process and currently the only process is sequential but they're adding other processes later so process. sequential and basically all that means is it's going to execute task one and then execute task two and that should be it for the crew definition and that's it really the next thing we have to do is just kick off the process so we do result is equal to crew. kickoff and I'm going to I'm going to click save and let's try it out let's see what happens so I'm going to click play in the top right and there we go working agent researcher starting task investigate the latest AI Trends so thought action action input and so since I didn't provide it with any tools it doesn't know which tools to use and it's going to attempt to complete it without using any tools and so basically it's just using GPT 4 prompting to actually get these topics so here it is Final Answer AI in healthcare AI in cyber security etc etc then it passes all that information to the writer and now the writer is writing a blog post and so what I really like about crew AI is how easy it is to chain these tasks together and to assign different agents to different tasks and let them delegate to each other when necessary and here it is the whole blog so we have a blog post perfect and finished chain so now it's done and it exits out so that was really simple I know but the more sophisticated use cases are going to come in my follow-up video and let me know the use cases you you want to see in that follow-up video I think I'm going to put together a stock analysis crew and maybe even a trip planner crew and they're going to be using Lang chain tools they're going to be using custom tools I'm super excited to show you that but the last thing I want to show you today is how to use a local model so you don't need to use GPT 4 and that is very easy now I already showed you in a previous video how to use oama so I'll drop a link to that video in the description below if you don't already know how but assuming you do the first thing we're going to do is download open Hermes which seems to be the best model to use with crew so olama run open Hermes hit enter and now it should download the model all right there we go it is up and running and remember with olama you can have multiple models running at the same exact time and especially because crew aai Works sequentially through task you can assign different models to different agents and run it all at the same time with basic consumer Hardware okay now what we need to do is actually tell the different agents Which models to use and so we're going to define a new model at the top here and I'm going to say _ open Hermes equals and then o Lama and then open PRS and then we're going to say model equals agent and we also need to import ol llama so let's remember to do that so at the top I'm just going to say from Lang chain. llms import olama and that should be everything we need so we import olama from Lang chain then we create a new olama model called Agent it is going to be open Hermes and we come down here and for the agent we're going to say llm equals and then AMA open Hermes and then for the writer we're going to do the same thing come down here llm equals boom then we're going to hit save and we're going to run this again now it should be running this completely locally now so top right hit play and let's see it run okay so I got one thing wrong rather than model equals agent of course it's model equals open Hermes okay now that we assigned an llm to each of the agents we're going to go ahead and click play and there it is now we're using our completely local open Hermes model powered by olama and there we go it's done so now we're running it completely locally obviously when you're using local models you need to play around with all of the settings to make sure you're getting the most out of them it's not as plug andplay as a GPT 4 would be but it is working and it's showing that there so again in our next video I'm going to be showing you more sophisticated use cases we're going to create our own tools we're going to be using laying chain tools we're going to do complex delegation I'm so excited let let me know in the comments what you want to see as part of the follow-up video to crew AI if you liked this video please consider giving a like And subscribe and I'll see you in the next one
Info
Channel: Matthew Berman
Views: 126,214
Rating: undefined out of 5
Keywords: crewai, crew ai, chatgpt, chat gpt, gpt, ai, artificial intelligence, openai, llm, large language models, ai agents, agents
Id: tnejrr-0a94
Channel Id: undefined
Length: 10min 38sec (638 seconds)
Published: Fri Jan 05 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.