Describe tools with JSON Schema
Tool calling lets a model ask your code to run a function: you describe tools with JSON schemas, the model replies with a tool name and arguments, your code validates and runs it, and the result goes back. An agent is that exchange in a loop with a step limit, an allow-list and human approval for risky actions.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write validate_args(parameters, args) that returns a list of problems for missing, unknown and wrongly typed arguments.
Write run_agent(model, tools, max_steps) with a step limit that returns the final answer or "gave up".
Write safe_dispatch(name, args, tools, risky, approve) with an allow-list and an approval gate.
Explain it without notes
Describe the sequence of messages in one tool-calling exchange.
Why does an agent loop need a step limit and argument validation?
How would you make a tool that deletes data safe to expose to a model?
Your agent sometimes loops, calling the same tool again and again. How do you prevent it, detect it and debug it?
Expected output
tools sent to the model: ['get_weather', 'add']
{
"type": "function",
"function": {
"name": "add",
"description": "Add two numbers.",
"parameters": {
"type": "object",
"properties": {
"a": {
"type": "number"
},
"b": {
"type": "number"
}
},
"required": [
"a",
"b"
]
}
}
}