Defining Needed Agent Tools0:00
So now, if you think about it, if we're actually going to use this agent from meaningful work, there's just some things that it needs access to, some abilities, some tools. It needs to be able to run a shell script for sure. If I say, "Hey, run my tests and fix the bug," it needs to be able to run the test. So it needs some way, some tool that will allow it to run a given shell script or bash script. It needs to maybe read a file.
or bash script. It needs to maybe read a file. We've already made that one, maybe edit a file, maybe clog, maybe list the files within a directory. So as you know, it can technically do all of that via a simple shell script, but still we will often wrap some functionality and dedicated tools just to help with clarity. It helps with clarity to know I executed this specific tool rather than this
clarity. It helps with clarity to know I executed this specific tool rather than this generic confusing shell scripts, right? It also just ensures that things are always handled in a very specific way rather than sometimes it does this to search the codebase, and sometimes it does that. We want it to be deterministic, so we wrap it up within a tool, okay. So yeah, if we were to open up our tool section, why don't we get rid of most of these or
So yeah, if we were to open up our tool section, why don't we get rid of most of these or just little examples, but maybe revenue could change to read file. Maybe we'd have another one for write file. Maybe we have one for run a bash script or something like that. Maybe we have another one to glob some files. One that I've often seen is like the ability to list files within a directory. I don't know if that's, yeah, well at it, it won't be hard to implement. Then maybe one to search within a file. Again, a lot of this can just be done through a bash script, but yeah.
Implementing Tools via Claude1:48
Then maybe one to search within a file. Again, a lot of this can just be done through a bash script, but yeah. So we have one to read a file, one to write file. Write file could technically include the editing of a file or it could just assume that we're appending to it. Let's see how this turns out. So I'm actually going to leverage AI here because that's going to take too long and it doesn't matter and you're not going to write it by hand either.
and it doesn't matter and you're not going to write it by hand either. So let's do this. Let's cheat in this case and we're going to switch to Claude, a real agent, to implement these for me. Good up, Claude. I know it feels like I'm cheating here. Check the tools directory. You'll notice that the file name dictates the functionality I desire.
Check the tools directory. You'll notice that the file name dictates the functionality I desire. Your job is to update each file to implement the appropriate functionality so that it can be used as an AI agent tool. Yeah, I mean, no reason to spend 20 minutes writing these out while making mistakes when this is boilerplate stuff it can do for me. All six tools are implemented. They followed the tool interface.
Reviewing Tool Implementations3:14
All six tools are implemented. They followed the tool interface. So yeah, let's just take a look at one real quick. If I wanted to read a file, we're going to give our agent the ability to read one of my files, then it's going to find the relative path. If it doesn't exist, we do the error handling that we talked about, otherwise it does file get contents. Fine.
get contents. Fine. Run a bash script. All right. Here's the name of the tool. You have to give it the command you want to run. So you can imagine the AI agent will be like, all right, I want to, what is it called? I want to run this bash script. Pest on tests features foo test.php and it will fetch the output.
I want to run this bash script. Pest on tests features foo test.php and it will fetch the output. Now it has the ability to do that. If we scroll down, it's going to use again process, run the process. If it's not successful, we grab the error output and return it. Otherwise we get the response from that script. You get the idea. Okay. So now we could have our simple chatbot agent. It's going to use these tools.
Wiring Tools Into Chatbot4:11
So now we could have our simple chatbot agent. It's going to use these tools. So in fact, why don't we just say update while we're using cloud, we might as well keep using it tools to use all of these new tools. Cool. So now we have our chatbot agent. We have instructions. You're a bit of a jerk and are sarcastic with every reply, but you help out with programming
You're a bit of a jerk and are sarcastic with every reply, but you help out with programming tasks. Cool. Let's now go into our agent command. We're going to once again return to our chatbot agent. And we got rid of our while. That's okay. We'll say while true. Paste that in.
Testing Agent on Project4:54
We'll say while true. Paste that in. We're going to prompt it with what is on your mind. And then I'm going to dump the response. All right, let's boot it up. Hey there. All right, what are we working on today? List the files in the project. All right. And sure enough, we can see the general structure.
All right. And sure enough, we can see the general structure. Create a new file called test.nd in the project root. See if that works. Done. I created test.nd in the project root. So again, it's just doing that via tools. So we have test.nd in the project root. Change the heading of that file to blah, blah. All right, I updated it.
Change the heading of that file to blah, blah. All right, I updated it. And if we switch back, and knew that we were still referring to that file, you get the idea. All right, next, what framework am I using for this project? All right, so it's, again, being very sarcastic, you're using Laravel. Take a Laravel route endpoint for about, and have it return the string about me . Now, keep in mind, because of the tweak we made, we're not seeing the tools
. Now, keep in mind, because of the tweak we made, we're not seeing the tools that are being run, but we can still hook into that. We could even fire events each time a tool is run, pick up on that, and then handle it. We just aren't doing that right now. Okay, so I added the about endpoint to route slash web. So let's take a look. Yep, it works.
So let's take a look. Yep, it works. And again, that's all via tools. So in fact, why don't we just cheat real quick in our agent? I'll just say, I'll just do it directly in here, even though we shouldn't. Running tool call name, I'm not going to show the arguments, but just to show you what's happening here. All right, so once again, PGP artisan agent, don't forget because I don't have a guidelines
All right, so once again, PGP artisan agent, don't forget because I don't have a guidelines file. I don't really know anything yet, and that's part of what some of the good agents actually do. They understand that they need to learn before they start providing an answer. Anyways, this is a Laravel project. Add a contact route that returns the string, contact me. Same thing.
Add a contact route that returns the string, contact me. Same thing. All right, so it's running glob, it's reading the file, and again, I don't have the arguments there, but it would read the routes file. It would use the update file tool to update this. It adds this N. All right, let's once again, test it. We already know it's going to be there. But yeah, now we have an agent that is capable of interacting with and working on our code
Wrapping Up Key Patterns7:52
But yeah, now we have an agent that is capable of interacting with and working on our code base. So very cool. All right, so in conclusion, what was the goal here? Is it for all of us to build our own little personal software versions of Cloud or chat TPT? Absolutely not. You should still use those.
Absolutely not. You should still use those. The point of this is to demonstrate the general workflow and the pattern. And we've learned that it's a loop within a loop. We need a way for the AI to decide what it wants to do next, and then do that thing, and then respond to that thing, and then do something else again, and that's what the loop allows for. And then, of course, we need to offer it a series of tools so that it can
loop allows for. And then, of course, we need to offer it a series of tools so that it can interact with your code base. But second, we're not all just building chatbots here. We can build agents that are going to work within our code base as we saw here. We built a simple little grammar assisting agent. And this agent is custom. It has its own system message. It has its own structured output that we must conform to.
It has its own system message. It has its own structured output that we must conform to. And you can build as many of these as your application requires. So as they say, the sky is the limit.
