Your AI assistant knows how to answer questions. But when someone asks 'What's the weather in Tokyo?', it can only guess. It has no eyes, no internet connection, no way to check.
Unless you give it tools. Now it can call a weather API, get real data, and respond with facts instead of fabrications.
That's the difference between a chatbot that hallucinates and an agent that acts.
Tool calling transforms language models from oracles that guess into agents that act. The AI decides what to do. The tools do the doing.
AGENTIC AI PRIMITIVE - Enables language models to invoke external functions, APIs, and services based on natural language intent. The bridge between understanding and action.
Tool calling (also called function calling) lets a language model request the execution of external functions. You define tools - their names, descriptions, and parameters - and the model decides when to use them based on the user's request. It doesn't execute anything itself. It outputs a structured request: 'Call the get_weather function with location=Tokyo.'
Your code receives this request, executes the actual function, and returns the result to the model. The model then incorporates that real data into its response. The human asks a question, the AI decides what tool to use, your system executes it, and the AI explains the result.
This is the foundation of AI agents. Without tool calling, AI can only process information. With it, AI can query databases, send emails, update records, book meetings - anything you can wrap in a function.
Tool calling solves a universal problem: how do you let an AI make decisions about what actions to take while keeping humans or code in control of execution?
Define tools with clear names, descriptions, and typed parameters. Send user requests to the model with available tools. Parse the model's tool call response. Execute the function in your code. Return the result to the model for final response.
Select a scenario and click Play to see the full tool calling flow: user request → AI decision → tool execution → final response.
Get current weather for a location
Check product availability
Send an email to a recipient
One request, one action
The simplest pattern. User asks a question, model calls one tool, you execute it, model responds with the result. 'What's the weather in Tokyo?' → get_weather(location='Tokyo') → 'It's 22°C and sunny.'
Multiple actions at once
When the model needs multiple pieces of information, it can request several tool calls simultaneously. 'Compare weather in Tokyo and New York' → [get_weather('Tokyo'), get_weather('New York')] → Combined response.
Actions that depend on previous results
Some tasks require chains of tool calls where each step depends on the previous. 'Book a flight to the cheapest destination' → search_destinations() → get_flight_prices(destination) → book_flight(flight_id).
A customer asks your AI assistant about product availability. The AI decides it needs to check inventory, calls the appropriate tool, gets real data, then calls another tool to reserve the item. all in a natural conversation.
Hover over any component to see what it does and why it's neededTap any component to see what it does and why it's needed
Animated lines show direct connections · Hover for detailsTap for details · Click to learn more
You give the AI a 'delete_user' tool and someone asks 'Delete all inactive users.' The model happily generates that call. You execute it. 10,000 users gone. The AI did exactly what it was told.
Instead: Require confirmation for destructive actions. Add rate limits. Validate parameters. Never execute high-risk operations without human approval in the loop.
You name a tool 'process_data' with description 'Processes data.' The model has no idea when to use it. It either calls it for everything or nothing. You get confused behavior and wasted API calls.
Instead: Write descriptions like documentation: what it does, when to use it, what parameters mean, what it returns. The model only knows what you tell it.
The model calls your 'get_stock_price' tool. The API is down. Your code throws an exception. The model gets nothing back. The conversation dies or the AI hallucinates an answer.
Instead: Always return a result to the model, even on failure. Return structured errors: {"error": "API unavailable", "retry_in": "5 minutes"}. Let the model explain the failure gracefully.
You've learned how AI decides when to use tools and how to execute them safely. The natural next step is understanding prompt architecture - how to structure the instructions that guide AI behavior.