Learning Hub/Prompt Engineering/Tool Use & Function Calling
08 / 10Composition

Tool Use & Function Calling

Defining tools, schemas, and multi-turn tool loops

Tool use lets the model call external functions — search APIs, databases, calculators, code interpreters — and incorporate the results into its response. Effective tool definitions require clear names, precise parameter schemas, and unambiguous descriptions that tell the model when and how to use each tool.

Language models cannot browse the web, query a database, or run calculations natively. Tool use bridges this gap: you define a set of available functions with their names, descriptions, and parameter schemas, and the model decides when to call them. The model outputs a structured tool-call request (function name + arguments), your application executes the function and returns the result, and the model incorporates the result into its final response. This is the foundation of agentic AI — the model reasons about which actions to take rather than just generating text.

The quality of tool definitions determines whether the model uses tools correctly. A tool name should be a clear verb phrase (search_documents, get_weather, calculate_price). The description should explain when to use the tool — not just what it does. "Search the knowledge base for technical documentation. Use this when the user asks about product features, APIs, or configuration" is far more useful than "Searches documents." Parameter schemas should use specific types (enum instead of string where possible), include descriptions for each parameter, and mark required vs. optional fields explicitly.

Multi-turn tool loops occur when the model needs to call multiple tools sequentially — for example, searching for a product, then looking up its price, then calculating a discount. The application must handle the loop: send the tool result back to the model, let it decide the next action, and repeat until the model produces a final text response. Error handling is critical in tool loops: if a tool call fails, the model should receive the error message so it can retry with corrected parameters or inform the user rather than hallucinating a result.

Key Concepts

  • Tool use lets the model call external functions and incorporate results into responses
  • Tool names should be clear verb phrases; descriptions should explain when to use each tool
  • Parameter schemas should use enums over strings where possible, with per-field descriptions
  • Multi-turn tool loops repeat until the model produces a final text response
  • Always return tool errors to the model — let it retry or inform the user rather than hallucinate