AI Skills Wiki 中文

Tool Calling for AI Agents: Letting LLMs Use Functions and APIs

AI Skills Wiki › AI Engineering · Last updated: 2026-08-12

Definition

Tool calling, also called function calling, is a structured interface between a language model and external software. Instead of only emitting free-form text, the model selects a declared tool, fills a schema-validated argument object, and lets the host application execute the corresponding function, API call, database query, browser action, or workflow step. The application then returns the result to the model so it can continue reasoning or produce a final answer. Modern agent platforms use tool calling as the control plane for retrieval, code execution, SaaS automation, and multi-step task completion.

Why it matters for AI jobs

AI job descriptions mention tool calling because production LLM systems must do more than chat. Employers need engineers who can design safe tool schemas, route model requests to reliable services, validate arguments, handle retries and partial failures, log tool traces, and prevent prompt injection from turning a helpful integration into an unsafe action channel. Tool calling also connects directly to agent orchestration, Model Context Protocol servers, evaluation harnesses, and product integrations, making it a practical bridge between backend engineering and applied AI.

Key concepts

  • Tool schema: a JSON-schema-like contract describing the tool name, purpose, parameters, required fields, and return shape.
  • Argument validation: checking model-proposed inputs before execution to reject malformed, unsafe, or out-of-policy calls.
  • Execution loop: the host application sends tool results back to the model, allowing multi-step plans instead of one-shot responses.
  • Tool choice and routing: deciding whether the model may call any tool, a specific tool, or no tool for a given request.
  • Observability and evals: tracing calls, measuring success rates, latency, cost, and whether the selected tool actually solved the task.
  • Security boundaries: permission checks, sandboxing, allowlists, user confirmation, and prompt-injection defenses around side-effectful actions.

Learning path

  1. Start by wrapping three local Python functions as typed tools, such as weather lookup, calculator, and document search, then inspect the raw model tool-call JSON.
  2. Add strict JSON schema validation, clear error messages, timeout handling, and retry logic so bad arguments do not crash the agent loop.
  3. Connect one real API or database, implement least-privilege credentials, and log every call with inputs, outputs, latency, and user-visible effects.
  4. Build evaluation cases that test correct tool selection, argument accuracy, refusal of unsafe actions, and recovery from unavailable tools.
  5. Study MCP or an agent SDK to expose tools across processes, then compare when to use built-in tools, custom functions, and remote tool servers.

Resources