StudyVisuallyStart studying
AI developers · Part 03

Tool calling

Describe functions with a JSON schema and let the model ask your code to run them.

Last updated

  1. What a tool isA tool is a function in your code that you describe to the model. The model can ask you to run it, but it never runs anything itself.
  2. Function schemaYou describe each tool with a name, a description and a JSON schema for its parameters.
  3. Tool descriptionThe description is the model's only clue about when to use a tool. Vague descriptions lead to wrong tool choices.
  4. The tool_calls replyWhen the model wants a tool, it replies with tool_calls (a function name plus JSON arguments) and its content is null.
  5. Arguments are a stringfunction.arguments is a JSON string, not an object. You must JSON.parse it, and it can be malformed or wrong.
  6. The tool messageAfter running the tool, you append the assistant's tool-call message and then a tool message with the result, linked by tool_call_id.
  7. Calling the model againTool calling takes two model calls: one where it asks for the tool, and another (with the result added) where it writes the answer.
  8. tool_choiceA parameter that controls tool use: "auto" (model decides), "none" (no tools), "required" (must call one), or a specific function.
  9. Parallel tool callsThe model can request several tool calls in one reply. Run them all, then send back one tool message per call.
  10. Tools give data and actionsTools do two jobs: fetch data the model doesn't have (an order status) and take actions it can't take (create a Jira ticket).