Hello guys.
In this video we are going to implement multiple AI agents for real world use cases using GRU AI and
Google Gemini model.
Now why Google Gemini?
Because if you go in the AI documentation, right?
Uh, so if you probably just go and click on Get Started here by default, uh, the kind of LM model
any agent requires is specifically OpenAI API key.
Now, you know that OpenAI API key is a paid model.
So we will not go ahead with that.
You know, and uh, obviously many people wants lot of examples specifically how we can use open source
LM models or Google Gemini, which is like freely available.
We can use it for 60 queries per minute, I guess.
Right.
If you probably go ahead and see the documentation of Google Gemini Pro.
So, uh, in this video I'm going to show you that example.
And the LM model that we are going to use is Google Gemini Pro.
Now the best thing about this video, uh, will be that I will be starting completely from scratch.
Uh, we will develop some use cases related multiple agents.
And this AI agents will also be interacting with each other.
Right.
So let me just go ahead and open my coding environment.
So this is my entire coding environment right now.
Here you'll be able to find out some folders I have already created my environment.
Uh, sorry.
Uh, I've already created my virtual environment.
Along with that, I have my env key because I will be using Google Gemini API key.
Along with that, I will also be using one tool which I will be talking about.
And then you'll also be able to see requirement dot txt.
Now let me show you that how I have started creating the environment over here.
So first of all, in order to create the environment you have to use conda create minus p v and v python
double equal to 3.10.
Okay.
So I am going to use the 3.10 environment over here.
Along with this.
By default you have to give dash y so that the installation will start.
Start taking place and your virtual environment will get created.
So please do this because I have already done that.
And once this entire things gets executed, then you will be able to see that I will be having a V env
environment.
Perfect.
Uh, once you do this, uh, the next thing is that, uh, we will go ahead and uh, create our requirement
dot txt.
Now in this requirement dot txt I'm going to use q u I.
Along with that since we are using Google Gemini.
So in Lange chain you have this lang chain underscore Google underscore gen AI.
So this is the library that we are going to use to interact with any Gemini models.
Along with that, uh, you'll also be able to see load underscore dot env so that any environment variable
that I will be creating, I will be able to call all the environment variables in any code by using
this okay.
So these are some basic information.
And now let's go ahead and start our coding okay.
As usual.
Uh first of all we will go ahead and create our tasks dot p y.
Along with that we will go ahead and create our agents dot p y um agents dot p y.
And uh task is there, agent is there.
And then one more that we are going to create is tools dot p y.
And finally we will also be creating our uh q dot p y so that we will be able to execute the code or
we'll be able to start our entire process.
Okay.
So all these things has been created.
Now let's start writing one by one, as usual.
Uh, what I am actually going to do, first of all, I'm going to probably go ahead and create my agents,
and I will start writing my agents.
Now over here, uh, there are two things, uh, which I'll be mention.
One is which search tool I will be using along with that, which LLM model like Google Gemini.
Right.
For that you will be requiring an API key.
So first of all, uh, let's go ahead and uh, import some of the important libraries like Q I import
agent.
Okay.
So this is the first library that I'll be using.
And as you all know that I have to create my agents over here itself.
But before that I will go ahead and import from dot env import load underscore dot env.
Right.
Then uh, here you'll be able to again see load underscore dot env I will be calling it.
So that it will load all my environment variable.
Now we are going to set the Or call the Gemini model.
Call the Gemini model right now in order to call the Gemini models.
Uh, one important library that we are going to specifically use over here is from lang chain underscore
Google underscore Gemini.
We are going to import chat Google generative AI okay.
So chat Google generative AI.
So this is the library that we are going to specifically use.
And then I will use this library and use uh LM variable over here.
And some information that I really need to give over here is first of all what model name I want.
So here I'll be giving my model name.
Second, uh, I will also set the parameter of verbose to true so that I will be able to.
See almost all the details when it is getting executed.
Then you have temperature which will be equal to 0.5.
And then here we also need to give our Google API key, which we will be calling from our environment
variable.
That is OS dot get env.
And here we are also going to use my Google API key right.
Google API key.
Now this key has been created in my environment variable which I will again show it to you.
So this all suggestion are specifically coming.
Oh my god so many different different suggestions are coming.
But I will remove this because I don't require it.
So I will be uh using this OS dot get env uh, which is nothing but Google underscore API key.
So once this is done, uh, so this is my LM model.
Now obviously this Google API key here, you will be able to see that in my environment variable I have
already created one right.
Google underscore API key.
And uh, with the help of this API key, I'll be able to call any models that I want specifically with
respect to Google Gemini Pro.
Okay.
Now if I go to back to my agents, how do we create this API key.
So for that you have to go to AI studio.google.com/app/api key.
Once you go to this page just click on get API key okay.
So once you click on get API key here you'll be able to see create API key.
Select uh the one of the project by default project.
And just go ahead and create it.
Once you able to create it you will be able to get a API key itself.
Okay, again my suggestion would be don't use this whatever I have used because I'm going to delete
it after the video is getting recorded.
Okay, so here, uh, you can probably see my entire LM model over here, right?
And uh, with the help of this specific LM model, we will be using this in while we create our agents.
Okay.
Now, let me just go ahead and create some of the agents over here.
So first step will be that I will be creating a senior research agent.
And this particular research agent will be doing some amazing research.
So I will be creating a variable called as researcher.
And this will be nothing but agent.
Now inside this researcher and in this agent I have to provide my role.
So role will be nothing but senior researcher okay the next is nothing but goal which will be uncover
ground ground breaking technologies.
I will talk about the problem statement.
What I am going to probably do in this.
Okay.
So here, uh, I am trying to create an AI agent, which will be a researcher which is responsible in
creating some amazing blocks on different different topics.
But we it has to probably do a lot of research and communicate with multiple agents.
Okay.
So here, uh, our goal is basically to uncover ground breaking technologies in the specific topic.
Or I can also say this will be a news reporter, which will be responsible in, uh, getting all the
news details.
Okay, so the third parameter here, we are going to set it to verbose as true.
Okay.
Then next will be memory to true okay.
Memory to true.
Uh these are some of the default parameters.
And then we will also go ahead and write our backstory.
So the backstory will be something okay.
So I will try to write it down over here.
Some amazing backstory like this news reporter that we are trying to create.
Right.
It's uh, first it's has its own backstory, like driven by curiosity.
You're not at the forefront.
Uh, you are at the forefront of innovation, eager to explore and share knowledge that could change
the world.
So something amazing backstory.
We have actually developed and assigned it to the, uh, this specific researcher or the news agent.
Okay.
Then we have this tools.
So tools we are going to use something which we will be discussing as we go ahead.
And then we I'm also going to define my LM model.
And this LM model if see if I'm not using this then by default it is expecting OpenAI LM model.
But right now it is having this uh LM models okay.
Then my last parameter will be allow delegation.
Allow delegation is equal to false.
Okay.
Oh, sorry.
I need to make it sure that this becomes true.
Because I want this researcher to probably communicate with the other agent.
Right.
And so we are keeping this allowed delegation is equal to true.
Now similarly what we are going to do now this person is responsible in researching the news.
And uh, we will try to create another person.
So I will just go ahead and keep this variable as news researcher.
Okay.
And based on this news researcher, there will be another agent which we will try to create.
So here I'm going to write create creating a writer agent with with custom tools.
Um writer agent uh or I can also say, okay, creating a writer agent with custom tools responsible.
Okay.
Responsible and writing news blog.
Okay.
Something like this.
So this will be the person.
And uh, similarly we will also do this for this person.
So here I will go ahead and write uh, news writer okay.
So this person is basically a news writer agent role is writer narrate compiling text stories about
the topic.
Uh, with a flair of simplifying complex topics.
You craft engaging narratives.
Some back stories there.
Right now, I have not defined my tool search.
So this will basically be LM and uh, allow delegation is false because once the research is done and
uh, it has come to the writer, it is responsible of writer to probably write the entire blog.
Right?
So that entire text story will be written by this person or by this particular AI agent.
Okay, I'll not say post, okay.
But this is, in short, doing all the people work, right?
Uh, over here.
Now, I don't need to have another researcher or, uh, another writer, you know, it will be able
to do it.
Perfect.
Uh, so this is the first page that we are going to work with.
Now I'm going to go to tools.
Okay.
Now which tools I'm going to use.
Right.
So, uh, in Korea I when I went to the documentation, right, I was seeing a lot of tools.
So first tool that is Google search.
Uh, so we have used this Google search for search okay.
Now Google search for search.
Uh, we are going to use surfer dev tools.
Surfer dev tools.
So I'm going to use this specific tool for this tool.
Uh you also need to have an API key.
So in order to create it what is this surface.
It is the world's fastest and cheapest Google search API.
Again it is completely for free for 2500 queries.
Okay, so what I have done is that just go ahead and sign in and uh, you will be able to see something
like this dashboard here.
You can see that I have accessed some of the previous request on 22nd May and 23rd May.
Now I'll just go ahead and create my new API key.
So here you can use this API key and the same API key I have actually pasted in my environment variable
okay.
So again don't use this because it is completely for free okay.
So for.dev okay.
So that is the URL.
So here you can see surfer.dev okay.
So you have to probably go in this URL.
Uh let me do one thing again.
Uh let me to make it better, I will just write the command over here okay.
So that you will be able to see it.
Okay.
Now, uh, as usual, uh, in my agents that we have specifically discussed.
Right.
So in the agents, uh, I will also go ahead and import this.
Okay, along with this, I will go ahead and import OS.
Now why?
I'm doing it?
Because I will set up my environment, uh uh, environment and probably os dot.
Okay.
And.
Well start.
SOP API key is nothing but OS dot get so server API key.
So we are going to do this uh, along with this uh, the next step again we can see the remaining code
from the crew AI website itself.
That is nothing but from crew AI underscore tools import.
So support dev tool and we have to initialize this tool okay.
So that is what I'm going to probably write it over here okay.
Now one very important thing that you really need to understand.
This crew AI underscore tool is to be part of the requirement dot.
TXT file.
Okay I will go ahead and import it.
Um, and let me just go ahead and open the terminal and we will do the pip install minus r requirement
dot txt okay.
So done.
This is done.
The installation is basically happening.
So once this installation is happened our tools is also fine okay.
So let the installation happen.
And we are going to use this specific tool which will be a soap or dev tool okay.
Now the same tool I have to call in the agents right.
So here I'm going to basically write from tools import tool.
Right.
So this basically is my tool.
Now all I have to do copy and paste this tool over here okay.
Perfect.
So this is the tool that we are going to use over here which was pending.
And again let's remove all the spaces so that we will be able to work.
Okay.
Perfect.
Uh, till here everything looks good.
Uh, now one thing in the agent, we also have not specified the model.
Right.
In order to see which model we are going to work on.
Right.
I'm just going to click on Google AI studio.
Let's see.
Okay.
And here you have multiple options of using like uh here you have Google Germany 1.5 flash.
You have 1.5 Pro.
So let me just go ahead and use this, uh, Germany 1.5 flash.
So here, uh, what I'm actually going to do over here is that let me just see the name again.
Germany 1.5 flash.
So let me just go ahead and write it down.
1.5 flash okay.
So this is the recent model that we have in Germany.
Uh, we are going to use this.
And now everything is ready in our agents.
Right.
Tools.
Now for every agents we also need to create some kind of task.
So let's go ahead and create the task now and again for creating the task.
Uh, first of all we will go ahead and import from Cru.
I import task okay.
Task from Q I import task.
And now we are just going to develop all our task uh, again uh, almost uh, the task is also similar
like how we have written for the agents.
So let me just go ahead and copy and paste it and let's go one by one.
Okay.
So first of all we have created some research task okay.
And from this particular research task what we have done we have used this task Klaske description have
written identify the next big trend in this particular topic.
Whatever topic we give, focus on identifying pros and cons and the overall narrative.
Your final report should be clear.
Articulate the key points its market opportunities and potential risk.
Then expected output will be a comprehensive three paragraphs long report on the latest I train.
So this is what it is going to do.
Uh, since we know that from tools import tool okay.
So I'm going to use this tool also okay.
So let me just copy this over here and let me paste it over here.
And this will also be pasted over here.
Now we know with respect to our agents okay.
Uh from tools Import Tools.
Let's see if this is fine.
Why there is a red mark okay.
No worries.
Okay, I will call this.
Okay.
Done.
Okay.
Now, one thing, uh, that I will be doing over here again, I need to call both my news researcher
and news writer.
Right.
So here again, I will go ahead and write from agents, import import news researcher comma news underscore
writer.
Okay.
So both of them I will be using because here in the agent we need to replace it with this okay.
So these are some of the parameters that uh we have done it.
Now once this is updated what we are going to do let's go ahead and explore this.
So here the expected output was nothing but a comprehensive three paragraphs long report on the latest
AI trends.
And then, uh, the next thing, uh, we have for the writer task, uh, for writer task, you can probably
see that I have.
So let me just go ahead and write this as writer and this will be okay.
Right.
Write task.
Okay.
So here you can see task is over here.
Compose and insightful article on topic.
Focus on the latest trend and how it is impacting the industry.
Expected output is nothing but a four paragraph article on advancement formatted as markdown tool will
be tool.
Okay, here we are using the agent as news writer and.
Output file will be nothing but new blog post.md.
So this will basically be created.
And this is one of the example of output customization.
You can also create another type of file like txt any type of file that you want okay so all these things
are done.
So here is my entire task.
Uh so here.
In short what what we have done see agents is just like persons like people news researcher, news writer.
Then we have assigned a definite task like research task and write task.
And this is specifically going to use the Google Gemini model that we have defined in the agents dot
pi.
Okay.
So perfect.
Uh, I think we are good to go.
Uh, each and everything.
And again, as I said, with respect to tools, this is just one of the example.
You can use any tool that you want again from the crew page.
Okay.
Now finally, uh, let's go ahead and import our crew and process.
Now I will go ahead and start my process from here.
So for that, uh, let me just go ahead and write it completely from scratch.
So here I'm going to write from crew.
I import crew comma process.
Okay.
And then we are going to form the tech focused crew with some enhanced.
Configuration.
Okay.
So finally let's go ahead and write.
Our q is equal to q.
So we will define this specific class.
Q is equal to q.
The first parameter that is required is all the agents that we want right.
The second parameter that we require the kind of task that we want to execute based on this agents okay.
And finally the third parameter will be our process.
Uh, there are multiple process.
Uh, we will first of all learn about process dot sequential.
Okay.
Sequential.
And as I've already told uh, this process dot sequential.
What does it mean?
Uh, this is just going to this entire code is going to or this entire execution of, uh, uh, the
communication between this particular agents will be completely sequential.
That basically means once the news researcher is completing its work, then it will further carry on
the results to this particular news writer.
So, first of all, uh, when this agent is initialized, we know what kind of task is assigned to this.
So it will get completed based on this particular task.
And then once you get the output, uh, over here, you can probably see what kind of output we want
with respect to the task.
Right.
A comprehensive three paragraph long report on the latest writer end.
Once this output is got, it will be further sent to the news writer and, uh, further or more information
based on that particular topic.
It will try to compile more text stories, and then it will further use the LM model to those process.
Right.
And at the end of the day, based on this task, it is going to give you the output file.
So this is completely a sequential process.
There is also one more process which is called as hierarchical process.
Uh, which we are going to see in the upcoming video.
Okay.
So uh, that is the reason we are selecting uh process dot sequential.
Now what I'm going to do from task.
Uh, import research task.
Research underscore task.
And this will be write underscore task.
Okay.
Write underscore task.
So this are my task that you will be able to see again.
You can also get an py file output file a coding file anything that you want.
So this task will be okay.
Just a second.
Research okay.
Research task will be added over here.
And write task will be also added over here okay.
And here in the agents uh we are again going to import from agents import.
And in this specific agents uh, we have, we have some uh let's see which all agents we have.
One is the new researcher okay.
News researcher.
And, uh, okay, okay, okay, okay, okay.
News researcher.
And then you have news underscore writer.
Dot perfect.
Over here, you will be able to see my entire crew is ready.
Um, now, what I'm actually going to do over here is that just go ahead and use this news researcher
in my agents.
After that, use this news writer.
Okay.
Now this process uh, also is their sequential is also there.
Now we are going to start the execution.
So starting the task.
Task execution process with enhanced feedback.
Okay.
Now we are going to do this.
Now you have the result is equal to true dot kick off.
And here we are going to go with the inputs.
Topic.
Let me just go ahead and write topic.
AI in healthcare.
Okay.
Then finally you'll be able to see I will go ahead and write my results.
Okay.
So in short, what we are doing over here is that we are just going to kick off this entire process.
Once this line is executed right here, the topic is basically gone.
This will get initialized.
It knows which will be the agents that we are working with.
So two agents, one is news researcher, one is new news writer which will be working independently.
Okay.
Then you have this research task and write task.
These are the assigned task over here with respect to this particular agents.
The process that we are going to follow is sequential.
Then based on these agents it is going to go in that specific page, get out all the information and
then execute assign the LM models and all.
So here we have not used OpenAI instead Google Gemini.
So let's go ahead and execute it.
And I think now hand crossed everything should work fine okay.
And I hope so.
It works fine.
So python q dot p y.
Okay.
So there is an error okay.
No worries because I have to go inside this folder right?
Q Google Germany, no worries.
So I'm going to write CD Q Google Gemini okay I'm going to clear the screen.
And then let's go ahead and write Python q.py.
So once we execute this here you will be able to see that um my entire execution is basically starting
okay.
There is an error saying that uh cannot import chat Google generative AI from from uh sorry from Lang
Chen underscore Google AI.
So let me just see the documentation whether it is correct or not.
And let's see.
So agents uh, from Lang Chen underscore Google j'en ai uh, now I think it should work.
Okay.
So there was one spelling mistake, but no worries.
Anyhow.
But I will be giving you the code right?
So you can probably check it out.
So here you can see name chat.
Google generative AI is not defined because we have imported the right thing, but we have not initialized.
Okay no worries.
So I will copy this.
I will paste it over here okay.
There was a spelling mistake.
Serious spelling mistake.
It happens.
Okay I'm just going to keep this error also so that you see what kind of errors we usually get.
Okay.
Now here you can see it has entered the new configuration change.
Now it is probably going to do the search the internet see from the from the search API.
It is doing the search internet.
Uh thought it is.
I need to understand the current landscape of AI in healthcare to identify the next big trend.
Then you have this all top ten titles, ten ways all the articles it is able to scrap in the Google,
right?
And uh, delegate the work to the coworker.
So coworker says write at us, write a three paragraph report, see how the communication is happening.
Now just imagine how powerful this amazing application or tool is through AI, right?
Uh, here, agents are communicating with each other.
They are able to do something.
They are able to finally come up with a conclusion.
See?
Then again, let's let's go step by step.
Uh, by this, you'll be able to understand thought.
I need to research each trend, gather information about description, pros, cons, and overall search
the internet again.
Search the internet.
I tried using the same.
I must stop using the action.
I'll try something else instead.
I need to research each trend and gather information about description, pros, cons and all.
Again, search the internet.
Then this was the personalized results.
Um.
Then again thought I need to research each trend and gather information so it is continuously doing
that work.
Uh, understanding the thoughts, trying to communicate.
So thought I know the final answer, final answer.
This this this this all.
The final answer is over here.
Then the finished chain is here.
And here you will be able to see this in my entire article.
Thought I know the final answer.
The next big trend of AI explainable AI in responsible AI.
So it is just still exploring.
It is trying to gather more and more information.
Finally, this is your entire, uh, page that we really wanted to create, our news page that we want
to create.
And again, here also you have this particular blog page, right?
So this entire blog page is also there.
So I hope, uh, you were able to understand this and just in, you know, hardly 30 to 40 minutes,
we are able to create this amazing application, uh, where multiple AI agents are able to communicate.
So yes, this was it for my side.
I will see you all in the next video.
Thank you.
Take care.