# Make it follow steps

> Gives an agent ordered phases for the part of its work that must wait or happen in order, including waiting for a person's answer.

**Skill for your coding agent:** [`mindset-script/SKILL.md`](https://docs.mindset.ai/skills/mindset-script/SKILL.md)

**Skill for your coding agent:** [`mindset-human-in-the-loop/SKILL.md`](https://docs.mindset.ai/skills/mindset-human-in-the-loop/SKILL.md)

Building an agent goes in order: build the agent, connect your systems, add functions, scripts and widgets, test it, take it live, then put it in your product. Highlighted: Add functions, scripts and widgets.

## Ask your coding agent

```
Add a script to the invoice exceptions agent. Gather the invoice, its purchase order and the comparison first. Check the supplier contract only when they differ, and allow the supplier query write only in the last phase. Keep a test case for an invoice that matches and one that doesn't.
```

Skill: [mindset-script](https://docs.mindset.ai/skills/mindset-script/SKILL.md)

## What gets built

A [script](https://docs.mindset.ai/docs/scripts): ordered phases, each with what it must collect, the resources it can use, and a gate that decides when it moves on. It's saved with the agent as a new version. Most agents need none, so a script covers only the stretch that must wait or happen in order, and the rest stays in the prompt.

| Phase          | It must collect                                                      | It can use                                                   | How it advances                                                     |
| -------------- | -------------------------------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------- |
| **1. Gather**  | The invoice, its purchase order and their comparison                 | The finance system reads and the invoice comparison function | **A check**: all three are collected. No differences skips to Close |
| **2. Assess**  | Whether the contract allows the difference, and which clause says so | The supplier contracts knowledge base                        | **A judgment**: the answer names a specific clause                  |
| **3. Prepare** | A registered supplier query                                          | `register_supplier_query`                                    | **A check**: the query is registered                                |
| **4. Close**   | Nothing                                                              | Nothing                                                      | Ends here                                                           |

## What you decide

- **The phases, as outcomes.** "We know whether the contract allows this difference" rather than "search the contracts".
- **A check or a judgment for each gate.** A check tests what was collected: it's instant, costs nothing, and the agent can't argue past it. A judgment asks a model, and only a clear yes passes. Use a check wherever the answer is yes or no.
- **What each phase can use.** A phase that lists resources, even an empty list, gets only those. One that lists none at all gets everything the agent has, unless it collects values, when it gets only the tool that records them. To make sure the agent calls a function, list only that function on the phase and make the gate depend on what it returns.
- **Where to branch.** Phases only go forward. To branch, route to a later phase.
- **Whether a route depends on who the session is for.** A gate can read the label your backend set, such as `attribution.plan`. Don't ask the person for it: the answer couldn't change the route. Keep a test case for each label value, with `attribution` set, and one with no labels.

## Wait for a person

```
Before the invoice exceptions agent registers a supplier query, ask the finance manager to approve it in Slack. If nobody answers within two days, close the run without registering anything.
```

Skill: [mindset-script](https://docs.mindset.ai/skills/mindset-script/SKILL.md)

A run can park until a person answers in Slack, then carry on with the answer. An `$ask` step posts one Slack message with up to 10 buttons, records each click with who made it and when, and parks the run until the gate passes. It needs a Slack connection whose message operation accepts buttons. See [Post to Slack or send email](https://docs.mindset.ai/docs/post-to-slack-or-send-email).

Give every wait a time limit and the later phase to move to when it runs out, because nobody answering is the normal case. An `$ask` step without one waits indefinitely, and its shortest limit is 5 minutes.

> **Info:** An operation's approval, one of your org's [compliance rules](https://docs.mindset.ai/docs/compliance), is given once for the whole operation. A wait like this is the only way to put a person's yes in front of each call.

## Done when

- Its test parameters ran, one set per path, and the script reads as verified.
- The agent version is active. Activation is refused while the script calls an operation that hasn't been tested. See [Versions, testing and going live](https://docs.mindset.ai/docs/versions-and-going-live).
- You watched a run on the **Chat** tab and saw where each phase advanced.

## See it working

**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.

## In your repo

The script is `script.json` in the agent's folder. A script belongs to one agent, and a change to it goes live only when a new version of the agent binds it. See [Keep your agents in your code](https://docs.mindset.ai/docs/keep-your-agents-in-your-code).

## In the Studio

On the agent's **Script** tab, press **Create script** and tell the Agent Builder what you want. **Diagram** and **Document** show the phases, what each can use and how it advances. Run the test parameters listed there, press **Save as version**, and activate it on **Versions & Availability**. **Detach script** takes the script off the agent in the next version, and keeps every version of it.

![The Script tab, showing the first phase of a script as a diagram.](https://docs.mindset.ai/images/docs/studio/agent-script.png)
