Automations
Automations are business rules that run when something happens in Tradehall, such as a client being added or an invoice being paid. Each one is a short JavaScript function. Owners who don’t write code describe the rule in plain words instead, and an agent drafts it for a person to approve.
Writing one
Section titled “Writing one”A script exports one function. It receives the event and a tradehall object:
export default async function (event, tradehall) { await tradehall.http.fetch('https://us21.api.mailchimp.com/3.0/lists/abc/members', { method: 'POST', secret: 'mailchimp_key', json: { email_address: event.client.email, tags: ['new-client'] }, });}What a script can do:
tradehall.tools.call(name, arguments)calls the same tools agents and MCP clients use, such as creating a ticket or listing invoices.tradehall.mail.send(message)sends an email.tradehall.http.fetch(url, options)calls an HTTPS API on a domain the automation allows.secretnames a secret from Settings, Automation secrets, which Tradehall adds to the request. The script never sees its value.tradehall.log(line)writes to the run’s log.
How it runs
Section titled “How it runs”A script runs sandboxed on the queue worker as the automation’s own staff account, so that account’s role caps what it can do. It has no file system, database, or network access except through the calls above, and everything crosses into it as copies of JSON.
- Every run is logged with its result and what it called.
- Every save is a version, and a version rolls back in one click.
- An automation that keeps failing pauses itself and emails the owner.
Drafting with AI
Section titled “Drafting with AI”Describe the rule, such as “When a client signs up, add them to Mailchimp with the tag new-client.” An agent writes the script, then Tradehall replays it on recent matching events with nothing sent, and shows what it would have done: which services it calls, which secrets it uses, and any samples that failed. A person with permission approves it and turns it on, or discards it. Drafting needs ANTHROPIC_API_KEY.
Limits
Section titled “Limits”| Setting | Default | What it does |
|---|---|---|
AUTOMATIONS_TIMEOUT_SECONDS |
10 | Longest a run may take, calls included |
AUTOMATIONS_MEMORY_MB |
64 | Roughly how much memory a run may use before it’s stopped |
AUTOMATIONS_RUNS_PER_MINUTE |
30 | Runs per automation per minute |
AUTOMATIONS_PAUSE_AFTER |
5 | Failures in a row before it pauses |
AUTOMATIONS_KEEP_DAYS |
90 | How long run logs are kept |
Set GOMEMLIMIT on the worker as the hard memory cap.