my name is David Andre and here is how to build anything with open AI swarm this is a new AI agent framework from open Ai and by releasing it they are telling us that they believe AI agents are the future so if you are not building AI agents now treat this as your wakeup call so here's my promise if you watch Until the End you'll know exactly how to Future proove yourself with the power of AI agents so here's the difference between one agent and a team of Agents having multiple AI agents allows you to specialize each of them for a single task this lets you achieve far more than you can do with just ch gbd for example each agent can have a different API call to visit a website to edit a file to call a prospect to email a client anything you can imagine but in general it is better to start with one AI agent do not add complexity unless it's necessary now you might be thinking but David how can I actually benefit from this well here are a few practical ways agents can save you time find more leads do your research respond to customers automate repetitive tasks brain ideas write your copy and so much more in 18 months and I'm certain of this every single company and individual will have teams of AI agents working for them that's why you need to get in now real quick if you want to build a business with AI agents then make sure to join the new Society inside I'll teach you step by step how to build your first AI agent and how to make money with it you can do this with zero coding experience in just 30 minutes day it's the first link in the description now what even is an AI agent framework simply put a framework makes makes building AI agents easier and faster with open AI form specifically you can have ai agents delegate tasks to one another so let's say one AI agent is more suited for a task you can have that linked as a function in the Swarm but you'll see what I mean in a moment now it's built on top of openi chat completions API which is basically the standard API for gp4 01 and all the other models so you will find the syntax super familiar and easy to follow now here is why you need to be like Napoleon this is one of my alltime favorite quotes I engage and then I figure out what to do Napoleon bonapart you the people watching this you are smart your problem isn't not knowing what to do or not knowing how to code your problem is lack of action so stop overthinking stop overpreparing stop over researching and just get started so now let's get to building this is the main GitHub repo from open AI about the swarmm system it is still in Early Access but look at the syntax isn't it's beautiful anybody can follow the syntax you don't have to programmer to understand this right like you define an agent you give it a name you give it instructions and you give it functions like super simple guys so I'll show you how to implement this and yeah I'm going to link this below the video as well let me open up cser actually this is the code for my new AI startup by the way if you want to see exactly what I'm doing and watch me step by step reveal all the steps I'm doing all the steps I'm taking then again it's in the new Society in the classroom you simply click on start your era startup and in there you'll find daily reports progress reports from my journey of building my a startup anyways let's go back to cursor then click on open a folder all right so here I have an empty folder let's select it boom now as you can see there's zero files nothing so I'm going to create a new file right click new file main. py let's go back to the GitHub and follow the instructions open a tells us again this is my first time using the framework so you'll see me fail you'll see me make mistakes and you'll learn from them but I'm guarantee you this is not this is not a crazy thing you can do this even if you have lack of time even if this is your first time building agents install requires Python 3 10 plus 11 so we need to set up our environment I'm going to be using K so let's do anaconda prompt by the way you might be thinking like oh my God David I don't know how to use K I don't know I don't know how to use cursor don't worry I have all of these tutorials inside of the new Society there is a really 50 minute plus Advanced cursor tutorial andly just this single module is worth joining new Society 4 so again it's the first link in the description anyways let's jump into Anaconda prompt and let's create a new K environment K create dasn I'm going to name it swarm and let's do python equals 3. 11 as they said on the GitHub we need at least 3 10 plus so 311 should do enter and if you're like oh my God David I don't know how to create a new K environment well this is exactly why use cursor in cursor you can do control l or command L and ask chat right how do I create new K EnV and it will tell you the command K create name boom this is your name python 38 whatever version of python you want to be using so okay we have created a new environment let's Now activate it K activate activate swarm then I'm going to copy these pip installs okay let's do this copy paste and actually inside of curs as it's showing an error select your interpreter we can select python interpreter and we can select our new one swarm right here boom let's just put in a comment right here so now if we go in here these are all the packages right identic yl this troll so this is you know you don't have to worry about this because with one line this single line open a already installs everything we need all dependencies we need usually stored in requirements.
txt file so now that we've selected the environment inside of cursor which by the way cursor is built on top of vs code so if you've used VSS code before it'll be super familiar but the beauty about cursor is that you can literally speak to it in plain English right so I can we can just start copy pasting stuff from the usage right so let's not reinvent the wheel let's follow GitHub this is why you should always look up documentation and githubsign it tells you what to do you can just copy paste code from the developers so this is why documentation and following the readme files is important so we can just get started from swarm input swarm and actually we can tell crer um to add explanatory commments right so we can control x x add an explanatory comment above so that you know let's say you don't know anything about programming and you want to understand what the code does CER will let you do that so import necessary classes from sword simulation okay let's change that to from open AI swarm all right let's go next now we Define the client all right boom and then I'm going to start writing comment in initialize the Swarm client beautiful so this is another thing about cursor you start writing anything and it already predicts what you wanted to say okay so what I'm going to do is I'm going to build a sales agent let's first try this simple example and then we will build sales team of agents that you can all of you if you have a website or if you want to sell it to a client you can can do that okay so let's add a comment on here Define a function to transfer yes so now we can just copy both of these agents so this is the test demo right after this I'll build a proper one maybe we can rename it to let's rename this to test. py all right so here we Define our first AI agent it's named agent a his name is Agent a so it's super simple literally you give it a name this is instructions also known as the system prompt you are a helpful agent again just a demo from open AI they didn't anything crazy and this this is how you do the functions right so here this is the function we also known as a tool where it can it has the ability to delegate to Agent B Agent B is a simple again a super simple agent that can only speak in high cus so if you don't know High cus just a short poem basically so again this is a demo from open AI so to keep it to show you how easy it is to use use the framework next you will use some you'll build something practical that you can use in your business or sell for real money all right so then once we Define the agents we need to run a response again super insanely simple so now response equals cly on run so as you can see this is the very similar syntax to open AI uh chat completions API and then we see which agent we want the response from right so agent we do agent a so we're not calling Agent B that's up to agent a so agent a decides if it's good to call Agent B so now in our prompt we say I want to talk to Agent B so obviously super explicit but agent a will delegate it to Agent B actually let's change it a bit right so Agent B could be I explain everything in let's do like 700 700 English okay something like this and then I want talk to Agent B have him explain llms okay let's this this should be interesting actually let's run it save contrl s and run and we have a nice error what is this oh we don't have the open AI API key amazing so something obvious but I forgot it so let's go to platform. open.
com API keys if you don't have uh your account simply use the same one as you have in chat GPT so on the top right you should be logged in then once you log in takes 20 seconds super easy you click on uh on the left API Keys again platform I'll leave I I'll leave the link to this in the description uh create a new secret key let's name it um new Society create new create secret key copy let's create a new file let's name ITV and now we need to name it exactly open AI API key this cursor is already helping us with that and now we replace the syntax with just new API key so now when I save this by the way do not share your API keys with anybody I will delete mine before uploading the video now we can run it again let's run it and we don't get the error which is good meaning our agents are working so this is explanation of llm in 1700 English how though wishes to converse with M humble self regarding those metaphysical constructs knows as large language models does though so you get you get the point right so it works maybe we should uh one thing we could do about cursor is go to the composer section also control I you can pull it up and say add more DB bu print statements so that we know what's happening don't overdo it though and the reason I want to do this because we only waited like when we ran the program we just waited until we got the response right so that's kind of kind of long okay so uh I think this is good we can just accept all and then we can rerun it and we will get way more so swarm CL initiated engine I created starting conversation me yeah so we're getting the inputs before before you get the final response I like that now we can actually have it create a new file and this is going to be a okay so let's let's use the power of cursor this is why again I love curser if you want to dive more into it check out the advance tutorial we have in the new Society so this is what you can do right you can tell it now create a new python file use the exact same syntax as we have in and I'm going to T tag test. py but leave the agents empty create four different agents um four different agents for different agents I think that's good only keep the most useful debug print statements again make sure to use the exact same formatting as test. py enter and cursor can not only write your code it can also create files and it has access to your entire code base so you you don't have to copy paste stuff it knows what's in your files so we name it NE okay so new agents let's accept it maybe let's rename this to let's do sales agents sales agents okay so what I want to do is I want to build a team of sales agents that you can put into website and maybe let's describe it I'm going to say good job my goal is to build a sales team of of agents that any business can put into their website or sell this to other companies the team should have a manager agent a lead qualifier an objection handling agent a closer agent and researcher agent that can perform web search okay your task is to update and I'm going to tag it again sales agents.
y file changing the names and instructions of our agents and creating okay so we didn't have the okay we the one thing that it didn't copy over is this function right and just like in let's do test. py we need to have a transfer function that lets the manager delegate tasks to the other agents so again I I'm just typing in plain English and cser is going to build out for me because now it understands the syntax so the reason why we had to copy paste this example is because cursor uses Sonet 3. 5 by default which is llm I think it's one of the best llms for programming right now if not the best the issue is that it it um uses the data from the training data and this is a super new thing it's not in the training data that's the issue with NE releases new Frameworks new AI tools so it definitely doesn't have knowledge of open AI swarm now curser does have a web web search feature but it's not that great so it's much better to just copy paste the syntax and tell it to follow that okay so let's review the changes let's go to our sales agents again accept transfer transfer to qualifier transferring to okay uh uh uh so we have these different functions transfer to qualifier transfer to object Handler transfer to closer transfer to researcher so we have four agents on top of the manager so five different agents right okay uh let's maybe let's Okay I'm going to select the entire code and say add a few comments separating the different sections from each other so it's nicely organized and I'm going to also say do not overdo it because llms have a tendency to try to impress you and you know try to do everything in a single um yeah in a single shot so this is good I like this so again at the start is we just import necessary modules nothing changes then we initialize the client and print out the update message then we have the transfer functions so this is super simple it basically calls the agent that it wants to transfer right so here it's transfer to qualifier it calls the lead qualifier agent so whoever uses this we know it will be the manager whoever uses this will just have the power to call on this agent all right so this is pretty simpler now with the agent definitions enter this out agent definition so manager this is the mo most important agent actually one thing I I'm curious about how to use llms llm llm model model override an optional Str override model being oh okay an optional string so which model is it using by default GPT model the model used by the agent default GPT 40 that's good that's good um let's see maybe maybe we can use let's customize this a bit right so we have name instructions yeah so we can we can play around with this actually name let's then do let's do model model and Cur is suggesting gbd 40 mini for the manager you overse for okay for manager actually might be might be enough GPT 4 mini is like all it has to do is delegate to the proper agent right it doesn't have to be crazy so this one actually can be cheap or can be a small model now here tab tab C is telling us to go to the lead qualifier here maybe we can actually use o mini right o mini because we need a bunch of reasoning here objection Handler this is also important o1 mini will be good it's reasoning model so we can do a lot more thinking we need a more brain power then we have a closer agent this is to finalize a sale 01 mini is definitely a good idea here and the researcher we don't need that much power here we can just probably use GPT for o not mini just for o so this one this one by the way needs a function web search but I don't know if we can do it by itself wait let me test it out let me test it out uh because I think I've read that they have web searching by default seems like they don't have that ability interesting so we need to give it web search so we can actually create a new function for this or maybe wait let's maybe it's St let's do st.
com they have a great free plan so let's use this API so this is you know for those people like oh my God I can't just C gbd no you can't because you cannot give cgbd custom tools custom functions and do it have it execute actions on your behalf this is why you need to build agents because it you you can do anything with agents like it's only up to your imagination and you know how far you're willing to go so t. com again Link in the description let's go to the dashboard they have a let's look at the pricing they have a great free plan, API calls monthly for free I mean wow really good really good rep plan all right once you log in again took me literally 5 Seconds 10 seconds uh just use Google click on API Keys plus let's name it let's do new Society Again by the way all of this code and all of my other codes is available in the new Society so if you click on classroom and templates and presets I will put in all of this code and the prompts will be in the new Society just like my other AI agents I've built in the past useful gbds I've made my code pron instructions list of my subscriptions and all of that is available in the new Society right in the templates and presets stab so again first link in the description so let's name this new Society let's create copy Tav API key so yeah let's go into our EnV file DAV API key equals control V okay save beautiful now let's just copy paste all of this and I'm going to say let's go into sales agents use the composer feature I'm going to paste this inside I'm going to say above is the official Tav API documentation your task is is to implement a simple web search function into and we we're going to tag our file sales agentp that uses T API make sure to link our API key from EnV follow the exact syntax mentioned above in their official docs sometimes Sonet hallucinates so it's good to repeat this prompt let's let's see how it executes this function so boom from import T client then it wants to import OS to load API key it says load EnV variables then it says then it wants to initialize so let's accept this then it wants to initialize Tav client so Tav Cent equals client AP equals. get EnV API key so this will get our environment uh a variable and extract the API key from there then this is the function this is how Define functions in Python web search query performing a web search query for query and it should give yeah it gave our research so this is amazing right you didn't have to think about this curs took care of that for us it literally knew that okay I need to give the researcher the function and I also need to update the conversation The Prompt I mean wow amazing if you're a beginner you have to use I mean AI tools would just help you so so much it's really amazing truly amazing okay one thing we forgot is we completely skipped this step right so this is this is why you should uh read the dogs is you need to install the tavill API so let's copy that you know what let's go go into cursor contrl J going open the terminal and let's install that nice delete that so we've installed a vill so this should no longer be underlined hopefully yeah boom okay so we Al also need to install do n so what I can say is that you know I can let's I know what to do but let's assume I don't know what to do you can literally highlight it go into chat and say uh this line is highlighted why and how do I fix it super beginner prompt and it tells you what to do in the install the python package so copy boom again terminal new terminal and I'm going to contrl V what it told me I'm going to install python dash.
n and now it's good and now it should disappear in any second now there it is so okay what I'm going to ask the composer one more thing the new web search function is accepting a query parameter however in our code we don't pass it that fix this so we would have figured this out by testing but I just see the error so I pointed out basically nowhere we you know when we call the web search we don't pass it the promt so you perform web searches and then web search uh uh query I okay I think this is a mistake you know what let's let's reject all of these let's just test it out right so um these proms are could be optimized but that's not the case that not my worry I want to test out whether the T API works so this is the user prompt I'm going to say okay let's create a new composer change um change the code in Sals agent API to ask the user for the prompt not hardcoded do not change anything else this is a simple change I don't want it to rewrite system prompts and all that so again user prompt equals input enter your prompt for the sales manager boom okay save that's good and let's run it let's test it test so now I want to test out specifically if the T API works so I'm going to say I need you to browse the web for the latest info about Starship SpaceX Space X launch okay transferring to researcher performing web search for latest information on space launch okay wait is is this actually is it actually good launch details LIF of wait I think it actually works that's crazy let's let's go again let's go again let's try something else tell me about the new open AI swarm project that just launched yeah okay so it it didn't know to call on the researcher it wasn't explicit okay maybe maybe we can update the system prompt for the manager okay so let's I'm going to highlight you know what let's highlight this I'm going to say make the instructions a multi-line string okay again I'm coding with plain English here accept then I'm going to highlight it again and I I'll say let's make the instructions more forough telling it to telling it that if it doesn't know how to answer it should call on the researcher agent pretty good pretty good let's accept that let's run again I'm going to say tell me about the new open AI swarm project on GitHub let's be specific on GitHub transferring to researcher performing web search opening as SW project GitHub nice very nice boom okay let's see open as project is education framework designed to facilitate multi-agent orchestration so amazing it works it actually works wow I'm shocked this is very simple to implement function calling honestly this might be my favorite AI agent framework so far and that is saying a lot this might be I would I think I prefer this over crew AI over um agency swarm over autogen I mean it's so simple to use it's crazy literally name then you can do model or you don't have to and then okay okay so you know what let's let's actually let's have some f fun with this let's have some fun with this U let's write these promts okay manager all right let's update the knowledge of manager update in the instructions clearly explain which agents the manager has access to tell it explicitly to always call on one of the agents and clearly explain what each agent does and is good for all right so now we're going to improve this and we're going to make it actually useful so you guys you can if you have a business you can use this in your websites or you can sell this to businesses who need these sales agents which I mean it's going to be almost every business honestly okay much better much better now now let's let's use re okay let's use perplexity to figure out what makes a great lead qualifier so what makes a great lead qualifier what does one need to properly qualify leads in their business what are the most common common ways to qualify to disqualify lead lead in business how do you qualify potential clients that are chatting with you U via text different prompts let's see how this is perplexity by the way it's almost I mean it's it's a team of agents at this point look at this Pro search boom boom boom it lays out the steps and then each agent searches for something else perplexity is really crazy um yeah it's it's great if you're not paying for it what are you doing okay now we get this info so you might be thinking like David oh why are we doing the search well I'm doing the search because I don't know all this stuff you know I'm not an expert in qualifying lead so I'm going to copy this we can actually click on copy here go back into cursor and I'm going to highlight our lead qualifier I'm going to do control K edit I will say update the I'm going to paste this in I'm I'm going to give it okay above is research on what on how to properly qualify leads in business using that information rewrite the instructions of this agent to be a lot more forough explicit and professional spelling mistakes left and right it's kind of funny use multi-line strings boom enter so again you can use AI to write your system proms for you boom this is this is like I I myself probably couldn't write custom prom this good so that's why you're doing web search same for this right I'm going to actually you know what I'm going to do a Live Hack even more let's do like Inception this is going to be AI Inception let's open up clot boom I'm going to say rewrite the following web search prompt to make it relevant for objection handling in sales through text boom amazing now let's copy this let's go into perplexity and let's ask these questions related to our objection Handler agent we're going to get super forough research on this which we're going to use in the system prom now this is how you build a solid solid team of Agents oh this is really nice this is going specific like price objections lack of need trust issues timing oh my God this response is 40 wow okay let's copy I'm going to do the same thing here contrl K using the above mentioned info rewrite the instructions of this agent and make them a lot more forough and explicit use multi-line string boom seeing the agent work is like magic never ceases to amaze me all right so this is 12st Step Pro I mean amazing amazing respond promptly to maintain engagement use the customer's name keep it keep it clear always acknowledge valid C this is like sales Mastery 101 like actually I'm about to learn something yeah that's great closer agent okay you know what that maybe we can use actually hormos closer framework so let's open up a new perplexity research about Alex horos closer framework what what it is how how to do it how to follow it via text and and everything think else you can find about it obviously horos knows a thing or two about sales so why not just use one of the best salesman in the world and his let's let's put his framework into our team of Agents so C is for clarify L is for labeling o for overview s sell the vacation e explain away concerns are reinforced some of this is like concern handling would be handled obviously by um other agent but this is just a you know closer the closer should have knowledge of this so I'm going to again contrl K boom using the above mentioned info rewrite maybe I could be using the composer so I'm not repeating myself rewrite the instructions of this agent to make them a lot more for and explicit use multi-line string there it goes accept and researcher honestly I mean we can probably keep it simple for researcher there is nothing crazy on here um maybe let's let's do rewrite the instructions okay make the instructions into a multi-line string and rewrite them so that they reflect Theo of world class web researchers submit okay that's good enough I mean definitely Improvement right and let's see so here's our user prompt that's pretty solid what else the manager is I mean pretty good I mean we've massively this is actually a really good way to improv proms maybe my favorite way right now I'm going to call it the AI Inception just you know using AI into AI to improve to build your team of Agents so now with 106 lines of code again you don't have to build this yourself you can if you want I mean everything is shown in this video but you can access all of my AI agents I've built in the past and all agents I will build into the future in the new Society in templat and PRI section right here under AI agents by David I'll upload it right here or at the bottom okay let's run it I I can't wait to test this run enter your prompt for the sales agent so now keep in mind this would be embedded on your website right so a new customer comes in it's like uh you know let's role play this for my service like I'm interested in joining the new Society however I don't have okay maybe say um I'm not sure if it's for me because I don't have much time to implement the AI the a the exclusive AI content inside of it boom so again if I was sending the link on my website okay wait where's the error oh the oan model doesn't support function calling oh my God whatever do doesn't matter so I'm going to go into composer can create a new one say repl make sure all of our agents are using the GPT for o model I think this is actually the default one but whatever I want it to be fancy by using o1 but it doesn't support function calling unun unfortunate let's accept that so now all of our agents except for the manager which actually can use o1 mini because it doesn't do anything it just delegates so this doesn't we can save some costs over here but let's run it let's run the exact same promp I'm interested in joining Society blah blah blah enter transferring to lead qualifier okay so now uh uh lead qualifier final response thank you for interest blah blah blah we need to improve it right so we need to tell it to be super concise I'm going to say update the instructions so that we tell the agent to be super concise in its responses almost as if it was chatting with someone through text like WhatsApp mention this at least twice this is another prompt engineering tip if something is important enough you should repeat it at the start in the middle and at the end of your instructions do not remove the original uh the original system just add this new instruction to it I don't want it to undo the work that we built with perplexity so let's accept this save okay I'm actually kind of confused let's let's highlight only the this part of the code that we want to change closer researcher boom contrl K I'm going to say this exact message you know what let's just do it manually remember to be super concise almost CH sound yeah let let's just add this manually boom Cur already knows what was going on yes sir cursor is learning cursor is amazing honestly this I I've underestimated the power of tab you can just press Tab and it it predicts your behavior it's pretty pretty mind-blowing actually so now it should be a lot more like texting right so let's let's do a different objection right let's do uh I want to buy new Society new Society but I need a bit more info about what AI agents can do for my business which is let's say which is um travel agency which is travel agency from La uh okay so now it should hopefully called researcher yes final response wait what what happened why didn't it loop back and give me the oh my God okay I I know what happened we need to update this okay explicitly tell the agent in the instructions to always browse the web no matter no matter what the user query is mention this at least twice I want to buy the browsers but I don't know which size to go with because it's all in American sizing and I'm from Europe okay let's see how this goes objection Handler final response hey there I totally get the confusion what's your usual size in European measurements I can help you find the right US size just let me know and now this should okay we need to make one more change this needs to be a continuous loop so let's go into the composer we need to make one small change in sales hpy make it so that that we are in a continual while loop oh okay continuous V Loop until the Contin V Loop where the manager keeps receiving texts from the user and keeps uh calling the correct agents to hand handle them until until um the customer is is H is ready to buy then the manager calls a new custom function which you have to code by the way that will end the while loop by doing one last um cycle implement this in the simplest way possible again that last prompt is really good because AI models have Tendencies to over complicate and you know be try hard way too try way too hard okay so we should have a new end conversation function ending conversation customer is ready to buy objection Handler okay okay so that's good ending conversation return true let's approve this let's approve this this as well this as well and instead of this we're going to have this while loop while true user prompt equals prompt enter your message response equals CL run agent manager then user prom print manag response if any end coration for function well actually you know what the W Loop should be infinite because if the customer is ready to buy he'll just stop texting so the W Loop should should actually be infinite so our solution is actually super simple I'm going to say actually make the while loop infinite because when customers when potential customers are chatting with an AI agent on a website they should always get a response kind of simplifies things for us so let's do that oh I did it in the chat section uh let's prove this accept now let's try again this is again testing browse the web for USD to check conversion rate and it still keeps going so it's amazing okay then we let's try it right so let's say we in a travel agency website I really like the by the way if you actually implemented this St website you can change the prompts and you can add it you know custom knowledge custom data like PDFs dogs whatever so that it has more knowledge about your product and your service right so right now it's generic so that any of you can take it and implement this either for yourself or for other businesses for profit I really like the I really like the hoodie you guys sell but I don't know if it's high quality materials objection Handler let's see hi glad you like the hoodie totally get your quality conern hoodie are crafed premium corn blends now is hallucinating because it doesn't have the details but this is good many customers uh Rave about them one more info yes please oh okay so it doesn't know to follow up with the manager okay so yeah here we he okay here we would have to add way to manage context in other words we have to save the states maybe something like assistance API would be more suited for this yeah so Okay this may might not be the best for a loop situation then endless loop it might be better for like oneoff thing right so you you type in an agent then you have like a manager that decides what to do and then each of the agents actually do it maybe we should have I should have done this I should have looked at the examples again the GitHub is going to be linked below but uh open AI included a bunch of examples here so Airline let's look at the airline one demonstrate multi-agent set up for handling different customer service requests in an airline context so this is very similar except for sales it's customer service agent can Trash requests handling multiple Okay blah blah blah Remo demo run demo Loop wow why didn't I do this run demo Loop war.