# Scripts

> A script holds an agent to an order of phases, each with a gate it must pass. Most agents don't need one.

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: Script.

A **script** splits an [agent's](https://docs.mindset.ai/docs/agents) work into [phases](https://docs.mindset.ai/docs/glossary). It belongs to the agent and is saved in the agent's [version](https://docs.mindset.ai/docs/versions-and-going-live), with no publish step of its own.

Add one only for an instruction the agent must not be able to skip: wait for a person's answer, don't move on until something is true, or don't reach a tool before an earlier step is done. A prompt can't make an agent wait.

## Why it matters

Mindset checks each gate after every turn, so the order holds whatever the model decides, and a write held for a later phase can't run early.

## Phases and gates

Each phase has its own instructions and resources, the values it must collect, and a **gate**: the condition that moves the run on. A gate either checks the collected values or asks a model, which passes only a clear yes. A phase that lists its resources offers only those.

> **Warning:** Phases only go forward. Mindset refuses to save a route back to an earlier phase; to branch, skip ahead.

Put a phase boundary only where the conversation must wait. "Collect the supplier, the invoice number and the amount" is one phase. "Confirm the total before you continue" is a boundary.

A script can't repeat an action for every item in a list. Use a [function](https://docs.mindset.ai/docs/functions) for that.

## Who the session is for

A gate, a step or a phase's instructions can read the labels your backend set on the session, as `attribution.<key>`. A gate on `attribution.plan` routes an enterprise customer one way and everyone else another, and the model can't change a label, so the route holds whatever anyone types. A session without the label reads nothing there, so give that case a route of its own.

## Asking a person

A phase can stop to put a decision to a person. The [run](https://docs.mindset.ai/docs/runs) parks, spending nothing, until someone answers or the wait the author set runs out, then carries on with the answer. It's the only way to put a person's yes or no in front of one particular action.

**Live demo:** [Guided intake](https://docs.mindset.ai/demos/guided-intake). A home insurance claim runs through fixed phases, moving on only when each gate passes.

## The invoice exceptions agent

Its script has four phases: Gather, Assess, Prepare and Close. Only Prepare holds the `register_supplier_query` write, so the agent can't register a query before the comparison and the contract check.

To write one, see [Make it follow steps](https://docs.mindset.ai/docs/write-a-script).
