Tool calling gives LLMs superpowers: calculators, web search, and APIs. Without it, language models are limited to their training data.: they cannot do precise arithmetic, they cannot access real-time information, and they cannot interact with external systems. Tool calling – also called function calling – bridges this gap by letting the model invoke external tools.
How Tool Calling Works
The model is given a list of available tools (functions) with their schemas. When it determines that a tool would help answer the user’s query, it outputs a structured JSON object specifying the tool name and arguments, rather than continuing to generate natural language. The host application executes the tool and feeds the result back to the model for the final response.
Tool Calling: Example Tools
Common tools include: a calculator for precise arithmetic (the model outputs calculate(3.14 * 7^2) and gets back 153.86); a web search engine for current information; a database query tool for structured data; and API wrappers for services like weather, email, or calendar. This paradigm was popularized by OpenAI’s function calling feature in GPT-4, and is now supported by most major LLM providers.
Run tools.py to see a calculator tool in action. The model recognizes when a user asks a math question, calls the calculator function, receives the result, and incorporates it into a natural language answer.
Tool Calling and Agentic Loops
Tool calling enables agentic behavior: the model can reason, take action, observe the result, and take further action. This loop – thought, action, observation – is the foundation of LLM agents. Frameworks like LangGraph and AutoGen orchestrate these multi-step reasoning processes.
This concludes our LLM series. You have gone from building a bigram model that could barely generate two-word phrases to understanding the full stack of modern AI systems – tokenization, embeddings, attention, transformers, training, generation, and deployment with RAG and tool calling. that could barely generate two-word phrases to understanding the full stack of modern AI systems – tokenization, embeddings, attention, transformers, training, generation, and deployment with RAG and tool calling.
Tool Calling: Parallel and Sequential
In practice, complex tasks often require multiple tool calls. A model might need to search the web for current data, then calculate statistics on the results, and finally format them into a table. Modern APIs support parallel tool calls – the model can request multiple tools in a single response, and the results are returned together. Sequential tool calls, where the output of one tool becomes the input for another, enable multi-step reasoning: the model can write and execute Python code, inspect compile errors, and iteratively fix them.
Tool Calling Safety and Validation
Of course, granting an LLM access to tools creates security considerations. Input validation ensures tool arguments are safe (e.g., a calculator tool should only accept mathematical expressions, not shell commands). Rate limiting prevents runaway loops where the model repeatedly calls expensive tools. Permission boundaries restrict which tools are available in which contexts – for example, a read-only database query tool vs. a write-capable one. The Anthropic research on tool use provides detailed guidance on building safe tool-calling systems.

Leave a Reply