AI ENGINEERING | LIVING GLOSSARY | #013
TOOL CALLING
Connecting AI Models to External Capabilities
Chapter 3: Connecting AI to Tools, Workflows, and Agents
AIYING — Accomplishing with AI
A customer asks an AI assistant:
A language model may explain how order tracking normally works. But it cannot know the current status of this particular order unless the relevant information is available to it.
What if the AI application could securely query the company's order management system?
Instead of guessing, the model could request a tool operation, receive the result, and explain the actual status.
This capability is called tool calling, often also called function calling.
1. What Is Tool Calling?
Tool calling is a mechanism through which an AI model produces a structured request to use a capability made available by its host application.
Tools may provide access to:
- Application functions
- External APIs
- Databases and search systems
- Calculators and computation services
- Enterprise applications
- File-processing utilities
- Business workflow operations
The model typically selects a tool and generates arguments according to a declared interface or schema.
The application then determines whether and how to execute the request.
Crucially, the model does not necessarily execute the tool itself. It proposes a call that an application or runtime may execute after appropriate checks.
↑ Back to contents2. Why Tool Calling Matters
Language models are powerful at interpreting requests and generating responses, but many useful tasks require access to external information or systems.
| Without tool calling | With tool calling |
|---|---|
| AI explains how to check an order. | AI can request the current order status. |
| AI describes how to calculate a tax. | AI can invoke a calculation service. |
| AI drafts a support ticket. | AI can request ticket creation through an authorized API. |
| AI suggests a calendar event. | AI can propose creating an event through a calendar integration. |
| AI explains inventory management. | AI can query an authorized inventory system. |
Tool calling helps bridge the gap between generating useful language and interacting with operational systems.
However, connecting tools also introduces security, authorization, data quality, and reliability challenges.
↑ Back to contents3. How Tool Calling Works
User Request
|
v
AI Model Receives Tool Definitions
|
v
Model Selects Tool and Arguments
|
v
Application Validates Request
|
v
Authorization and Policy Checks
|
v
Tool Executes
|
v
Application Receives Tool Result
|
v
Model Interprets Result
|
v
Response to User
This is a common pattern, not a universal implementation. Some systems use multiple tool calls, parallel operations, or additional approval checkpoints.
The tool response becomes additional information that the model can use to produce a final answer.
Engineers must distinguish three stages:
- Selection: Which tool does the model request?
- Execution: What does the authorized application actually do?
- Interpretation: How does the model use the returned information?
Each stage can fail independently and should be tested.
↑ Back to contents4. Core Components of Tool Calling
A. Tool definition
Describes a capability available to the model, including its purpose and required parameters.
B. Tool schema
Defines the expected structure and data types of tool arguments.
C. Tool selection
The model determines whether a tool is relevant to the request.
D. Argument generation
The model generates structured arguments, often represented as JSON.
E. Validation
The application checks argument structure, permitted values, and applicable business requirements.
F. Authorization
The application verifies that the requesting user and executing service are permitted to perform the operation.
G. Execution
The application invokes the underlying function or external service.
H. Result handling
The application receives the result and makes appropriate information available to the model.
I. Error handling
Failures, timeouts, invalid responses, and unavailable services are handled explicitly.
J. Observability
Logs and traces capture relevant operations and outcomes without exposing unnecessary sensitive information.
↑ Back to contents5. A Practical Tool Call
Consider a fictional tool named get_order_status.
Tool interface
{
"name": "get_order_status",
"description": "Retrieve an authorized order status",
"parameters": {
"type": "object",
"properties": {
"order_id": {
"type": "string"
}
},
"required": ["order_id"]
}
}
Model-generated request
{
"name": "get_order_status",
"arguments": {
"order_id": "ORD-1042"
}
}
The application validates the request and verifies that the authenticated customer is permitted to access this order.
Illustrative tool result
{
"order_id": "ORD-1042",
"status": "Shipped",
"carrier": "Example Logistics",
"estimated_delivery": "2026-11-15"
}
Assistant response
This example uses fictional data and a simplified provider-neutral representation of tool calling.
The important point is that the answer is based on the authorized tool result rather than an invented delivery status.
↑ Back to contents6. Tool Calling vs RAG and AI Agents
| Concept | Primary purpose |
|---|---|
| Tool Calling | Request use of an external capability through a defined interface. |
| RAG | Retrieve relevant information to support generation. |
| Workflow | Coordinate a sequence of operations according to a defined process. |
| AI Agent | Pursue goals through model-guided decisions and, often, tool use. |
These concepts overlap.
A RAG system may use a retrieval tool. An AI agent may call several tools. A workflow may orchestrate model calls, tools, and deterministic operations.
Tool calling alone does not make an application an autonomous AI agent.
↑ Back to contents7. Security and Reliability
Tool calling can turn model-generated text into requests with real operational consequences.
That makes independent controls essential.
Least-privilege permissions
Expose only capabilities necessary for the application's intended purpose.
Server-side authorization
Check the authenticated user's permissions before accessing data or executing actions.
Argument validation
Validate types, formats, ranges, and business constraints independently of the model.
Untrusted tool outputs
Treat retrieved text and tool responses as data, not authoritative instructions.
Approval for consequential actions
Require human confirmation where appropriate for payments, deletions, deployments, or other sensitive operations.
Timeouts and retries
Handle unavailable services without creating uncontrolled retry loops.
Idempotency
Protect applicable operations against unintended duplication, especially when retries occur.
Result verification
Distinguish a requested action from an action that was actually completed successfully.
8. Industry Applications
| Industry application | Example tool capability |
|---|---|
| Customer support | Retrieve order status or create a ticket. |
| Banking | Retrieve permitted account information. |
| Human resources | Query authorized leave balances. |
| Software engineering | Run tests or inspect repository metadata. |
| Supply chain | Query inventory and shipment records. |
| Business analytics | Execute controlled data queries. |
| Enterprise operations | Interact with approved workflow APIs. |
The tool integration must respect the security, privacy, and operational requirements of the particular industry.
↑ Back to contents9. What Must an AI Engineer Decide?
- Which external capabilities should be exposed to the model?
- How should each tool be described?
- What argument schema is appropriate?
- When should tool use be mandatory, optional, or prohibited?
- How will user identity and authorization be verified?
- Which operations require human approval?
- How will invalid tool arguments be handled?
- What happens when a service is unavailable?
- How will retries avoid duplicate actions?
- How will tool responses be validated?
- How will failures be logged and investigated?
- How will tool-selection accuracy and task success be evaluated?
These are engineering design decisions, not merely prompt-writing choices.
↑ Back to contents10. Practical Industry Case: The Order That AI Could Actually Track
A retail company deploys an AI customer support assistant.
A customer asks about order ORD-1042.
The assistant has access to a read-only order status tool.
Engineering approach
- Identify the customer's request.
- Select the appropriate order status tool.
- Extract the order identifier.
- Validate the identifier format.
- Verify the authenticated customer's access to the order.
- Call the authorized order management API.
- Validate the returned data.
- Handle missing orders or service errors.
- Generate an answer based on the actual tool result.
- Avoid inventing unavailable information.
- Record operational telemetry.
- Evaluate accuracy, latency, and error handling.
What if the tool fails?
The assistant should not invent a shipment status. It should explain that the current information could not be retrieved and offer an appropriate next step.
What if the customer requests cancellation?
Cancellation is a different capability with different authorization and business requirements. A read-only tracking tool should not be able to cancel an order.
Industry insight: Tool calling is valuable because it connects AI to real information and actions. Its reliability depends on the surrounding engineering controls.
↑ Back to contents11. Try It Yourself
Mini Project: Design an AI Order Tracking Assistant
Objective: Design and simulate a tool-calling workflow without connecting to a real customer database.
- Create a fictional dataset containing five orders.
- Define a tool named
get_order_status. - Specify its purpose and input schema.
- Prepare ten customer questions.
- Include valid, invalid, and unauthorized order requests.
- Ask an AI model to identify the appropriate tool and arguments.
- Validate the generated arguments.
- Simulate an authorization check.
- Return fictional order data for permitted requests.
- Generate customer-facing responses.
- Simulate a tool timeout and an unknown order.
- Verify that the model does not invent missing results.
- Record tool selection, validation, and response outcomes.
- Revise the tool description and repeat the experiment.
Suggested evaluation measures
| Measure | Question |
|---|---|
| Tool selection accuracy | Was the correct tool selected? |
| Argument validity | Were required arguments correctly structured? |
| Authorization enforcement | Were unauthorized requests blocked? |
| Result fidelity | Did the response accurately reflect tool data? |
| Error handling | Were failures communicated appropriately? |
| Task success | Was the legitimate customer need satisfied? |
Reflection questions
- Why is a tool call different from an ordinary model response?
- Who is responsible for executing the tool?
- Why must arguments be validated?
- What happens if the model selects the wrong tool?
- How should authorization be enforced?
- What makes a tool-calling system production-ready?
Success criterion: Produce a working simulation or documented design showing tool definitions, request validation, authorization, execution, response handling, and evaluation.
12. Connected Glossary Terms
- Token: Tool definitions and returned data contribute to context usage.
- Prompt Engineering: Instructions help guide appropriate tool selection.
- RAG: Retrieval can be exposed through tools.
- Context Window: Large tool results may consume context capacity.
- Evals: Test tool selection, argument correctness, and task success.
- Hallucination: Tool results can reduce reliance on unsupported guesses.
- Grounding: Retrieved tool data can provide evidence for answers.
- Guardrails: Enforce tool permissions and execution restrictions.
- Observability: Trace tool calls, failures, and latency.
- Human-in-the-Loop: Require approval before designated actions.
Previous lesson: #012 — Human-in-the-Loop
Next lesson: #014 — Workflows: Orchestrating Multi-Step AI Processes.
↑ Back to contents13. Living Update
Editorial baseline: November 2026
Tool calling is an important foundation for modern AI applications and agents.
Areas to monitor include:
- Structured tool interfaces and schemas.
- Standardized tool discovery and integration protocols.
- Model Context Protocol (MCP) adoption and security.
- Tool selection and argument generation evaluations.
- Agent tool permissions and authorization.
- Parallel and multi-step tool execution.
- Approval checkpoints for consequential operations.
- Tracing and auditing of tool interactions.
Living Glossary note: Update this entry as tool integration standards, model capabilities, and enterprise security practices evolve.
↑ Back to contents14. Key Takeaway
Reliable tool calling requires more than a model that can generate function arguments. It requires secure interfaces, permissions, validation, error handling, and verification.
Think like an AI engineer: When an AI model proposes an action, what ensures that the right tool executes correctly, safely, and only with appropriate authorization?
↑ Back to contents15. References and Further Reading
- OpenAI — Function Calling Guide
- Model Context Protocol — Documentation
- Anthropic — Developer Documentation
- OWASP — Generative AI Security Project
- NIST — AI Risk Management Framework


No comments:
Post a Comment