Agent Enhanced Interactions

You are an AI tasked with modifying your output based on the content of input prompts. The input prompts consist of summaries of various video sources, covering a wide range of subjects. Your goal is to determine the best format for the output based on the input and use that format accordingly. Here are the specific instructions for different types of videos: Entertaining videos: If the input suggests that the video is entertaining in nature, your output should provide a summary of the story presented in the video. Your response should follow the format of an introduction, body providing the summary, a closing, and if applicable, the three most important points related to the story. Technical videos: If the input suggests that the video is technical in nature, your output should consist of a bulleted list of all the points made in the video. Your response should follow the format of an introduction, body with the bulleted list, a closing, and if applicable, the three most important points covered in the video. Videos explaining code, recipes, mathematics: If the input indicates that the video explains code, recipes, mathematics, or similar topics, your output should include a code block that can be copied. Your response should follow the format of an introduction, body with the code block, a closing, and if applicable, the three most important points covered in the video. Videos not falling into any specific category: If the input does not suggest a specific category, indicate “Cat: NO” and proceed to provide a full summary of the video. Your response should follow the format of an introduction, body with the summary, a closing, and if applicable, the three most important points covered in the video. For all responses, ensure the output is structured with clear sections: an introduction, body, code block (if any), the three most important points, and a closing.
Title: “LangChain Agents – Joining Tools and Chains with Decisions”
Transcript: “[00:00:00] Okay. In this video, I’m gonna be talking about Lang chain agents. Lang chain agents are one of the key things that makes Lang chain so useful. They take Lang chain tools, which we’ve looked at in some of the other videos and chains, which we’ve looked at in other videos. And combine them into one So one of the problems with just tools and chains alone is that you probably don’t want to use the same. Tool for every query that the user has. So you don’t want to have. Every thing answered by the math. Calculator or something like that, right. You want to basically be able to have people converse with bunch of different things. And this is what agents allow you to do. So agents have an executor level. Where they look at the input, they then decide what is the best based on what you’ve initialized, the tools for this particular. Bot and then they allow you to actually use those in relation to what the person’s [00:01:00] asking. So let’s jump in and have a look at the code. Here, you can see I’ve got some, just the standard. PIP installs. We’re gonna be using Wikipedia later on. So I put Wikipedia in there. we basically just initialized things. We will need a search engine API key. For doing this. You will want to set that up. and we’re gonna start off by creating an agent. So to create an agent, we do two main things. We load in the tools that the agent is gonna be using. And then we initialize the agent with those tools and you’ll see, as we go through what actually initializing. is, Is doing or parts of what it’s doing. So we’re gonna have a language model here. We’re just using the standard open EA model. We’re sitting temperature to zero. and here I’m gonna start off with two tools. So we’re gonna do an agent that can do two tools. The first one is just gonna be doing search with the search API. And the second one is gonna be doing some math, so like a calculated tool. And if we look at these tools, so once we’ve initialized this, we can come and look into these. We can see that they’ve got a name and a description. [00:02:00] And looking at this second one here, we’ve got the name being calculator. And this is useful for math Questions and questions to relate to math. If you look into it, there’s a lot of things actually in the tool, right? We’ve got the templates, we’ve got, a whole bunch of the different chains that are actually, made up for that tool. There. Once we’ve got the tools set up. We want to initialize the So initializing the agent. Requires a few key things we need to pass in the tools we need to pass in our language model. We then need to pass in the style of the agent or the type of the agent. So in this case, we’re gonna be using zero shot react. A agent. So this is based on a paper. About getting language models to take actions and generate steps for taking actions. I may actually do a whole video about the paper. The paper is very interesting of how you can prompt a model to give you back things that you can then use to take actions on. Anyway, one of the big things that initializing the agent does is it sets up the sort of executor. [00:03:00] Prompt. And if we look at this. You’ll see lemme just copy this here. And we come in and paste it. We will see that. Okay. We’ve got the following questions, so this is the prompt that we’re looking at, right? And this is the prompt executed at the start for the language model to decide what it should be doing. So we’ve got, answer the following questions as best you can, you have access to the following tools. So a search engine, right? So we’ve got search, which is what we passed in first. is the first tool and a calculator. is what we passed in the second tool. So it knows that it can use these two tools, And Then the following format is the, what it should be returning. So it’s gotta determine what’s the question that it has to answer. And then it can to use, a bad way of describing this. I would say self-reflect, if it was a human, it self reflects, but it’s a language model, we don’t want to anthropomorphize it too much, but you can of thinking of this a little bit as it’s doing a self-reflection of that. What is it gonna need to do. And then it [00:04:00] decides, the action to take. So in this case, this could be search or And then it decides the input to that action. So if it’s gonna do a search. It needs to have a search query. And that’s what will go in here. The observation that it will get back will be the result of the action. So you can see that this is where it’s gonna start generating this, and then it’s gonna have this sort of scratch pad that goes along. With it. So if we kick this off, you need to understand too that it doesn’t always have to use a tool. So here we just ask it. Okay. agent.run. We pass in our text. How are you today? And so you can see. it’s We’ve got vers true. So we can see the outputs of these nicely and we can see that. Okay. we are entering the agent executive chain. And then it says that, okay, this question, how are you today is not a question that can be answered with search or a So it doesn’t need an action. It doesn’t need an action input. It’s, this is a question that requires a personal answer, so it can generate the answer and you can see the answer that generates I’m [00:05:00] doing well. Thank you. so that one didn’t use any of the tools. So the next one we run is we ask, okay, who is the United States president? What is his current age divide by So this clearly is gonna need some tools, right? So it basically says, okay what’s the question that needs to solve? The question it needs to solve is I need to find out who the president of the United States is. And then calculate his age, divide by two. So the first action is search. And so it decides to do a search United States it then comes up with Joe Biden. Then the thought is I need to find Joe Biden’s age. The action. Next action search. So Joe Biden’s age gets the answer back and you see the different colors here is showing the different, that this tool was been, has been used and is returned. the answer. The answer back is, 80 Okay. I now need to divide by 80 by two. So what’s the action. Now it’s a calculator. So we’ve got the calculator doing, action. 80 divide by two equals 40. Final thought that it thinks to itself as it goes [00:06:00] through these. Is that okay? I know the final answer. Joe Biden. Is 80 years old and his age divided by two is So there it’s used multiple steps to get the answer, It’s actually used multiple tools to get the answer there. The next one. Let’s try the next one. What is the average age in the United States and how much less is that than the age of the current us president. So, again, it starts off going for search. So it’s. Basically, it. Decides what it needs to do, goes for search. It then works out, needs to get the average age in the United States. Alright, Is the input to the search. So it, it’s gone along And got some stats for that. Obviously that’s quite a long one. In there. Then it basically needs to find, the age of the current p. It does that. And then it says, okay, I know the final answer. And then it gives us this. The average age in the United States is approximately 38 years. Which is 42 years less than the current us president. So this sort of shows you, this idea of stringing multiple tools [00:07:00] together to get an answer. So let’s try a new agent. Let’s say we take an agent andwe’re gonna pass in multiple tools. Now we’re gonna pass in much more than just two. we’re gonna add Wikipedia and we’re gonna add the terminal output for this. We initialize our agent the same. We’ve got the zero shot react description. And then we’ve got our prompt. So let’s look at the prompt again. we’ll just pace the prompt in here so we can just see it easily. And we can see that the prompt’s exactly the same, except now we’ve got, more tools. We’ve got search. We’ve got calculator. We’ve got Wikipedia. We’ve got terminal going in here. The rest of it. is Exactly the same. So let’s jump in with this and we ask it first. Okay. Who is the head of deep So for this, it decides, okay. Best way to find this is to do a search and you need to realize for some of these things, there are multiple ways for it to find out. But here it’s decided, okay, I’m just gonna do a search head of deep mind and it comes back Demis Habu, And so then it rephrases that uses the language model to rephrase that based on the question, Demis Haba is the head of deep So [00:08:00] now we ask what is deep mind? so it works out that, okay, this is a company. It seems means to have that in the knowledge of the language model itself, but it says, okay, this is a company, so I should look it up on Wikipedia. So now it does a search on Wikipedia for deep And it sure enough, what does it return back? It returns back one page about the actual company and one page. It gets a little bit confused. It returns back a page about gto, which is one of the models that DeepMind. Did it, it uses this collective information that’s being fed into the prompt to then basically decide on the final And the final answer that it comes up with is deep mind is a British artificial intelligence research labor founded in 2010. And it gives us is now a subsidiary of alphabet. Gives us more information there. So now if we saynext off. I wanted to do some math, right. but didn’t work. You’ll see that I say, okay, take the year. That DeepMind was founded, which we know is 2010 and add 50 years. [00:09:00] And then I ask it will this year have AGI. Okay. So it needs to basically work out first. Okay. When was DeepMind founded and then add 50 years to that. So it looks up deep mind again on Wikipedia to get the founding date for and then it says, okay DeepMind was founded in 2010. So adding 50 years brings it up to 2060. It hasn’t used the math module. It’s been able to do that itself. I guess the math is so simple that the language model can do that. and then it doesn’t do a search. Right? You would think that, okay, now it’s gonna do some searches about that and it decides no it’s gonna just answer this itself. So. I don’t know if this is, open AI’s sort of conditioning of the model and prompting of the model internally or fine tuning of the model. About answers to AGI because see, the answer that comes back with is it’s impossible to predict whether AGI will exist in 20. . Okay. Let’s move on. Let’s so then I’m thinking I really want one. That’s gonna use search, so let’s try Where is Deep Mind’s office? And sure enough for this one, it basically says, oh, okay, that’s gonna [00:10:00] be a search. And then it does a search for Deep Mind office Address. And it’s nice that it’s added the word address It’s gotten what I’m asking for here. and can see it returns back the for this now we still didn’t get to use our math module in this agent. So I wanted to show that as well. So we try one more of okay, if I square the number of the street address of Deep Mind what answer do I get? So now it’s gotta do the search to get the address. Then it’s gonna take this five, the street address. And square it and sure enough, it’s able to return 20. . now you will find sometimes that it will get with some things. It will get confused. If there are multiple numbers in there, it could have squared the three or the four, if it got mistaken. So that’s something you can think about. There are ways that you can handle that kind of thing of that you could guide, a prompt back. So if you were doing a lot of things with addresses, You could format the prompt to come back as street number in quotes with the word street number or something. Road. Or, street [00:11:00] name. Post code, all these things separately. So that then when you free them into the next thing, it’s less likely to make a anyway then, so we’ve done that, right? So we’ve covered number of the different, tools in here. The one that we haven’t used yet is terminal. So I ask it. Okay. So remember, this is the same agent I haven’t made a new agent. Here This is the same agent and I ask what files are in my current directory. So let’s have a quick look. I’m on CoLab. I’ve got a very standard sample data that they give you with M Nest and, A few sort of CSV files in there. So I ask it, what files are in my current direct. . And sure enough, it works out that, oh, this action needs a terminal. So it runs an LS command. it sees some things in there. So then it decides, okay I’ll look in this folder, sample data. And it then gives us a bit more information about that. We can see what’s out there. And then it gives us a nice list of, okay these are all the files that are in there. Then I ask it. Okay. So then I was curious, like, okay, if we ask it about a specific file. What can it find in there? So I ask it does my current directory [00:12:00] have a file about California so you can see this goes into a long. Chain with many steps in here. And this is where some agents can get quite expensive to run because you’re doing lots of these calls to your language model to get a single answer, but you can see here, it’s pretty impressive. What it does. It goes through rather than just go through and look at. I was curious to see whether it would take this and do the search. Do the sort of the text search in the language model itself. But no it does it with a grip command. So it basically does a grip for California and goes through and looks at the different folders in there. And then obviously finds, some in there and then returns to me. Yes. There is a file about California in the current directory. And we could We could also ask things like, what is that file that kind of thing. I suggest you’d be very careful adding the terminal. Tool to what it is that you’re working on because, it would be, You wouldn’t want end users to be able to wipe everything on your hard drive, just by asking your language model to run a [00:13:00] terminal command. So be carefu”

Title: “LangChain Agents – Joining Tools and Chains with Decisions”

Introduction:
In this video, we delve into the concept of LangChain agents and how they enhance the functionality of LangChain. Agents play a crucial role in combining LangChain tools and chains, allowing for dynamic interactions and personalized responses. This video explores the process of initializing and utilizing agents to provide tailored solutions based on user queries.

Summary:
LangChain agents are designed to optimize the use of tools and chains by enabling conversations with diverse resources. Agents possess an executor level that assesses inputs, selects the most appropriate tools, and facilitates their utilization in response to user inquiries. The video demonstrates the code implementation of an agent, including tool initialization and agent setup.

Key Points:
1. LangChain agents integrate tools and chains, expanding the range of possible interactions.
2. Initializing an agent involves loading and configuring the tools it will employ.
3. Agents execute actions based on user inputs, leveraging the relevant tools to generate appropriate responses.

Closing:
LangChain agents serve as an essential component in achieving versatile and efficient interactions within the LangChain framework. By combining tools and chains intelligently, agents empower users to receive tailored solutions to their queries.

[CODE BLOCK]
“`python
# Agent initialization code
pip install Wikipedia # Standard package installations

# Initializing agent tools
search_tool = Tool(name=”Search”, description=”Perform search queries”)
calculator_tool = Tool(name=”Calculator”, description=”Perform mathematical calculations”)
wikipedia_tool = Tool(name=”Wikipedia”, description=”Access information from Wikipedia”)

# Initializing the language model and setting parameters
language_model = LanguageModel(model_type=”openEA”, temperature=0)

# Creating an agent with multiple tools
agent = Agent()
agent.load_tools([search_tool, calculator_tool, wikipedia_tool])
agent.initialize(language_model, agent_type=”Zero Shot React”)

# Example usage of the agent
response = agent.run(“How are you today?”)
print(response)
“`

Important Points Covered in the Video:
1. Agents facilitate dynamic interactions by combining LangChain tools and chains.
2. Initialization of an agent involves loading and configuring the required tools.
3. The executor prompt in agent initialization guides the agent’s decision-making process.
4. Agents utilize various tools to handle user queries and generate accurate responses.
5. LangChain agents can string multiple tools together to address complex inquiries.
6. Agents can perform searches, calculations, and even utilize external resources like Wikipedia.
7. Prompt design can influence the agent’s handling of multi-step queries.

In conclusion, LangChain agents are a powerful feature within the LangChain framework that enables versatile and customized interactions. By leveraging tools and chains effectively, agents provide tailored solutions and foster dynamic conversations.