Introduction to AgentBuilder | Automate your Agents with AutoGen

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
a question had was what if we had autogen create agents for us and of those agents it selects which ones are best for the task that we ask it to execute well I'm going to show you that today with something called Agent Builder let's get started all right well what is Agent Builder well simply this means that aen is going to give us a way to provide a list of agent names and then autogen is going to do the rest we're going to ask it to build something from a specific task and it's going to create all these agents with the system messages for each of them and then it's going to select which of those that we want to use or it wants to use to execute the task okay well the next thing is what is the process that we're going to be coding well the first thing is we have the configuration down like the config list and the llm config which we have done before and then finally we have a way to generate the agents then they're going to be saved into a Json file and then we're going to create the agent Builder which is just a class that we instantiate and then we call the build from library function which is something new and then finally we have executing the task and what this is going to do is when we execute the task it's going to go back back through generate the agents create the agent Builder and then select which ones are best and then finally when it selects the agents execute the task well let's start creating a new project and start coding all right go ahead and open up your IDE I use py charm Community Edition which is free so I'm going to go ahead and file new project and let's just name this agent Builder so now I'm going to hit create okay there are a couple libraries that we need to install so just open up your terminal and you're going to say pip install Pi Pi autogen and chroma DB okay this is needed for agent Builder so go ahead and run that whenever that's done it's going to take a couple minutes because chroma DB has a lot we'll come back okay the first thought we're going to create is something called utility and what's is going to have for us is all of the tasks the system prompt for all of the agents which is going to be one prompt and then a list of all the agents we would like autogen to create for us let's go ahead and do that going new python file and call it utility what I'm going to do here is I'm just going to copy and paste all this because we don't need to go through everything here but uh what I'm going to have is a building task an execution task this is a system prompt that autogen is going to use whenever it creates all the system messages for the agents which when we get there I'll show you what I mean and then something just called a position list and these are the names of all of the agents we want autogen to create for us but we're not going to actually uh create the system messages for each that's what this agent system prompt is for all right so now let's create our main python file and then this will make little more sense so come up here new python file and just call it main there's a couple things we need to do here is we're going to import Json import the class or the python file we just created and so import utility and then import autogen and then finally from autog gen. agent chat. contribution. agent Builder import agent Builder okay now that we're done with all the Imports there's some variables that we need to create and then the config list so let's get started first thing is we going to have a variable called config file or EnV we're going to call this o AI config list and we'll we'll end up creating a file called this which will store the API key in the model and then next thing is we'll have llm config is equal to and then temperature we'll just make this um let's let's make this how about 0.7 0.7 okay and then we need our config list variable which is going to be autogen and we're going to use a function from autogen to get it from Json so config list from Json and we just need to pass in the name of it which is we have stored in the variable up here and then we need to pass in a filter dictionary and we're just simply going to have model and then what we do is we just give the model that we actually want to use and this is just going to be GPT -4 okay so then whenever it goes to retrieve the model from this file oi config list it's also going to retrieve the API key for this GPT next we're going to have position list is equal to utility. position list and then the agent prompt is going to be equal to utility. agent system message prompt so we just have I just have variables in here so it kind of maybe makes a little bit more sense but we're just getting all these from the utility python file that we just created and next what we need is whenever autogen creates the agents it's got to store them in a Json file so we need to give it a path and the name so we're going to say library path or Json and this is the name of the parameter when we get to building the agents that it'll use so I just use the same uh variable name is going to be equal to you can say just do slash and it will be within the agent Builder directory up here so it'll just create it here for us and then the name we can just say um agents. Json and then we're going to need something called a build manager which is autogen doop AI wrapper and it's just a wrapper class config list is equal to our config list and then we're going to have a system message list is equal to just an empty array right now and we're going to append to this all the system messages and the names of each agent that autogen creates for us now that we created that what we need to do do is create the open AI config list file so create a new file config oore config list and you're just simply going to have an array here this and we're going to say model GPT 4 oops GPT T4 jeez if I can type and then API key and then sk- whatever your API key is you're going to put it here so this is going to be our oi config file that we're going to use to actually run everything all right now what we need is the function to generate the agents so we're going to say def generate agents for position in position list so this is going to iterate through all of the names of the agents that we have provided and then we're going to say response agent system message is equal to and now we're going to say build manager the one this open AI wrapper up here we're going to say build manager. create and then messages this is going to be an array and we need a role and the RO is going to be user and then we need the content and this is going to be agent _ prompt. format and this just going to and this is just going to format the variables that we're going to pass in here so the position and then the default CIS message is going to be equal to autog genen and we're just going to pass in the assistant agent. default system message from this create function which is from the open AI Raptor we just say do choices get the first one message do content and all this create method from the build manager which again is just open AI wrapper this is basically sending us a completion which a completion is just what the model generates in response to our input and then finally we're going to say system message list. append and then we need a few things here we need the name which is going to be the name of the agent and then we need the call the profile which is going to be the response that we just got above and I understand this is a lot so far once we run this this will make more sense okay so just keep following along and we'll get there and the last function we're going to create is just called start Task So Def start _ Task this is going to uh we're going to take in execution task which is just a string and then the list of the agents okay and this is probably something you're going to be more familiar with so group chat is equal to autog gen. grroup chat and then we say agents equals the agent list that we passed in and then messages we're going to leave empty array and then max round let's just set to 12 and now we have the group chat manager so manager is going to be equal to autogen dog group chat manager and then we say group chat is equal to the group chat and then llm config is going to be equal to the config list so oops config list property and then config list and then finally and then what we can do to pass in the llm config is you can just say star star llm config and this is kind of like the extra parameter that we'll have oops made a mistake there that's supposed to be a colon then next thing we need to do is grab the first agent in the list because we want to initiate the chat with it so initiate chat then manager and then message is going to be equal to the execution task that we have provided as a parameter now we got all the variables set up and the functions let's start executing these functions whenever we go to run this file so the first thing is we're going to have generate unor agents so this is going to generate the agents for us and then we have json. dump and we're going to provide the system message list which was created from the generate agent so it's kind of really agents and then we want to open Library path or Json so this is the path of the variable that we had created up here so we want to store everything into this Json file here so now that we come back down and then you just have W for right and then finally just indent equals 4 okay just kind of format a little bit right now we're going to have a a new variable called new Builder which is going to be now we're creating the agent Builder object so agent Builder and then we need to pass in the config or file V so we already created that this is the parameter for it so config file or EnV maybe would make a little more sense if I if you highlight over or at least here or you can like kind of Click into it okay so we need the config file or EnV which is the environment of the configuration and then we're going to need the Builder model so as you can see it defaults to gp4 so we already say gp4 but you know you could give it something else so also the agent model defaults to gp4 so if you want to give it a separate GPT like 3.5 turbo or some GPT 4 preview you could set that um you could set that in the agent Builder I'm going to go ahead and just uh use those this is just so you kind of have an idea of what to do next so I'm going to create these I'm going to create these parameters for the agent Builder so Builder unor model is this is going to be equal to GPT 4 and then the agent model so the Builder model which builds the agents and then when the agents are chosen what model do we want to use for those agents so this will be gp4 as well just for now and then we're done okay now we created the agent Builder the next thing is we need to execute that build from library function that I mentioned before next we're going to say agent underscore list comma and underscore and this going to be equal to new builder. build from library okay this underscore here this means that the build from library can it will return two different things but we only care about the first one which is the actual agent list all right so so what do we pass in here well we're going to pass in the utility dot which is from the file okay we're going to pass in the building task okay to build the agents the library path or Json and then this is the path where we stored and generated all the agents and then finally llm config and then I'm going to say saved path is going to be equal to new builder. saave and then we're going to give a path to save uh all everything it's going to do for this iteration of generating the agents um creating the prompts uh everything here is going to be saved in the file that I'm about to create so we're say Auto genore aent AB for agent Builder all right I'll show you what this is in a second and then finally we can start the task so startor task and then the execution task that we defined is utility. execution task and then agent list is going to be equal to agent list and then finally you can say new builder. clear all agents and this is just going to clear all the agents from the cache okay so that the next time through it can create new ones that was a lot I know I know but thank you for following along now I'm just going to grab my open AI key insert it here and we're going to run it and see what happens okay now I just ran it and we're going to see it in action but one thing before we get started is this because of the update to 0.2.0 if you have Docker running fine perfect it's going to work however if you don't have Docker running or you don't even have it installed what you have to do before you run this this is you say export Auto genore _ Docker equals false and then that'll locally execute the code if you don't have this in the last video I had last week I talked about this update and it could be breaking so either put this uh execute this in the terminal before you run it or if you have docor running then you're fine okay but do that and then run your main P python file now I already run this because I've ran into that issue and what happened was it created this agents. Json file for me which I'll look at in a second looking for suitable agents in the library which is there and it found for it found sof developer programmer IT specialist and AI engineer okay not I don't know necessarily know if we need the AI engineer because all I asked it to do was to create a python function that reverses a string okay but either way then it generates the system message preparing the system message for each of them creating the agents which basically means it's now it's going to use those agents to perform this task and then it's building the configuration that's going to be used for this run through um to create the python function that reverses a string so now we have the software developer who has this code here that reverses a string and it documents it right so it's saying takes the input and then just reverses it um and then it just you know all you do is take colon colon negative 1 and it'll just reverse the string for you um and then it says the user con basically the user is going to execute the code and then the programmer says seems you didn't provide any code to execute blah blah blah the function is ready to be used okay so then the programmer's talking then it goes back to the user the user saying okay well this doesn't exist and then the software developer um gives you the full code and and then the test function also so now the user does it it works great and then finally we're terminate so as you can see we didn't even get to the AI engineer okay and that's something I want to talk about part of this you know this is great it still needs some f tuning it's not perfect but it can still solve the task right and then finally here it says all agents have been cleared so the next time around if you want to do the same thing you can probably use the same cash it's still going to create new agents for you so you might still get a little bit of a different outcome now if we look at the agents. Json here you can see here it created we we provided the name but then it created the system message for each of these okay so if you just scroll down this whole Json file it created all of these for us and it selected four of these right here you can see is the IT specialist the AI engineer uh let's see we have the programmer and the software developers right here okay so it selected those for us and you can give it however as many names as you want or different names whatever it is okay and then for this specific run it saved it in this autog genore uh autobuilder that file that I told it to save to and then it says be able to be able to create a python function with documentation on how it works so this is the building task okay this is what I want how like what I wanted to build all right and then the agent configuration is see the name the model the agent is used and then it created this system message for the for the software developer and the description okay and it did this for all of them all right see the coding set to true the default llm is 0. 7 and then the code exec execution configuration is the working directory is group chat used Docker is false because I had it export the autogen used Docker U environment variable to false and then this had a default timeout okay and this is the configuration it used to run or execute the task okay so we just created something with agent Builder which as you can see is kind of awesome it allows you to just give a list of names and a single prompt which which you can copy and use and you give it different names to do different tasks and it will try to perform that test for you by letting autogen select which which agents make sense for the task that you want to perform this is just a basic rundown of how to do something with it how it works I'm sure this going to be improved as you can see it didn't even use one of the agents it didn't even use the AI engineer so there's still a lot of improvement that needs to be made but the concept the concept is good the concept I really like that we can allow AI to do more of the task for us including which agents need to solve the task okay if you have any questions or comments leave them below there will be more videos here for you to watch about autogen please like And subscribe and I will see you next time
Info
Channel: Tyler AI
Views: 4,270
Rating: undefined out of 5
Keywords: ai, chatgpt, ai agent, ai agents, chat gpt, gpt 4, tutorial, ai automation agency, ai tools, autogen explanation, autogen explained, automate agents, agent builder, software engineering, auto gen, autogen, microsoft autogen, auto gen tutorial, how to code, microsoft, ai agents explained
Id: qaTID9LRlk8
Channel Id: undefined
Length: 17min 42sec (1062 seconds)
Published: Thu Feb 01 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.