Function calling (or tool use) lets a language model ask your application to run a specific tool, such as a search, a database query or an API, with structured arguments. The model never runs code itself: your app validates the request, runs the tool, and returns the result for the model to use. Repeat this in a loop and you have an AI agent.

How does tool use work, step by step?

  1. Describe tools: you send the model a list of tools with names, descriptions and a JSON schema for their arguments.
  2. Model decides: for a user request, the model either answers directly or returns a tool call, for example get_train_status with {"train_no": "12301"}.
  3. Your code validates and runs it: check the arguments and permissions, then call the real function.
  4. Return the result: send the tool's output back to the model.
  5. Model continues: it answers the user or calls another tool.

How do you define good tools?

PracticeWhy
Clear names and descriptionsThe model chooses tools from their descriptions
Strict argument schemasFewer malformed calls; easier validation
Small, single-purpose toolsEasier for the model to pick correctly and for you to test
Helpful error messagesThe model can recover by retrying with fixed arguments
Read-only by defaultWrite or payment actions should need confirmation

How do you keep tool use safe?

  • Validate every argument on your side; never trust the model's output blindly.
  • Give the narrowest permissions possible (allow-lists, scoped API keys).
  • Ask a human before irreversible actions such as payments, deletions or emails.
  • Treat tool results from the web as untrusted input that could contain prompt injection.
  • Log calls and cap the number of steps per task.

From tool use to agents

Once a model can call tools reliably, wrapping the process in a loop with memory and limits gives you an agent. Read how to build AI agents and multi-agent systems next. In Program Zero, APIs and backend design come in Phase 4, agents and tool use in Phase 8, and AI security in Phase 11.