ENSPIRING.ai: How to Build a Multi Agent AI System

ENSPIRING.ai: How to Build a Multi Agent AI System

This video provides a detailed walkthrough on how to construct a multi-agent system using "Whatsinext AI". The system uses reaction prompting by connecting basic LLMs (Large Language Models) into agents capable of performing complex tasks. The tutorial aims to demonstrate how to swiftly create a functional multi-agent system within 15 minutes by employing a framework called "Crew AI", which facilitates the building of these systems to automate tasks.

The video explains each step of the process clearly, starting with importing necessary dependencies and setting up API keys. It highlights the integration of different AI models such as "Watson X LLM" for developing the LLM interface and provides a detailed description on creating modules for different environments. It also covers defining the parameters for the AI models, setting up agents for specific tasks like research and function calling, and finally integrating these components into a cohesive system that performs tasks through delegation among agents.

Main takeaways from the video include:

💡
Understanding the framework and utility of "Crew AI" for developing multi-agent systems.
💡
Learning how to create multiple LLMS and integrate them into a multi-agent system for effective task management.
💡
Insight into the process of configuring different agents, each with specific roles and capabilities, for designated tasks using AI models.
Please remember to turn on the CC button to view the subtitles.

Key Vocabularies and Common Phrases:

1. vanilla [vəˈnɪlə] - (adjective) - Standard or unmodified; often used to describe something plain or lacking in special features. - Synonyms: (plain, basic, standard)

They turn your vanilla LLM into an agent, a system that can reason and complete tasks.

2. dependencies [dɪˌpɛndənˈsiːz] - (noun) - Software components or modules required for a program to operate. - Synonyms: (requirements, prerequisites, components)

So the first thing that we need to do is import a number of dependencies.

3. prompting [ˈprɑːmptɪŋ] - (noun) - The action of asking or encouraging someone to perform an action. - Synonyms: (urging, encouraging, stimulating)

Multi agent systems work using react prompting.

4. parameters [pəˈræmɪtərz] - (noun) - Limits or boundaries that define the scope of a particular process or activity. - Synonyms: (specifications, criteria, guidelines)

Then we need a couple of parameters or keyword arguments.

5. verbose [vɜːˈboʊs] - (adjective) - Using more words than necessary; overly wordy. - Synonyms: (wordy, long-winded, garrulous)

And then the last thing is whether we want it to be verbose or not.

6. collated [kəˈleɪtɪd] - (verb) - Collected and arranged in order for some purpose. - Synonyms: (compiled, organized, gathered)

So once it's collaborated or collated, everything it needs, it should generate the bullet point summary of the research that we want.

7. sequential [sɪˈkwɛnʃəl] - (adjective) - Following a specific order or sequence. - Synonyms: (consecutive, successive, serial)

So it's almost like a sequential agent.

8. collaboration [kəˌlæbəˈreɪʃən] - (noun) - The act of working jointly with others. - Synonyms: (teamwork, partnership, cooperation)

So this agent's got a little bit of a cross collaboration between AI and quantum research.

9. keynote [ˈkɪnoʊt] - (noun) - A speech that serves as the main address, often setting the underlying tone or main theme. - Synonyms: (address, lecture, talk)

So we want this agent to actually write some keynote speeches for us.

10. decoding [diːˈkoʊdɪŋ] - (verb) - Interpreting or converting a coded message into an understandable form. - Synonyms: (translating, deciphering, interpreting)

Okay, so our first value is going to be decoding method and we're going to set that equal to greedy

How to Build a Multi Agent AI System

Multi agent systems work using react prompting. They turn your vanilla LLM into an agent, a system that can reason and complete tasks. Now, if we put a bunch of them together, you can build up a team of specialist agents to automate tasks. Were going to do that in exactly 15 minutes. But is this possible with all LLMs and is there a framework that can help? Well get to that, but for now ive broken it down into three steps and it begins with getting our LLMs ready.

Alrighty guys, we've got 15 minutes on the timer. Let's kick things off. So the first thing that we need to do is import a number of dependencies. So we're going to be using crew AI. It's a framework that allows you to do multi agent systems or build multi agent systems. So we're going to say from crew AI, we are going to be importing the crew task and agent. And then we also want to give our multi agent system access to some tools. So we're going to say from crew AI, underscore tools import Serp dev tool. Now the cool thing is that there's a number of different tools as well, right? So if you wanted to use CSVs or Docx files or GitHub or JSON or MDX or PDF, you got the ability to do that as well. Let me know if we maybe do that in another video.

Okay, then in order to build our LLMs and interact with our LLMs, we're going to be using what's the next. So we need an interface to what's next? So we're going to say from Lang chain, underscore, IBM, we're going to import Watson x LLM. So that's going to allow us to build our LLM interface. And then we also need OS. So this is going to give us the ability to set our API keys for our environment. So we're going to do that first. So we're going to say OS environment and then we want to go and set our Watson X underscore API key value and we're going to set that to one that I got a little earlier. So I'm going to grab that API key from over there. Okay.

And let's zoom out a little bit. And then we also want to set our API key for our Serp a dev tool environment. So this is actually going to allow us to interact with the net. So we can set that by running or passing through OS environment, then setting SErP underscore API underscore key. And then we're going to set that to the value that you can get from Serpa dev. So you can actually go and register for a free API key and get that up and running. We've got a bit of an issue there, so that's because of our quotes. Okay, cool. So we've now got our API key set, we've got a couple of dependencies imported. We're now going to create the first LLM.

So we're actually going to be using two LLMs. I'll get back to that in a sec. So to create our LLM we're going to create an instance of the Watson X LLM class. Then we need a couple of parameters or keyword arguments. So the first one is model id and we're going to set that to a blank key for now. We also need the URL. So because of the way the Watson X is spun up, we've got the ability to run this on a whole bunch of different environments. Plus we've also got different multi region availability.

So if you wanted to go and run it in the US or in Europe or in a pack, you've got the ability to do that as well as on premises. Okay, so we've got model id, we've got URL, we also need to specify the parameters for the model. So this is going to be how we actually decode and we also want to be able to pass through our project id so you can actually isolate your machine learning and data science projects using what's an X AI. So we're first I'm going to create a parameters dictionary. So this basically dictates how we actually go and decode from our model.

So we're going to create a new value called parameters and set that to a blank dictionary. How we do it on time, we've got twelve minutes. Okay, so our first value is going to be decoding method and we're going to set that equal to greedy. So we're just going to use the greedy algorithm for now. And then we also want to go and specify max new tokens. This gives you a little bit of cost control so it dictates how many new tokens you're going to be generating. So we're going to grab that parameters value and set that into our LLM. And then we also need to specify our model id. So our first LLM that we're going to be using is llama 370 B.

So we've got the ability to actually go and change that so you can see that we've got the ability to use llama 370 B instruct. Feels kind of weird. I know, I've been using llama two for so long now. So we're going to specify metal and then it's going to be lama Dash 370 B instruct. And we also need to go and set the URL. So we're going to go to over here. So we've got the ability to copy this URL. So I'm just going to grab that and then paste this into my URL area. Let's save that. So it should reorganize it. Okay.

So I'm just going to get rid of everything after the.com. so we don't need that. Okay. So that is our LLMs spun up. We also need to pass through our project id. So again, that's available in a similar region. So it's available from your. What's the next environment? So the project id is just over here. So I'm actually got a project id I spun up a little bit earlier. So I'm going to grab that and paste that in there. Okay, so this should be our LLM. So we've gone and specified our model id.

So we're going to use armor three a URL, primes and our project id. Let's actually test it out. So if I run printed LLM, dot invoke and then I pass through a prompt. So this could be any prompter. Right now this is just a vanilla LLM. So I could go and say, who is Neil's ball? You can tell I've been getting into a little bit of physics lately. So if we go and run this now. So the file is called Agent PI. So to run it, we can run Python Agent PI. I'm going to pause the timer while we test it out. We have exactly ten minutes left.

Okay. All right. Coincidence? Yes. Okay. So if this runs, so I'm going to pause a while it's generating, because that's a little bit out of my control. And let's see if we get a response to who is Neil's ball? Crossing my fingers. Okay, take a look. So we've got a response. So this is coming from llama 370 b right now. So we've got a response. So, Niels ball was a danish physicist who made significant contributions to the development of atomic physics and quantum mechanics. He's best known for his model of the atom, which posits that electrons exist in specific energy levels, or shells, around the nucleus. Sounds pretty good.

Okay, so that is our first LLM created. Now I did mention that we're going to need a second LLM and that's going to handle our function calling. So we're going to go and power on ahead. So we've got our LLM setup. Now we're actually going to go on ahead, create our second LLM and then build our agent. So we're effectively on to part two. Time is at ten minutes and to kick this off. Let's go.

Alright, so we're going to need to just copy this LLM over here. We're going to create a function calling LLM. I'm going to speed up just a little bit, not too much. We're going to create a new variable called function calling LLM. And for this LLM we're going to use a slightly different model. So we're going to use the IBM Dash Mistral AI and we're going to use the Merlin at model. So Merlinite Dash seven B. Okay, cool. So those are our two LLMs now set up. Now we're going to create the agent.

Create the agent. And our first agent is going to be a researcher. But keep in mind eventually you could have a ton of different agents. They could all delegate and interact with each other. So first agent is going to be a researcher and we're going to create an instance of the agent. So there's a ton of keyword parameters that you need to pass through here. The first one is the LLM. So this is going to be the base LLM that we use to do all of our generation. We then need a function calling LLM and that is going to be our Merlinite model that we just set up there.

So I'm going to paste that keyword argument in there and then we also need to specify three additional arguments. So there's more than three. So role, goal and backstory. And I've pre written those prompts. So we're going to spin those or pass those two in a second. We also want to determine whether or not we want to allow delegation. So eventually I might do this in another video, but eventually you've got the ability to allow these agents to hand off to each other and just sort of delegate and work out which agent is going to be able to do the task the best.

We also want to specify some tools. So we want to give our agent access to the net. And then the last thing is whether we want it to be verbose or not. So I'm going to set that to one. Okay, so roll goal back. Sorry. So this basically dictates what our agent is good at. So our agent is going to be a senior AI researcher. The goal for that agent is going to be to find promising research in the field of quantum computing. And then the last backstory bit is going to be. So this agent's got a little bit of a cross collaboration between AI and quantum research. So our backstory is you're a veteran quantum computing researcher with a background in modern physics.

Okay, so that's our agent. We now need to give it some tools. So tools. This one's pretty straightforward. So we're going to create a tool called search and that's going to be equal to the SERP a dev tool. So this I believe inherits from LangChain. It allows you to go and search the net. We just need to grab that search value and pass it through here. So that is our first agent now completely set up. Now we actually want to go and fill this out a little bit more. So we want to give it a task. So create a task. And a task is effectively what we want our multi agent system to do. So our task, first task, so we're just going to call it task one, is going to be a task and then the task is going to have a couple of things. So we need a description of the task, we need the expected output, how we're doing on time, seven minutes.

Okay, I think we're all right. We're sounding all right. We also want the output file. So this is actually going to output the results of the task and then we want the agent that we want to complete that task. Okay, so the description again, I've baked these a little bit earlier. So we're going to grab the description search and net and find five examples of promising AI research.

Going to paste that into description and I'll make all of this available via GitHub later so you guys can grab it as well. And then the expected output is going to be a detailed bullet point summary on each of the topics. Each bullet point should cover the topic background and why the innovation is useful. Output file is just going to be the name of the output file that we want to output. So we're going to say task one, output TXT and the agent that we want is not a string. The agent is going to be our researcher. So which agent that we want to complete the task. Now we need to pass through these tasks to the crew.

So put it all together with the crew. So we're actually going to hand it off to a crew and let the crew run it. So we're going to take crew is equal to crew. And then inside of there we want to specify agents. And initially we're just going to have one agent, but we're going to come back to that in a sec. And then we also want to specify the tasks that we've got. So right now it's just task one and then we want to specify verbose equal to one. And then we just need to kick it off.

So we're going to run crew or print crude kickoff. Okay. All right, I'm going to pause it. So let's actually go and run it. So I'm going to clear this for now and we're going to run Python Agent Py again. And all things holding equal, they should start doing our research. Let's pause it. All right, five minutes, 32 on the clock. Let's see how we go. If this works, we should start this task. So search the Internet, find five examples of AI research. You should see it making calls out to the net and us getting research back.

So you can see that this has generated some action input. So saying to use the search function, so search query and then run this command, promising AI research and quantum computing. And take a look. We've got some responses back from the net. So anything is orange is what we're actually getting back from the Internet.

So once it's collaborate or collated, everything it needs, it should generate the bullet point summary of the research that we want. So let's just let that run for a little sec. You can see that we've got a bunch of other research coming back there. And take a look. We've got our response back. So you can see that we've got all of our output down here. So here are five examples of promising AI research. So it's gone and done all of the research and then it's decided that it's done. So the agents now understood that it's complete because it's gone through its thought process, it's queried as much as it needs to and it's generated its response.

So down here we've got five examples of promising AI research in the field of quantum computing. So quantum AI, quantum machine learning, quantum optimization, quantum RL, quantum neural networks, and we've got all of the responses. The cool thing is that it will output it as a text file if you wanted to go and use it. Those are all of our bullet points. You can go and use that. I'll include that in the GitHub repo so you can see the responses as well. Okay, so that is, I'm actually going to save this as the first example so you guys can grab it because we're actually going to regenerate this in a second. So so far we've gone and created one agent, one task. Right. But this isn't really a multi agent system, it's a single agent system.

So what we now need to go on ahead and do is generate our second agent to be able to go and truly convert this into a multi agent system. All right, we've got five minutes, 32 left on the clock. You can see that. Let's go bring this home. Second agent. Okay, so what we're actually going to do now, let me zoom out a little bit so you can see that we've got our first agent and task pair. We're actually going to copy this and I'm just going to paste it down here again. So we're now going to create the second agent and it's pretty much the same. The only thing is that we don't need to give our second agent access to the net.

So we're going to tweak this a little bit. Let me zoom in. Alright. So we can get rid of this function calling bit and get rid of the tools. And this agent is actually going to be a writer. So we want this agent to actually write some keynote speeches for us. So we're actually going to pass through a different role goal and backstory. So I'm going to grab that out of here. So our second role is a senior speech writer. So let's say that you're writing speeches for a prominent executive. You need to go and write some speeches.

So the role is going to be senior speech writer. The goal is to be write engaging, witty keynotes, features from the provided research. I'm going to paste that in and then the back story is going to be. You're a veteran? No, it's the. It should be tweaked a little bit. Looks like I just went and copied and pasted when I was writing. So you're a veteran. Quantum computing. I'm going to say writer with a background in modern physics.

But again, you could go and tweak this a bunch more, but effectively you could provide a bunch of background on how this person's a writer. Okay, so that's our backstory then we want to go and create our second task. Tweak this and let me know how you actually go. All right, so we're going to generate our second task here. So our second task is write an engaging keynote speech on quantum computing. I'm going to paste this in the description, and then our expected output is a detailed keynote speech with an intro, a body and a conclusion. So we're going to paste this in over here. Perfect.

And then a second output file is just going to be called task two. Output. Okay. So that is our second agent. So our second agent is a writer. Our second task is to get that keynote speech written. So it's almost like a sequential agent. Right. So the first agent is going to do the research, find all the research. Second agent's going to step in and then convert it into a keynote speech. So we can actually go and pass through a second agent, which is going to be our writer down here.

So this is what gives us the multi agent feel. Right. And eventually, once we allow delegation, if we did that in the next video, then we'd actually be allowed to be able to do all of the handoff tasks. So maybe we convert agents into a series on the channel. You let me know in the comments below. Okay, so we've now got a pass through our second task over here. Gonna pass through our second agent. We go and run this now, we should effectively go through that two step process.

So if we go and run this again and I clear this, and we should also get two outputs now, right, because our second output file is called task two output. So I'm going to run Python Agent PI. I'm going to pause the timer. So we've got two minutes 43. This all blows up. That's how much time we're going to have left. Two minutes 42 to solve this. All right, so let's let this run and see how we go. Okay, so you can see it's triggering the chain. It's doing the research again. So again, this is still the first agent. So you can see that the working agent is the senior AI researcher. We haven't got to the writer yet. Okay, so we're doing research.

Okay, so you can see we've now. I know we're still, still doing research there. I thought we were finished. Oh, actually, no, we've got a bug. Just realized I'm going to start the timer again. So we're 241. So I just noticed that we were using the same agent. So inside of our second task, we actually need this to use the second agent because right now we're just using the base agent. So we actually want this to be writer. Okay, we're going to change the agent there.

And then let's kick off our timer again. So I'm going to clear this all right. It only took me 10 seconds to resolve. So we're at 222. Still got time to debug, but we're probably going to speed through this. So editors speed through this. Okay, so we're triggering our first bit from our senior AI researcher. Hopefully, once we get to that next debug stage, we're now on to our. What is it? What do we call. Senior speech writer is going to pick up from there. Okay, take a look.

So we've now successfully gone and handed off to the senior speech writer. So this is our second agent kick in. Hopefully they just write our keynote speech. It might be limited because we've only given it 500 tokens to write the speech, but you sort of get the idea. Fingers crossed. We now get a keynote speech written in under 15 minutes. Not too bad. All right. Take a look as our keynote speech. Not too bad. All right, so we should.

So we can see that we've gone and done the research. We've got our bullet point list over here, bullet point list over here. And then we've got our keynote speech over here. So if we actually go and take a look, we've got our two outputs. So task one output and task two output. So this is the next set of output from the second run. So we've got all of our dot points. And if we go and take a look at our task two output. Let's read a bit of our keynote speech.

Ladies and gentlemen, esteemed guests and fellow innovators, I'm thrilled to be speaking with you today at a revolution about the revolutionary potential of quantum computing. As we stand at the threshold of a new era and technological advancement, it is imperative that we explore the vast possibilities that quantum computing has to offer. I don't know how witty this is, but it is a keynote speech. In the realm of artificial intelligence, quantum computing is poised to unlock unprecedented capabilities. Quantum. I'm going to put this all in the GitHub repo. So you can read it yourself, but you can see that we have, in fact, gone and written a bit of a keynote speech.

We could definitely take this further, but for now, that's how to build a multi agent system with Watson X AI. I'll catch you in the next one. It.

Artificial Intelligence, Innovation, Technology, Multi-Agent Systems, Quantum Computing, Programming, Ibm Technology