Don't Miss This CrewAI Update to Transform YOUR AI AGents

2.58k views3552 WordsCopy TextShare
Tyler AI
👉 Join My Skool Community: https://www.skool.com/the-ai-agent-5174/about 👉 Book With Me: https://c...
Video Transcript:
in this video I'm going to show you all the updates that just came out with crew Ai and I'm going to go over some of the code for them so you can see how they actually work let's go and begin we have this new before kickoff and after kickoff crew callbacks you have support to precede agents with knowledge that's a capital K and we add support for retrieving user preferences and memories using mem zero now I covered meem zero in a previous video a few months ago with autogen and kind of an example of how to use it I'm going to go over another code example with crew aai using chat they fix some async execution we have some upgrades you know the update on the CLI Watson supported models that makes sense because you know not long ago they partnered with IBM uh they reduced they reduced level for Bandit uh fix some tests and updated documentation okay great great now let's go back to the first one I want to go over this a little bit so the new before kickoff and after kickoff crew callbacks well what is that well the first thing is you need to update crew Ai and then once you do that on the newest version when you go to you the command line which I have shown in my courses is that you type crew AI create crew and then the name of the crew you're going to be seeing these two other annotations or these two decorators inside of your crew base before kickoff and after kickoff and they're going to give you the example of where you can print something and it returns inputs right well what does this do and what this says is this is an optional hook to be executed before the crew starts that's what does before kickoff mean so if we come back to the main python file where we always kick off the crew so I have the school crew. crew. kickoff and we always give it some sort of input whenever this gets kicked off before it goes into the actual crew it's going to execute whatever is inside of this before kickoff first and then in the after kickoff after the crew is done and gets the output after all the agents and the tasks are completed then it's going to call this log results function print out the output and you know and return it as well okay so I just ran this like normal and as you can see here where this print out and this is the inputs right so I said print out the inputs of whatever is being given into this pull data example python function with the at before kickoff decorator now what's happening is anytime you call this function we're always getting the inputs from whenever we kick off the crew So when you say kickoff inputs equals inputs you know I'm getting this topic Microsoft stock price and that's what's going to be given here and all I'm doing is just printing that out and then just returning it right so whenever you return this whatever is returned here is then going to be sent into the crew to do everything that the agents and the task are going to be doing now remember it still has to be a dictionary still has to be in the same form like you see right here topic and then whatever the value of that is because topic is the parameter they're using in the task and the agents in the configuration file well you might be asking what is the point of this like why why would I need to do this if like I already have the input data when I'm running running my crew okay well that's a fair point but there's a couple things here well what if we have an NN flow but then at some point we call a backend server that has a whole crew of maybe 8 to 10 agents they need to do something well you could manipulate the data possibly to send it to the crew and then you know the crew can form it into a dictionary which I'm going to show you as an example in just a minute or as you can see they have here whatever you get from n8n you can just send that send that here then we can actually pull data here you can have another API call here or whatever you need to do to change the inputs to actually then send off to the crew and actually in my school Community besides the crew AI Master course where I update sections of this every week There's also this no introduction where you do get a free gift where I show you how to use n8n and crew AI together as a full flow right this is before we actually kick off the crew so you can manip manipulate the data that's coming in here however you want before the crew actually starts and the same thing with after the kickoff right if you're going to send data back to the NN flow you can manipulate it here because it's I in my opinion it's much easier to do that with code you can do that here with all the libraries that you need send it back to n8n and then you know you can continue your workflow if you want but either way this is a way to no matter what we're you know we're getting data whether it's from the front end we can make sure that data is manipulated correctly massage it so it's into a dictionary or a list of dictionary that the crew needs okay so now I'm going to show you what I mean is this if I comment this out and then in the Run function here I'm passing in Microsoft stock price that's coming in here as a fir request parameter I'm giving that to the school crew and we got an error you know it must be a mapping not a string so how we can fix that we don't actually have to fix that here right we can just go back to our crew and you know we're printing we're still printing out the input is just Microsoft stock price the value right there's no dictionary so instead I could say return and then whoop I can say topic and then I want to pass the inputs whatever I know it's just going to be a single string right but you could even do something like you could comma separate out the strings however that's coming in we could manipulate that here but this is want to show you a simple manipulation so the inputs is going to be coming in as this Microsoft stock price but I'm going to be manipulating it or modifying it into this dictionary to then be sent off into the crew and then this will Works let's go and clear this and as you can see Microsoft stock price senior data researcher and now it's running because we manipulate the data to properly send to the crew this is a great feature and this is a perfect example of how to use that so the next one was knowledge right so you might be asking well if I'm just giving knowledge to an agent which is what we're doing here this is what they added you can give knowledge to an agent so if you had 10 agents you can give different knowledge sources to all these agents and then just for that task that they're going to perform or multiple task then they'll have more of what to know and how to solve it right but you might be thinking well we already do that with context right for each agent you already give a backstory you already give like you know a a goal and all that stuff right so the agent kind of knows what to do well the problem is you know that's text right you can add text as context and that's as part of the context window what knowledge is whenever you kind of dig a Little Deeper is actually using a chroma database to then store the vectors so that whenever you give it the knowledge then it's going to retrieve certain parts of the knowledge for whatever you may need to solve and it's not just text you can add PDFs spreadsheets and other types of sources just to this agent and I really think this is a great resource on to make your agents more powerful and execute better so let's just go over this really quick so knowledge and crew AI serves as the component for enriching AI agents which I kind of just talked about um it enables a to access and U utilize structured data sources during their execution processes making them more intelligent and responsive um and like it's saying here additionally we have specific tools for generating knowledge sources for Strings text files PDFs and spreadsheets um they actually have a class here that you can expand upon as well in here I have one called sampl knowledge.
py right so in this content here I just have this content stream my name is Tyler in 36 live in Florida I also rely know what I'm doing and I drink lots of coffee so I had the string Source right that the string knowledge source so the content is that then I just kind of you can get the metadata to kind of um you you can give it like more access to certain preferences right so this one's going to be personal just to me not like about anything else this is just personal to me then I just create an agent a task and a crew but in the crew here this knowledge you know the sources are the string source and the metadata the preference is personal okay so the question is where does Tyler live and what does he do so then that agent is going to have to go to that knowledge source and then uh and then Retreat then answer the question that way so the final answer is Tyler lives in Florida although he mentions that he rarely knows what he's doing a characteristic that highlights a sense of spontaneity and blah blah blah he also drinks lots of coffee which could indicate a busy lifestyle or preference for caffeine probably the second one but then what we can do is you can you can modify this to like whatever it is right it could be a huge file in the back end you know it's using chroma database as a knowledge source so then it's going to retrieve specifically what it needs a little bit more effectively than just giving it this big context window right then you have to worry about you know expanding your gaml file properties for the configuration and then in the last coding example they talked about uh integrating mem zero which again I have talked about before in a previous video and I really really like this even if I if I go to my request here this is the m zero dashboard right even um you know you have like I have the free plan right so you get like a th000 monthly API calls you know I've used I've used a lot recently right you want to do some testing um with the user ID that I'm about to show you okay so what is mzero it's a basically a memory database and it has this web UI where you can see the actual memory stored for the user and I'll I'll show you that um it's it's it's free to sign up you just come in here you'll go to the API Keys get an API key and you're basically ready to go so let's look at a code example so if I go into my crei m0o py file let's go a and clear this let me minimize this a little bit more so we can see I'm basically creating a chatbot within crew aai just using a while true Loop but I'm going to show you how this works right and this key will be deleted by the time you see this but what we need to do is you need to import m zero and they start off with this memory client class so you initiate this uh give it the API key and then again I just have this is really similar to the previous uh the previous example so I just have an agent a task and a crew although with the task I have a search m Zer tool which I will get to in just a second but and then I at the bottom I have a while true right so this is just going to constantly chat I basically give a question and then it's going to kick off the crew with that question and it's going to print the result and then what I do is in the mems of your client I'm going to add that question it's not necessarily a question it probably should be like um my input so I'm going to add that input to a specific user ID called Tyler and just so you know I ran into this error this is not going to work if you don't do this there are two versions 1. 0 1. 1 you need to make sure it's set to version 1.
1 or again you will run into errors it needs to be 1. 1 at least used with crew AI okay so use 1.
Copyright © 2024. Made with ♥ in London by YTScribe.com