Generative AI & LLMs
Function Calling (Tool Use)
In shortFunction calling lets a language model ask your code to run a defined tool, such as an API or database query, and use the result in its answer.
Function calling, also called tool use or tool calling, is the ability of a large language model to ask for an external function to be run and then use the result. You describe the tools available (for example “get_search_volume” or “check_stock”), and when a request needs one, the model replies with the tool’s name and the arguments to pass. Your code runs the tool and sends the result back, and the model continues. It is what turns a chatbot into an AI agent that can act on live data.
How it works
- Define tools: each has a name, a description in plain language and a JSON Schema describing its parameters.
- Send the user request plus the tool definitions to the model.
- The model decides whether a tool is needed. If so, it returns a structured tool call such as get_search_volume(keyword=”trail running shoes”, country=”GB”) instead of a final answer.
- Your application executes the call (an API request, a database query, a calculation) and returns the output to the model.
- The model uses the output to answer, or calls further tools in a loop until the task is done.
The model never runs code itself; it only proposes calls. The Model Context Protocol (MCP) standardises how tools are exposed to models, and WebMCP proposes the same idea for actions on websites.
How it’s used in SEO and marketing
- Agent workflows that pull live data (Search Console, a SERP API, analytics) instead of relying on the model’s training data.
- Structured extraction: defining a “record_result” tool forces the model to return clean, schema-shaped output for classification or entity tasks.
- Content brief automation that calls keyword and SERP tools before drafting.
- Understanding AI search: MLforSEO’s Agentic SEO course lists tool use as one of the five properties of agents. An agent that needs today’s weather in Rome calls a weather API directly instead of reading a web page, which means some information needs are now served by APIs rather than by content.
Example
An analyst asks an assistant, “Which of our top 20 pages lost the most clicks last month?” The model calls a search_console_query tool with the date range, receives the rows, calls it again for the previous month, compares the two and answers with a ranked list, citing the numbers it received.
Limitations and things to watch
- Models can pick the wrong tool, pass wrong arguments or invent values; validate inputs before running anything.
- Tools that change things (publishing, deleting, spending) need confirmation steps and limited permissions.
- Every tool call adds latency and token cost, and tool output counts against the context window.
- Provider APIs and syntax differ and change; check current documentation.
Learn it on MLforSEO
- AI Search Optimisation and Agentic SEO, module on intelligent agents in SEO workflows
- Semantic ML-enabled Keyword Research, lab on automating content briefs
- 10 Ways to Automate SERP Analysis with AI
- Your audience is no longer only human
Where Function Calling (Tool Use) shows up on MLforSEO
Learn it in a course
Sources and further reading
Other terms from Generative AI & LLMs
- AI GovernanceThe policies, roles and controls an organisation uses to make sure AI is used safely, legally, transparently a…
- AI HallucinationWhen a generative AI model produces content that sounds plausible but is false, unsupported by its sources, or…
- Attention MechanismThe technique that lets a neural network weigh how much each word in a text matters to every other word, so it…
- ChatGPT (OpenAI GPT models)OpenAI's chatbot and its GPT model family: strong at summarising and rewriting, unreliable for structured anal…
- Confidence Score (Generative AI)A number, usually 0 to 1, showing how certain a model is about a label or prediction; low scores flag outputs…
- Context WindowThe maximum amount of text, measured in tokens, that a language model can consider at once, including the prom…
- DeepSeek (R1 and V-series)DeepSeek's open-weight reasoning LLM, released January 2025. MLforSEO benchmarked it for entity extraction: ge…
- Gemini (Google)Google's family of multimodal large language models, behind the Gemini app, the Gemini API and AI features in…
- Generative AIAI models that create new content (text, images, audio, code) by predicting likely outputs from patterns learn…
