Transcription
Hello everyone, welcome to my channel. Do you want to build your own AI agent that actually runs custom tools?
In this video, I will show you how to do that exactly using GitHub Copilot SDK. No fluff, just a step-by-step guide to creating a real agent that thinks, responds as well as executes your logic.
So, this is the third video in my series of GitHub Copilot SDK. And let's get started with something interesting today. Let's understand what we are planning to build. So we are building a Copilot agent that can call custom tools and custom tools can be anything. It could be a simple calculator application. It could be a weather fetcher or even you can build your own file summarizer. So this is not a chat rather it's a real interaction.
So if you want to know how to do your development machine setup, then I would recommend you to watch my the very first video in the series because in that video I have explained what this SDK is all about and how you can get started.
So we will start by building two custom tools and we'll show you how to define those tools in a very simple manner and then we'll wire that or wire those tools inside our agent. Once this is done, we will go ahead and define our agent where we will give some name, we will give some personality and then we will uh define like what all tools our agent can use. So once it is done, we will go ahead and test this particular agent with the two to three scenarios and see how it behaves in all these different scenarios.
So if you are impressed till here, then let's go ahead and check everything in real application. So I'm on my VS Code and make sure that you have installed the GitHub Copilot SDK before moving here and you have an active subscription.
So the very first thing you need to do is make sure that you are importing these particular packages. The Pydantic we need because we need to define the parameter types and the classes. So this is where we need BaseModel as well as Field. Then we have CopilotentClient which is the base for creating our agent. And then we are also taking this define_tool. So define_tool is the mechanism to tell the agent that these are the functions you can use as a tool.
So let's talk about the very first tool which I have defined here and that is for greeting a person. So here I have defined a class GreetingParams which is taking BaseModel as a uh because this is from where uh this is the place from where we are creating our own uh class. So this is what we are inheriting here. Then we are saying that define_tool. So define_tool you can take as a decorator and here you need to define the name of your tool which you are supplying in your agent. So it should match exactly what you are defining with your within your agent. Then you need to provide some description which signifies that okay, this tool is doing this particular thing.
So if I will just remove the space here and here is my actual function, the Python function which I have defined and this is the function which will behave like a tool for our agent and here I'm doing very simple line of code. The very thing first thing is I'm printing it because I want to know whether this tool is actually called or not. So this is optional but it is always good to go when you are testing it for the very first time. Then I'm saying hello and the name of the person whom we are greeting and hope you are having an amazing day. Oops. Yeah. So hope you're having an amazing.
So this is one tool. Then I moved on to my another tool which is to invite any person for the party. So here I'm defining this particular description for my parameter and this is my new function which is invite. Here again I am just providing some text message. I'm returning this as a string. So these two are the simple functions but in your functions but in your case you can define any complex functions or you can reuse the functions which you have already defined using your programming language. Now again, we are not restricted to Python. You can go with NodeJS and there are many languages which are supported by SDK. So feel free to check out my very first video.
Now coming to the agent implementation part. So whenever you are creating an agent, the very first thing is you need to start the session. So when creating a session, you need to supply which model do you want to use and here comes the trick. So this is the list of uh this is the list where you need to supply all the tools. So in our case we have just two tools. So there is again a possibility that you are having any number of local functions defined in this file. So in that case, it will not be taken as a tool because as far as you are not adding those functions here, as far as you are not defining them with define_tool decorator, you are good to go. But again, when you are doing production application, definitely all these tooling code will go to separate file altogether, but make sure you are defining this line number 42 correctly with the list of all the available tools you want to set for the agent.
Now these are just for the logging purpose to tell the user that what this tool is all about. Now here comes the important part, the event handling part. So here we are saying start the event and whenever the event type is assistant message, then only give that as an output because this is what the assistant is giving us rather than the user, we want to take a look at the assistant message. Then you also have a tool calling. So this will be automatically called by the SDK to decide which tool needs to be invoked. So this is the tool call and then once it is done, it will fall into the idle state. Okay.
Now here, this is a simple Python code where I'm running in an infinite loop to just so that we can keep giving our queries. Okay. So I will quickly get into this and I will execute this. So I will say app.py and it should start the agent. So let me pull it up a little bit here. You can see these are just for the user's knowledge. It's not mandatory, it's just for the information that what this particular agent is doing. Okay. Okay.
Now the very first question I'm going to say is greet my and let's see whether it is going with the traditional way or it is actually using. So that is the reason I did my logging and here it is saying it actually called my tool which we have defined it over here. So here you can see hello, then name and hope you are having an amazing. So this is what we received it over here. Let me try one from the invite tool. Let's say invite Ruby. And again, you can see that it has called this particular tool and Ruby, you're officially invited to the event. So this is what we are seeing here.
Now these are the very uh simple scenarios. Let me show you a scenario wherein you need to invoke multiple tools at at once. So for that, we can write something like greet Maria and invite her to the party. So in this case, I'm hoping that it should collect information from both of these tools and then tell me. So hello Maria, hope you are having an amazing day. So this is what we received from our greetings. Then Maria, you are officially invited to the event. So the best part here is although I said invite to the party, but my actual tool wants to split invite to the event. So that's what you are seeing it over here. So irrespective of whatever the natural language you are using, the system will still follow the rules which we have defined inside our tools. So that is the best part and initially you may face some difficulties to plugging uh in plugging these tools and making the system work, but if you are following all the guidelines, then it should be very straightforward.
So I hope you enjoyed watching this and do let me know in comments what next scenario are you expecting. Thanks for watching.