# Use with AI agents

Coding agents such as Claude Code, Cursor or Codex can write a station, run it with `npx factory`, read the error, fix it and run it again. That's the same loop you'd follow by hand, and it stays on your machine.

## 1. Set up the repo yourself

Create the factory repo and fill in `.env` ([Quickstart](/docs/quickstart)) before you hand it to an agent, so the agent never needs your API key. If it needs credentials, it should ask you; it should never invent them.

Local runs are real: `npx factory stations run` really runs your station, so if the station calls an API or writes to a system, that happens. Point `.env` at test accounts while an agent is iterating, and keep your agent's approval prompts on.

## 2. Paste this into the agent's instructions

Add it to the repo's `CLAUDE.md` or `AGENTS.md` (the template's `CLAUDE.md` already describes the layout and `defineStation()`):

```markdown
## Assembly Line: running and debugging stations

- A station's code is `src/stations/<CODE>__<name>/station.js` (`defineStation()`); its config is in its station file, `.orchestrator/stations/<CODE>__<name>.json`.
- List stations: `npx factory stations list`. Run one: `npx factory stations run <CODE>` (`--empty` for no config); `--set key=value` changes one config key for that run. Output lands in `temp/<CODE>.json`.
- On failure, read the `Config` line and the error, fix the station and run it again.
- Workpieces: `al-control lines status <LINE> -f .`, `al-control workpieces show <id> -f .`, and `error.txt` in the failed bin.
- Ask me before: `al-orc lines push`, `al-orc stations push`, `al-orc stations run`, `al-control workpieces clear`, `al-control workpieces requeue`.
- Docs (raw Markdown): https://assemblyline.sh/llms.txt
```

## 3. Commands to confirm first

| Command | Why |
| --- | --- |
| `al-orc lines push`, `al-orc stations push` | Changes the line and station definitions on the Orchestrator |
| `al-orc stations run <CODE>` | Starts a real run in your factory |
| `al-control workpieces clear`, `al-control workpieces requeue` | Deletes finished workpieces, or sends failed ones through again (both dry runs unless `--yes`) |
| `npx factory stations run` | Runs your station for real, including any API calls it makes |

## 4. Example asks

- "Make IN1 attach a markdown report of the flagged invoices, and run it." The agent adds a `report.md` template next to `station.js`, renders and attaches it, and runs `npx factory stations run IN1`.
- "IN1 fails with `approval_limit` set to 0. Find out why and fix it." The agent reruns it with `--set approval_limit=0`, reads the error and edits the station.
- "INV-1002 is stuck in IN1/failed. Tell me what happened." The agent runs `al-control workpieces show INV-1002 -f .` and reads `error.txt`.

## Docs for agents

- Index of every page on this site: [`/llms.txt`](/llms.txt)
- Any page as raw Markdown: add `/md` after `/docs`. This page is at [`/docs/md/ai-agents`](/docs/md/ai-agents).
- Tool reference: the READMEs of [lib-factory](https://github.com/assemblyline-sh/lib-factory), [al-orc](https://github.com/assemblyline-sh/al-orc) and [al-control](https://github.com/assemblyline-sh/al-control).
