Tool calling bridges LLM reasoning and real-world actions. Use it to extend models with controlled capabilities such as retrieving up-to-date data, performing calculations, or executing side-effecting tasks.
Why tool calling matters
Tool calling transforms text-only models into systems that can:- Query remote data sources (databases, vector stores).
- Retrieve live information (web search, news feeds).
- Integrate with third-party APIs (payment, booking, analytics).
- Execute code or scripts to perform computations or modify state.
Building a basic tool-calling application (high level)
A minimal tool-enabled app typically follows these steps:- Define the available tools
- Each tool is an interface the model can call (e.g.,
searchWeb(query),queryDB(sql),runScript(payload)).
- Each tool is an interface the model can call (e.g.,
- Provide tool descriptions to the model
- Describe inputs, outputs, and when to use each tool.
- Let the model decide between generating text and calling a tool
- The model outputs a tool invocation or plain text.
- Execute the tool and return results to the model
- The tool runs in your environment; results are fed back into the model for further reasoning.
- Repeat as needed until the task is complete
Always validate and sanitize inputs and outputs when executing tools. Tool calls can have side effects (database writes, payments, etc.), so use authentication, input filtering, and audit logs.
Typical architecture patterns
- Model + Tool Executor: The model decides which tool to call; a secure executor runs the tool and returns results.
- Orchestrator Workflow: Deterministic pipelines call the model at specific steps for generation, validation, or transformation.
- Autonomous Agent: A loop where the model plans, acts (calls tools), observes results, and replans until a goal is reached.
Workflows vs Agents — at a glance
When to choose which approach
- Choose deterministic workflows when you need predictability, auditability, and clear failure modes.
- Choose agents when tasks are open-ended and benefit from the model’s planning and iterative decision-making.
- Hybrid approaches work well: use deterministic workflows for critical steps and agents for exploratory subtasks.
Practical tips
- Start small: give the model a focused set of tools and expand as you validate behavior.
- Use detailed tool descriptions and example invocations.
- Instrument every tool call (timestamps, user, inputs, outputs) for debugging and safety.
- Provide safety gates for destructive actions (manual approval, simulated dry-runs).
What you’ll learn in this lesson
- How tool calling extends LLM capabilities (search, database queries, API calls, code execution).
- How to implement a basic tool-calling application.
- The distinction between deterministic workflows and autonomous agents.
- Guidelines to choose the right architecture for your use case.
Links and references
- OpenAI: Tool Use Guide
- Designing Reliable LLM Systems — Best Practices (conceptual guide)