ai agents / function calling / agent tools
The ONE Trick That Turns ChatGPT Into An AI Agent (Tools)
Course walkthrough
AI Agents from Scratch
All lessons in this series
- 1I'll Teach You How To Build AI Agents From Scratch (10 Billion Tokens Proof)
- 2What Is An AI Agent? (ChatGPT Doesn't Count)
- 3The ONE Trick That Turns ChatGPT Into An AI Agent (Tools)
- 4The ReAct Loop: How Cursor & Claude Code Actually Work
- 5The System Prompt That Changes Everything (Prompt Engineering For AI Agents)
- 6How To Make Your AI Agent Truly Autonomous (Without It Going Rogue)
- 7How To Trigger An AI Agent (5 Different Ways)
- 8Subagents Explained: How AI Agents Launch Other AI Agents
- 9Simple Memory: How AI Agents Remember Between Runs
- 10How AI Agents Actually Remember (Memory + RAG Explained)
- 11How To Actually Tell If Your AI Agent Is Good (Evaluation)
- 12The Complete Guide To Building AI Agents (10 Lesson Recap)
Tools are THE key insight that separates a boring language model from a real AI agent. They're how the AI executes code, hits APIs, runs SQL queries, and actually does things in the real world.
In this lesson, I show you exactly how tool calling works — using a real production example from NexusTrade (my AI trading platform).
You'll learn: → The two ways AI agents do things: code execution and JSON-based tool calls → How to structure tools so the language model knows when to call them → JSON-based function calling — the pattern behind every modern AI tool → How to feed tool outputs back into the conversation → A real production system prompt that powers an AI agent in the wild
By the end, you'll know exactly how Cursor, Claude Code, and ChatGPT execute code, search the web, and run SQL queries on your behalf.
This is Lesson 3 of "How To Build AI Agents From Scratch" — a free 10-lesson masterclass on building production-ready AI agents.
#AIAgents #FunctionCalling #JSON #LLM #ToolUse
Transcript
0:05Welcome the next video in the how to build your own AI agent course In the last video we talked about ChatGPT and how it's a wrapper app
0:17around a large language model We also talked about how large language models don't actually know information particularly when it comes to real time information And then we talked about this
0:32little hack where if you just copy and paste the information into the system prompt and then when you ask the AI the question it will actually know the answer And this fact this little
0:45hack here is sort of the basis on how AI agents work In this video I'm going to be talking about two ways to get your
0:57AI agent to actually do things This forms the basis of tool calling a very important concept within AI agents
1:10So let's start with the first one that's most obvious having your AI execute code Let's return here Let's clear everything and let's ask the AI let's say
1:24you are a coding assistant You generate Python code that looks correct
1:37Then I'm going to say here I want to back test a trading strategy If you say this and the system prompt is designed to actually generate code
1:50then the AI will generate a message to generate code Let's see what the AI actually outputs
2:05Now what you can do is take the code that the AI generated copy paste it into cursor and then you can execute that code
2:17and then forward the response back to the AI agent That's one way you can have your AI actually do things You can think of an example
2:30of having the AI call a stock market API or having the AI just execute any code that you want the results of That's one way of having
2:44your AI to actually do things The second way of having your AI do things is not to generate code but to generate inputs to API
2:55calls or generating JSON objects As quickest roughest definition of a JSON it is simply a standardized format
3:08that allows you to communicate with other people's servers You generate this JSON object that has these little curly braces it has these param names and if
3:21you send this between servers then you can send a response Now in my system prompt I'm telling the LLM to generate a JSON object for a trading strategy I'm going to
3:36type in my strategy here buy and hold spy and the AI is going to respond in a syntactically valid JSON object just like this Now you can
3:49imagine by itself this doesn't do anything but what if you had some function and some API that took a strategy as input and as output it
4:03will return performance metrics how that strategy performed between start date and end date Now that you have this JSON object you can just paste it right here You can execute the code
4:18the code will do something and then it will give you back a response which you can paste back into the language model
4:30This is what we call a tool A tool is when you generate a configuration and then you execute some API call and get some sort of
4:43response back Now these tools are the key difference between a regular language model and an AI agent They actually allow your AI to do things You can within the system prompt you
4:58might want to tell it other tools it can have You might want to define an interface for a backtest You might want to define an interface for a deployment You can define all of
5:10the tools here and the language model will know how to create the right JSON object depending on what you want to do To
5:24make this hit close to home I'm gonna show you a real world system prompt that I'm using for my production AI agent You can see it has all of these instructions I tell it
5:38to respond in JSON I have this mode called force JSON mode I have a bunch of instructions for the language model to
5:50follow I also have a list of examples so the AI has something to sort of go off of We can see that the AI is responding
6:02within this JSON object You know it has this SQL query and if I copy paste this query and I remove all of the little new line Let's copy paste it here
6:17Let's erase these new lines If we execute the query we see we get a real answer based on fact This is simply a SQL query against the database This is just one of my
6:32prompts When you ask this question but under the hood it's going to generate this query and also this graph If I ask this same exact question within
6:44Nexus tray you can see what happens While it's actually responding with this SQL under the hood what it's going to do is execute the query and then
6:58show the results to the user You can see it's thinking it's executing the query and we can see the answer It summarizes the answer for us and then it presents these results in this
7:13nice pretty looking graph which you can also see in a table But this here is basically the same thing as this here I'm just executing different API
7:27calls in the backend This is the critical thing that makes an AI agent an AI agent The ability to
7:38execute tools to actually accomplish some sort of task In the next video I'm going to be talking about orchestration and how we can go from this
7:51a simple back and forth conversation between an AI to a fully autonomous or semi autonomous AI agent that can actually do things on your behalf This might
8:06be the most important video so far so tune in right now
Join the conversation
Loading conversation…