Glossary
Function calling
A way for a language model to request that your application run a named function with structured arguments, so it can fetch data or take actions instead of only writing text.
Function calling is a feature of large language model APIs that lets the model respond with a request to run a named function, with arguments in structured JSON, instead of only returning text. Your application runs the function and passes the result back, and the model uses it to continue. It is the mechanism behind most tool use, and the way an AI agent reads data and acts on other systems.
How function calling works
The model never runs code itself. It chooses a function and fills in its arguments, and your code does the rest. A typical exchange has five steps, repeated inside the agent loop until the task is done.
Step | What happens |
|---|---|
Define tools | The request includes each function’s name, a description and its parameters, written as JSON Schema |
Model chooses | The model returns a call naming the function and giving arguments that match the schema |
Application runs it | Your code validates the arguments and executes the function, such as an API request or database query |
Return the result | The output is added to the conversation as a tool result |
Model continues | The model writes its answer or requests another call |
Most APIs also let you control the choice: leave it to the model, force a particular function, or turn calling off. Many models can request several calls at once when the calls do not depend on each other, which cuts round trips. Descriptions matter more than they seem. The model picks functions from their names and descriptions, so vague ones lead to wrong calls or hallucination of arguments.
Function calling, structured output and MCP
Function calling is closely related to two other ideas. Structured output also returns JSON that matches a schema, but the JSON is the final answer, while a function call is a request for your code to do something. Constrained decoding is the technique many providers use to make either kind of output match its schema reliably. The entry on function calling vs structured output compares them.
The Model Context Protocol sits one level up. Function calling is how a single model API expresses a tool call. MCP is a standard way for applications to discover and connect to tools hosted by an MCP server, so the same tool can be reused across models and clients. Under the hood, an MCP tool still reaches the model through function calling. See MCP vs function calling for more.
Risks and good practice
Every function a model can call is an action that text in its context can trigger. Prompt injection, including instructions hidden in retrieved documents, can lead a model to call a function the user never asked for, and malicious tool descriptions can do the same through tool poisoning. Treat arguments as untrusted input: validate them, scope each function to the least it needs under least privilege, and require approval for actions that are hard to reverse.
Tool definitions also cost tokens on every request, because they travel in the prompt. A long list of verbose tools fills the context window before the conversation starts, so it pays to expose only the functions a task needs. Functions that change data should be idempotent where possible, since models sometimes repeat a call after an error.
Function calling with Exabase
Exabase is a set of APIs, so its operations map naturally onto functions an agent can call. A memory lookup can wrap memory search, which returns ranked memories for a natural-language query, or memories.ask, which returns a direct answer from Memory. A document lookup can wrap the resource search endpoint behind Deep Search, which returns matched passages with page numbers or timestamps. File processing can wrap Extract. Because each call can be scoped to a Base, a function can only reach the current user’s or tenant’s data, whatever arguments the model supplies.
The TypeScript SDK and REST API are described in the SDK overview, and an OpenAPI document is available from the API reference for generating tool definitions. Exabase Workers use the same pattern internally: each Worker calls built-in tools such as search-resources and create-notepad, and toolPermissions restricts which ones it may use, as listed in the worker tools guide.
The post on designing an API for agents, not humans covers how these choices were made. The customer support agents use case shows memory and search exposed as tools in a real architecture, and best AI agent frameworks compares the frameworks that manage the calling loop for you.
FAQs
What is function calling?
Function calling is an LLM API feature that lets the model request a named function with JSON arguments. Your application runs it and returns the result, which the model uses to continue.
Does the model run the function itself?
No. The model only produces the function name and arguments. Your code decides whether to run it, executes it and sends back the result.
Is function calling the same as tool use?
Mostly. Tool use is the broader idea of a model using external capabilities, and function calling is the API mechanism most providers use to implement it.
How is function calling different from MCP?
Function calling is how one model API expresses a call. MCP is a protocol for discovering and connecting to tools hosted elsewhere, which then reach the model through function calling.
Is function calling safe?
It is as safe as the functions you expose. Validate arguments, keep each function narrowly scoped, and require approval for irreversible actions, since injected text can trigger calls.
Can I use Exabase APIs as tools?
Yes. Memory search, resource search and extraction map directly onto functions, and scoping each call to a Base keeps every tool call inside one tenant’s data.
Related pages: Tool use, MCP, Structured output, MCP vs function calling, Agent loop, AI agent, Agentic AI, Agent memory solution, RAG accuracy solution, Best AI agent frameworks, ReAct agent, Agent SDK, Voice agents