> A bot acts when a story enters a stage: it writes a new version, and the engine moves the story on. Built; running on Distinctive Mark's ruling pipeline. Human review is never a stage.

Canonical: https://p.apyr.us/stage-bots.html

# Stage Bots

Stage Bots are automations that fire when a story moves into a stage. The automation runs a bot procedure, written in Tactus, which writes a new version of the story. Then the engine, not the procedure, moves the story to the next stage. The next stage's bots fire in turn, so a chain of stages becomes a chain of bots.

This is built and tested. [Distinctive Mark](https://distinctive-mark.com), our open-code demonstration site about trademark law, runs one: a TTAB ruling is analysed into a draft, fact-checked against the opinion, copy-edited with the site's [Editorial Checks](/editorial-checks.html), and then reaches typesetting, where no bot waits and an editor publishes. In our runs so far it costs about a cent and a half per ruling.

## The rules that keep it safe

- **One run per story, stage and version.** Delivering the same stage twice starts nothing twice.
- **A hop limit.** After five bot runs on a story (or the limit on the automation) nothing more starts and a hard-gate [Review Request](/review-requests.html) says so.
- **Bots never publish.** A bot saves a version. It cannot move the story and cannot publish; the engine moves it, and an editor publishes.
- **Bot actions are labelled.** The version a bot wrote says so, and the story's trail records each move, who made it and why.
- **A bot can stop the chain.** A bot that cannot do its job, for example a fact-checker that could not read the opinion, returns a hold with a reason. The story stays where it is and a flag asks a person to look.
- **Human review is not a stage.** Wherever a person is wanted, the engine raises a Review Request.

## Set it up

```
papyrus automations create --id distinctive.ruling.fact-check --title "Fact-check a ruling story" \
  --on-stage reporting --next-stage copywriting --monitor ttab --publication distinctive \
  --procedure distinctive.ruling.fact-check --max-hops 5
```

The procedures are in the open: [fact-check](https://github.com/AnthusAI/Distinctive-web/blob/main/procedures/ruling_fact_check.tac) and [copy-edit](https://github.com/AnthusAI/Distinctive-web/blob/main/procedures/ruling_copy_edit.tac). Not built yet: a per-story cost cap, and firing from a move on the console board (the command line fires them). See the [cookbook recipe](/cookbook/decisions-tracker/).
