StudyAIStudyAI
Pro
AI AgentsLesson 2
Lesson 28 min

Tool Use

How LLMs call functions via JSON schemas.

What you will learn
  • How tools are described to a model
  • The request/response flow
  • Designing good tool definitions

Explanation

You give the model a list of tools, each described as a JSON schema (name, what it does, and its parameters). The model can then choose to 'call' a tool by outputting structured arguments.

Your code runs the actual function (e.g. fetch the weather), returns the result to the model, and the model uses it to answer.

Clear names and descriptions matter — the model decides when to use a tool based entirely on how you describe it.

Code Example

json
1
{
2
  "name": "get_weather",
3
  "description": "Get current weather for a city",
4
  "parameters": {
5
    "city": { "type": "string", "description": "City name" }
6
  }
7
}
Real-world use

Every 'AI that can browse / run code / check your calendar' feature is built on tool calling like this.

Common mistakes
  • Writing vague tool descriptions, so the model calls the wrong tool or skips it.
Practice

Write a JSON tool definition for a function that sends an email (to, subject, body).

Knowledge check
0/1 answered

1. How does an LLM know what a tool does?

Answer all questions to check.