# Functions

> A function runs fixed steps and returns one answer. Agents call functions as tools, for work with one right answer.

Builders work from a coding agent and operators from an AI client, both through the MCP server, or in the Studio. In Mindset, an agent is a prompt and a model, held to an order by a script when needed. It uses connections to outside systems, operations on them, functions and widgets. Every change is a version, and every execution is a run. Every piece sits on one security and compliance layer: the org sets its posture once, and every agent works under it, with the audit trail and, once an admin turns it on, personal data redaction. The platform runs in your own cloud (AWS, GCP or Azure) or is hosted by Mindset. Your app reaches agents through the SDK, your server through the API, and people through the Hub and schedules. Highlighted: Function.

A **function** runs a fixed list of steps, top to bottom, and returns one answer. An [agent](https://docs.mindset.ai/docs/agents) calls it as a tool. Use one for work with exactly one right answer, so no model works out the arithmetic.

## Why it matters

Work with one right answer costs less, and comes out the same every time, when no model has to work it out.

## Steps

Each step calls an [operation](https://docs.mindset.ai/docs/connections-and-operations), asks a model, works out a value or chooses between values. Every step runs. Steps can't be skipped, so a choosing step does the branching. A step that calls an operation or a model can repeat over up to 1,000 items.

**Live demo:** [Ask your data](https://docs.mindset.ai/demos/ask-your-data). Ask sales questions and a dashboard draws the answers from what the agent’s functions return.

## Who the session is for

A function reads the labels your backend set on the session as `attribution.<key>`, so it can choose by the customer's plan, region or account: `attribution.plan` is `enterprise` or it isn't. The model can't change a label, so a choice made on one holds whatever anyone types. A session without the label reads nothing there, so give that case its own answer. When the function calls an MCP server that gets labels, the call carries the session's labels too.

## Rules

- A function can't call another function.
- It can't be scheduled or triggered on its own. An agent calls it.
- Agents always use its published [version](https://docs.mindset.ai/docs/versions-and-going-live), so publishing a new one reaches every agent that holds it on its next call.
- Publishing is refused while its steps call an untested operation. See [the go-live gate](https://docs.mindset.ai/docs/versions-and-going-live#the-go-live-gate).
- It makes no judgment. Deciding whether a difference is acceptable belongs with the agent.

> **Info:** A function's model steps go through an AI model connection, which applies your org's personal data protection unless its **PII protection** switch is off. Its operation calls follow the same approval as an agent's. See [Compliance](https://docs.mindset.ai/docs/compliance).

## The invoice exceptions agent

`invoice-comparison` fetches the purchase order and lists every line where quantity or price differs. The agent decides whether each difference matters.

To build one, see [Add a function](https://docs.mindset.ai/docs/build-a-function).
