Asked about How tool calling works
Walk me through what happens when a model calls a tool.
An answer that works
You send messages plus tool definitions. The model responds with a structured request naming a tool and arguments rather than a final answer. Your code executes that function, appends both the request and the result to the history, and calls the model again. The model then answers using the result. It never executes anything itself.
Then they push further
Where does the tool actually run?
In your application. The model only produces a structured request naming a tool and its arguments. Your code validates it, decides whether to run it, runs it, and sends the result back in the next request.
What do you check before running it?
That the tool exists and is allowed for this user, that the arguments pass the schema, and that the values make sense, such as an order id that belongs to this customer. The model's request is untrusted input.
What if the model asks for a tool that does not exist?
Return an error result that says so and lists what is available, and let it try again. If it keeps happening, the tool names or descriptions are probably confusing.
What gets marked up
Marked up for treating the model's tool request as untrusted input that must be validated and authorised. Weak answers imply the model runs the tool itself.
Reading an answer is not being able to give one. The section that teaches this is How tool calling works, 3 hours of Tool calling.
Learn this properlyAlso asked about Tool calling