Automations
An automation is a condition on objects and the work to start when it becomes true. When a raw milk silo passes 60 hours since its first fill, ask the planning agent for a draw plan. When a shop's freezer reads above −15 °C for ten minutes, notify the manager and open a maintenance task. Automations are evaluated from the Ontology's change feed, so they react within seconds of a source change, and every evaluation and every effect is recorded
In the platform today
- Automations run in the platform service, defined under
automationsinontology.yamlor throughPOST /api/v2/automations - Each has an
ownerit runs as, onetriggerand oneeffect - Triggers are
objects(added, removed or modified, optionally on chosen properties and a filter),threshold(an object set gains a member, with recovery recorded when it leaves),schedule(every N minutes or hours, or daily at a time) andsignal(a new match of an outside signal watch, optionally at chosen severities) - Effects are
propose(with an optionalexpireAfterfor the proposal),function,agentandnotify(an in-app notification to a user or a group), per object or as a batch, with up to 5 attempts, backoff and an optional failure effect - An
agenteffect starts the run in the background and records its id, or withforEacha batch over every matching object; if the run fails, is interrupted or gets no answer in time, the automation run is marked failed and the failure effect runs - The service reads each watched table's change feed every 30 seconds by default, a service setting
- Firing is at least once and deduplicated per object version or schedule slot
- Automations can be paused, muted, given an expiry of at most six months, and run by hand; one is muted on its own after repeated failures
- When the owner is deactivated in the directory, the automation runs as the service owner named at deactivation or in
directory.serviceOwner, and the handover is recorded on the owner's entry - A monitor rule of kind
automationalerts on repeated failures
- The other triggers, an apply effect, several effects per automation, cooldown and debounce, rate limits, the dead-letter list, pausing when the owner loses access and backtests
- Editor role on the project to create or change an automation, through a proposal like any other Ontology change
- An owner, a person or a service account with a named human sponsor, who can read the watched object types and run every effect: the agent, the function or the action
- The access labels on the watched objects, held by the owner; recipients of a notification must be able to see the triggering object
- Action types used as effects set to allow proposals from automations, or automatic application from automations for an apply effect
How an automation works
The service reads the change feed of each type an automation watches, evaluates the condition against each new object version, and runs the effect when the condition becomes true for an object. It fires on transitions, not states, which is what keeps automations quiet: a silo that stays above 60 hours fires once, not on every sensor reading. On request, conditions are evaluated the moment each change lands, and time-based conditions fire at the moment they come due
Conditions
A condition is a trigger on one object type, narrowed by a where filter in the same syntax as object sets
| Trigger | Fires when | Example |
|---|---|---|
objects | An object is added, removed or modified, optionally only when chosen properties change | A net quantity check is recorded as failed |
threshold | An object enters an object set, such as a property crossing a value. Recovery is recorded when it leaves | A silo passes 60 hours since receipt |
schedule | Every N minutes or hours, or daily at a time in the ontology's time zone | 06:00 every day, check weekend cover |
signal | An outside signal, such as a recall or a weather warning, makes a new match of a watch, optionally only at chosen severities | A supplier recall reaches batches in market |
On request, more triggers, such as an object leaving a set, a sustained threshold, a moment computed from a property, an applied action and a time series alert
Defining an automation
Automations are defined under automations in ontology.yaml or through POST /api/v2/automations. This is the silo automation the creamery's planners rely on to keep raw milk from ageing out
automations:
- id: r-silo
name: Silo past 60 h
owner: milk.murphy
trigger:
kind: threshold
objectType: silo
where: { hoursSinceReceipt: { $gte: 60 }, volume: { $gt: 0 } }
effect:
kind: agent
agent: agt-milk
input: "{{object.name}} is at {{object.hoursSinceReceipt}} h of its 72 h limit"
context: { siloId: "{{object._key}}" }
attempts: 3
onFailure:
kind: notify
group: milk-receiving
message: "{{automation.id}} failed: {{error}}"
An effect runs once per object, or once for the whole set with mode: batch. A failed effect is retried up to its attempts with backoff, and onFailure runs when the last attempt fails
An agent over many objects
An agent effect with forEach runs the agent once for every object of a type that matches a filter, as one background batch each time the effect runs. The effect's input and context are filled per object from {{object.<property>}}, the filter can use the automation's own values, and parallel and costLimitCad cap the batch. The automation run records the batch and how many objects it covers, and the batch's runs are followed like any other
effect:
kind: agent
agent: agt-weekend
input: "Weekend cover for {{object.name}}"
forEach:
type: shop
where: { status: { $ne: Closed } }
parallel: 2
costLimitCad: 5
Effects
| Effect | What happens | Requires |
|---|---|---|
| Start an agent run | Runs an agent in the background with the triggering object or set in its context, or once per matching object with forEach. Proposals go to the owner or a named group | The owner can run the agent |
| Run a function | Calls a query function and stores its result in the execution log, or passes it to a later effect | The owner can call the function |
| Propose an action | Creates a proposal with parameters from the object or a function result | The action type allows proposals from automations |
| Apply an action | On request: applies an action directly as the owner | The action type allows automatic application from automations, and the owner can apply it |
| Send a notification | An in-app notification to a user or a group, from a template; email and webhooks on request | Recipients can see the triggering object |
Edit functions cannot be used as direct effects, because an edit set with no action around it has nowhere to be validated or logged. To change objects, use an action effect whose action type runs the edit function. If the edit function's result should be reviewed first, use a proposal effect
An automation can apply an action only if the action type's own settings allow automatic application from automations, which is off by default, and the automation is configured to apply rather than propose. Holding and releasing production batches should stay manual for the reasons in tools and guardrails
Common patterns
Most automations fall into a handful of shapes. Naming the shape early helps choose the trigger, the dedupe key and the effect
| Pattern | Shape | Example |
|---|---|---|
| Watchdog | Threshold or time-relative trigger, notification effect, short cooldown | A shop freezer above −15 °C for 10 minutes notifies the manager on shift |
| Escalation | Two automations on the same condition with different delays and recipients | A late reefer run notifies dispatch at 30 minutes and the distribution lead at 90 |
| Planner on call | Starts-matching trigger, agent effect at Stage, dedupe per cycle | A silo nearing its limit starts the plant planning agent |
| Follow-through | Action-applied trigger, proposal or notification effects on linked objects | After a batch hold, every shop holding the lot gets a pull-from-sale task |
| Digest | Schedule trigger over a set, batched, one function and one notification | Thursday 13:00 summary of weekend cover for all shops |
Escalations are better built as two automations than as one with a wait inside it. Each has its own history and its own owner, and either can be paused without the other. A condition that resolves before the second delay simply never fires the second automation, because the object has left the set
Delivery semantics
Firing is at least once and deduplicated per object version or schedule slot, so a re-evaluation of the same version runs nothing. Past the boundary of the Ontology, such as a webhook receiver or a writeback target, the receiving code has to make a repeat harmless, as described in webhooks and writeback. On request, cooldowns, debounce and rate limits per automation
Identity and permissions
An automation runs as its owner. Every read, function call, agent run and action it starts uses the owner's access, and the action log records the automation as the origin and the owner as the actor. Ownership can be a person or a service account with a named human sponsor; group ownership is not allowed, because "the group did it" is not an answer the audit trail should ever have to give
When the owner is deactivated in the directory, the automation runs as the service owner named at deactivation, and stops until someone takes it over when none is named. An Administrator or a watcher with the Editor role on the automation's project can take ownership, which is recorded in the audit log
On request, when the owner loses access that an automation needs, for example they leave the plant planning group, the automation pauses at the next firing that would need it, records why, and alerts the automation's watchers, rather than failing silently or running with stale access
History, testing and monitoring
Every run is recorded with its trigger, effect, status and result, readable through GET /api/v2/automations/{id}/runs, and every firing is audited. An automation can be run by hand, paused, muted or given an expiry, and one is muted on its own after repeated failures. A monitor rule of kind automation alerts on repeated failures. On request, a dead-letter list for failed effects and backtests that replay past changes to show when an automation would have fired
Limitations
- Conditions fire on transitions, not states, so turning an automation on does not fire for objects that already match; use a schedule trigger to sweep an existing set
- Firings for different objects have no ordering between them, only firings for the same object
- Edit functions cannot be direct effects; changes to objects always go through an action type
- Automatic application needs both the action type and the automation to allow it, and neither setting alone is enough
- Group ownership is not allowed. An automation always runs with its owner's current access, never with access the owner has lost