# Function calling

Function calling is how a large language model asks an application to run a specific function. The model returns the function's name and arguments as structured data, the application executes it, and the result goes back to the model to shape its next step.

## How does function calling work?

Function calling turns a model's output from prose into an instruction your code can run. The model never executes anything itself. Your application does, and it decides whether to.

A typical round trip has five steps:

1. **Describe the functions.** You send the model a list of functions, each with a name, a plain-language description and a JSON Schema for its parameters.
2. **The model chooses.** Given the user's message, it either answers directly or returns a call: the function name plus arguments that match the schema.
3. **Your code checks and runs it.** The application validates the arguments, confirms the user is allowed to do this, and calls the real API.
4. **The result goes back.** The function's output is added to the conversation as a tool result.
5. **The model continues.** It answers the user, asks a follow-up question, or calls another function.

Steps 2 to 5 can repeat. That loop is what lets an agent finish a task that takes several calls.

## What is tool calling?

Tool calling is the same mechanism under a broader name. "Function calling" was the original term in early model APIs. Most providers now say "tools", because a tool can be a function you host, a built-in capability such as web search, or a tool exposed by a server over a standard protocol.

Whether the docs say tool use, tool calling or function calling, they describe one round trip: the model proposes a structured call, and something outside the model runs it.

## What does function calling look like in a CRM?

Take a CRM user who types: "Move every deal that hasn't changed in 30 days to the Review stage."

The CRM exposes two functions, `search_deals(filters)` and `update_deal_stage(deal_id, stage)`. The model calls `search_deals` with a filter on last activity. The CRM returns eight deals. The model calls `update_deal_stage` for each one, then replies with a short list of what moved.

Three details decide whether this works in practice:

- **Descriptions do the routing.** The model picks a function from its name and description. Vague descriptions cause missed or wrong calls, so say what the function does and what it returns.
- **Schemas constrain the arguments.** Enums, required fields and formats cut malformed calls. Many APIs offer a strict mode that forces output to match the schema.
- **Permissions belong in your code.** The function should run with the signed-in user's rights, so a request the user couldn't make in the UI fails here too. Destructive calls deserve a confirmation step.

## How do product actions use function calling?

Function calling is how an in-product agent moves from explaining a feature to doing the work. Each product action (create a project, invite a teammate, change a plan) becomes a function with a clear description and schema, and the agent chains them to finish what the user asked for.

Foldspace's Product Agent works this way: every action a team publishes becomes a call it can make [to the product's own backend APIs](https://docs.foldspace.ai/start/faq/), run with the signed-in user's permissions, and when it needs input it can render agentic UI such as a form or picker in the conversation.

## Learn more

- [Product Agent](/platform/product-agent)
