Hello guys.
So we are going to continue the discussion with respect to tools and agents.
Now, uh, already in our previous video, we have seen that how we have created tools, uh, even we
have also created our custom tools.
Right.
Now it's time that we combine this tools along with our LM model, along with if I really want to execute
this, I will be using something called as agent executor.
And that is where we are going to learn about agents.
So first of all, let's go ahead and use, uh, some LM models.
And again for this I will be using the grok API which we have specifically used over here.
So in order to use grok I will just go ahead and open this quickly.
I will go ahead and search for this dot env.
And I also require my opening API key.
Right.
Let's go ahead and use this LM model.
So here uh is my entire code right.
And for this I will.
Okay.
TX dot secrets.
Okay, I have to go ahead and just write import OS.
And finally, you'll also be able to see that I will go ahead and write OS dot os dot get env.
Will be with respect to my and similarly OS dot.
OS dot get env will be my open API key, right?
And uh, for this again I will go ahead and import open AI because I will require this.
And since I'm using Chat Grok API.
So obviously you know how to probably import this.
So for chat grok I will be using Lang chat underscore grok okay.
And I will go ahead and import it over here.
Right.
So I'm actually going to use this llama three model.
And already I've actually shown you how things are basically done you know.
So OpenAI API key is basically set to the API key.
The reason why I'm using OpenAI API key because for the OpenAI embeddings.
Right.
So here are the kind of embeddings that I'm trying to apply for this particular documents.
It will be from OpenAI embeddings itself.
Right.
So uh, I will be doing that.
And here, uh, I will go ahead and use this with respect to the get environment variable.
Okay.
Now this is my LM model.
Right.
Uh, and I'm using llama three specifically LM models.
Okay.
So this is the first step that we really need to do.
I'll go ahead and execute this I'm getting an error saying that okay.
Uh, Chad grok okay.
This OS dot get env okay.
This is the problem.
I will just go ahead and use my brackets brackets.
Okay, now it should work.
It's okay.
Uh, I am not deleting this error.
Whatever error we basically face, okay, whenever you get an error, never hesitate to solve it.
Okay?
And don't be afraid.
Errors are something which are simple, common mistakes that we do.
And it is fixable.
Okay, now we will go ahead and create our prompt template.
Now see guys, one example of creating the prompt template I've already shown you um in long chain.
There is also something called as hub.
You know some some different different types of uh, if I probably consider with respect to, uh, a
prompt, you know, is already created and uploaded in the hub.
Okay.
So today in this video I will talk about one way.
So I'll write hey from Lang Chen okay.
Lang Chen I'll say import hub okay.
And from this particular hub you know I will just go ahead and write.
Prompt is equal to hub dot pull okay I will say pull one of the type of prompt that is already been
created.
And when I was searching in the hub itself.
Right.
You'll be able to see something like OpenAI function agent.
So let's talk about this.
Okay.
So here, uh, what I'm actually going to do is that I will just go ahead and search about this OpenAI
function agent prompt.
Okay.
So in the OpenAI function agent prompt, if I go ahead and see it right, see to it.
So it uh, this is the prompt that is basically there.
And this prompt is basically getting displayed right here.
You have a system prompt message template.
You have message placeholder for the chat history.
Then you have human message prompt template.
Then you have this message placeholder.
So this kind of prompt is basically getting created.
And over here it says hey you are just a helpful assistant right?
But again, my uh, best practice will be that use always chat prompt template uh and then try to create
a prompt.
But here I wanted to show you a variety of ways.
So that is the reason I'm actually going ahead and showing you okay.
And here you can go ahead and write prompt dot messages okay.
So once I execute this here you'll be able to see this entire prompt is basically getting displayed.
Now I'm going to combine this prompt along with this LM and all the tools that I've actually created.
Right.
So if I want to execute all together in the form of chain.
So I have to specifically use agents.
Okay.
So what I will do, I will write from line chain dot agents okay I'm going to go ahead and write import
create.
Uh, one of the easiest way of creating agent is by using this open AI tools underscore agent.
Then you also have open API agents.
But I'm just going to use this open AI function agent is also there.
See.
So all these agents right.
So if I go ahead and show you in the documentation right.
And it's always necessary that see this is one tool and all are there.
Right.
Uh types of agents tool callings.
This is open AI tool.
Right.
So here you'll be able to see newer open AI models has been fine tuned to detect with one or more functions.
Right.
The goal of the OpenAI tools API is to be more reliable return.
You can basically go ahead and check out this documentation.
What is this?
OpenAI functions?
Uh, you saw one example over there, right?
And here it says that certain OpenAI models like GPT 3.5 turbo have been fine tuned to detect and not
see.
I'm using grok right now.
I don't know whether it is going to work or not, but let's see, you know, so there are multiple ways
of calling different, different tools also.
So here you also have with Google, you have with Mistral.
I don't know whether it will work with grok or not, but I'll just give her my best try.
If it works with grok, it is well and good.
Otherwise I'll just go ahead and change this entire model.
Okay, that is what I'm actually going to do.
So from Lang chain, uh, dot agents I'm just going to use one called as Create table open AI tools
agent.
So I'll go ahead in with this.
Again.
Please make sure that you watch these documentations.
Right.
Go ahead and check the documentation agent is equal to I will go ahead and write create open AI tool
agents.
And here I'm just going to specifically use my LLM model my tools and my prompt okay.
So I'll use this three.
And over here uh this specifically becomes my agent.
I will go ahead and execute it.
Go and execute it.
So here is the entire chain that is basically getting created.
And I'm using Chat Grok.
I think this should also work.
That is what I feel.
Uh but let's see.
Okay.
Once I have created my agent, I need to run this agent.
Right.
So for running this agent, we basically go ahead and create our agent.
executor.
Okay.
So I will go ahead and write from line chain, dot agents, import agent executor.
And from this agent underscore executor I will go ahead and write agent executor.
And here first of all I need to give my agent.
The agent is a combination of all these things which will be in the form of chain link tools and prompt.
Then along with this, I will also go ahead and give my tool section, which will be equal to this tools.
And I'll go and write.
My verbose is equal to true, so that I will be able to see the interaction how it happens.
Right?
So once I go ahead and execute this so this basically becomes my agent executor.
So here you can see chat prompt template is also included.
Input type chat history language and core message.
And all right just to give you an idea I've used a hub over here.
So that is the reason you'll be able to see the variable name will be chat history over here.
Right.
All the information the default variable name is input.
You can also go ahead and create this I think uh it will hardly take two minutes okay.
So now let's go ahead and finally execute our agent executor okay.
So I will go ahead and write agent executor.
Okay.
Dot invoke.
And here I'm just going to go ahead and write my input.
Because this is the key that we really want to know.
And let's say I go ahead and ask a question.
Tell me about Lang Smith okay.
So Lang Smith obviously it should go ahead and interact with our tool.
Right.
Let's see what happens.
So okay invoke let's go ahead and execute this.
So here you can see entering new executor chain.
And suddenly this language search has been opened up.
And this is what you are able to get the answer right.
Tell me about Langschmidt.
The result of the tool call ID is a web page about Lange Smith, a platform for building production
grade application.
Perfect.
Um, let's execute more.
Okay, I will go ahead and say hey.
um, let's see.
I'll go ahead and ask, hey, what is machine learning?
Let's see from where it will go ahead and pick it.
Whether it is just going to use the LM model center.
New executor.
Oh, it's meant to Wikipedia, right.
See, automatically.
Amazing.
Machine learning is a field of this.
There's this.
All the information is over here.
Uh, it is also going into the Lang Smith.
See?
But finally, you can see get started with Langschmidt.
It was not able.
I hope this response provides a good overview of machine learning and okay, it is also using the previous
history.
So this is the amazing thing right?
Uh, the the main reason of using this hub was making sure that this, this this one open agent function.
So here it is also recording the entire information about the chat history.
Right.
So here you can see that I'm able to get the answer.
Okay.
Let me just go ahead and ask one more question.
I'm just going to go ahead and ask about, uh, let's see what is in our save.
You know, if I go ahead and search for attention is all you need.
This is one of the famous research paper.
I'll just go and search for this number.
Okay.
Let's see where I'll get that number over here.
So this will basically be my number.
Okay.
And, uh, I will just go ahead and ask it over here.
Okay.
So I'll say, hey, uh, agent Dot executor, and I'll say, hey, just let me know, what is this research
paper all about?
Okay.
So let's see.
It should probably go to our chef.
See.
Beautiful.
Right.
And then we are searching about Wikipedia.
See how beautifully it is combined.
And here you can see all the response that is probably getting right now a part of the entire search
engine is actually completed over here.
But now in our next video, uh, I'm going to combine everything of this and probably, uh, you know,
implement it.
But at the end of the day, please make sure that you watch the documentation page.
You really need to understand how Agent Executor is here, what all options are specifically there.
You know, uh, how to probably combine this, how many number of tools you have to create, how to
create a common tools and all.
But later on, the maximum thing will be with respect to more about exploration, right?
So yes, in our next video, uh, I'm going to create our end to end search engine project.
So I hope you like this particular video.
I'll see you all in the next video.
Thank you.
Take care.
Bye bye.