Tool use & function calling
Let a model request actions through well-described functions your code controls.
With tool use, you describe functions to the model with a name, a description and an argument schema. The model replies with a request to call one, your code runs it, and you return the result so the model can continue. The model never executes anything. Your code does, which is where you enforce safety.
Tool descriptions are prompts. Say what the tool does, when to use it and when not to, and what its arguments mean. Few, clearly separated tools beat many overlapping ones, because the model has to choose between them.
Return results the model can use: concise, structured, with helpful errors that say what to change. A bare stack trace wastes tokens and invites repeated mistakes.
Key points
- Your code executes tools. Validate arguments before running anything.
- Descriptions steer behaviour as much as the schema does.
- Fewer, distinct tools are chosen more reliably.
- Write error messages for the model, not just for logs.
Answer these out loud
- 1A model keeps calling search_notes with an empty query. What do you change in the tool, not the prompt?
- 2Which tools should require explicit human approval and why?
Use this from an agent
Any MCP client, including Grok, can read this lesson. See how to connect.
curl https://engineeros-delta.vercel.app/api/v1/topics/tool-use-and-function-calling