# Workflows (https://docs.neuralisapp.com/agent-core/workflows)

<Callout title="Maturity: beta (75 %)">
**Workflows and scheduling.** Workflows run agent work on schedules, webhooks, channel messages or on demand, as their creator, with a Calendar view, upgradable templates and run notifications.

- Workflows run in a single process; a second replica would run every schedule twice.
- Platform events cannot trigger a workflow.
- Installing a workflow template copies it; installed copies are upgraded explicitly, never live-linked.

[How maturity is measured](https://docs.neuralisapp.com/getting-started/maturity.md)
</Callout>

A **workflow** is a persistent, per-agent entry that fires an instruction into
a normal agent stream — on a schedule, over HTTP, from a channel message, or on
demand. A run calls the same stream as interactive chat, so billing, tool
gating, package and feature filtering, quotas and conversation persistence apply
exactly as they do when a person types. The workspace surface is the
[Calendar](https://docs.neuralisapp.com/agent-core/app-surfaces.md#calendar); an agent uses the
[`workflow` tool](https://docs.neuralisapp.com/agent-core/tools.md#workflow) and the `manage-workflows` skill.

One deliberate difference: runs always execute in the **auto** profile — nobody
is there to approve a headless run, so **no tool pauses for approval**. That
grants no extra power: a run has its creator's *current* permissions, and a tool
the creator may not use is **refused**, not asked about. Design instructions
around the agent's granted scope, not around approval prompts.

## The workflow entry [#the-workflow-entry]

Each entry belongs to one agent and carries:

- `title`, optional `description`, `color` and `icon`;
- `instructionTemplate` — the prompt fired on every run (up to 10 000
  characters). It supports `{{WORKFLOW_DIR}}`, `{{WORKFLOW_STATE_URI}}` (a
  `data://` folder for durable state between runs) and `{{FIRE_TIME}}`; unknown
  placeholders stay literal. The tool names that state folder as `state=<uri>`
  in its answers, so an agent can hand it to a subagent;
- `stateMode` — `fresh` opens a new conversation per fire; `continue` keeps one
  thread, and later fires that carry an incoming message deliver just that
  message;
- `triggers` — schedules, webhooks and channel `message` triggers; an entry with
  none is *manual-only*;
- `executionPolicy` — per-workflow concurrency (default 1), a wall-clock limit
  (omitted, the platform default of 4 hours applies, under a 24-hour ceiling
  only `platform.config` can raise), and an optional model policy: model,
  reasoning effort, an exact catalog-declared context window, and fast on/off.
  Omitted fields inherit the agent's defaults at fire time; incompatible
  combinations are refused on save, and a combination that drifts out of the
  catalog fails before streaming and pauses the workflow;
- `sessionSetup` — an optional **goal and loop** seeded into every run's
  `<session>` block (a goal with checkable done-conditions, `until` and an
  enforced `maxSteps`). The goal is seeded whenever the run's conversation has
  none and displaces a goal the agent set for itself, never one a person wrote;
  every run's block also carries a live `Steps` counter against the real
  ceiling;
- `visibility` — `project` or `private`; `status` — `draft`, `active`,
  `paused`, `archived` (only `active` fires; pausing deletes nothing);
- `creator` — the identity the workflow runs as.

The `workflow` tool takes one `model` string: an exact id from the
caller-scoped model listing with optional reasoning/context/fast suffixes, or
`default.` plus suffixes to keep the agent's model and pin only the modifiers.

**Archive, restore, delete.** An archived workflow stops firing and is
read-only; its one allowed change is **restore**, which brings it back paused.
An archived entry can be **permanently deleted** — with its run history and
channel bindings, refused while a run is queued or running, and recorded in the
audit log. The conversations its runs streamed into are kept.

## Triggers [#triggers]

- **Schedule** — a timezone-aware **cron** expression (`#` nth-weekday and `L`
  last-day included) or a **one-shot** ISO time. The scheduler ticks every 30 s
  with a per-workflow jitter of up to 60 s, so many workflows on one cron line do
  not stampede. Each occurrence maps to a deterministic run id, so a crash
  cannot double-run it. A fire missed while the platform was down still runs if
  it is inside the catch-up window (15 minutes by default) and is marked as
  backfilled — unless someone already ran the workflow by hand at or after the
  scheduled time, which counts as that run; anything older is skipped and recorded, and at most one run per
  trigger is ever caught up. Spent one-shots and expired crons complete the
  workflow.
- **Channel message** — attached by a channel binding; see
  [channels](https://docs.neuralisapp.com/agent-core/channels.md).
- **Webhook** — an HTTP address of its own (below).
- **Manual** — the tool's `run`, the route, or *Run now*.

### The fire endpoint [#the-fire-endpoint]

A `webhook` trigger gives a workflow `POST /api/webhooks/workflow/<workflowId>/fire`.
Anything that can make an HTTP request — a CI job, a monitoring alert, another
system's automation — can start a run with it. The body reaches the run as
untrusted, delimited content after the instruction, never inside it.

Naming a hook does not open it. Its key is minted separately and **shown once**,
from the workflow's **Triggers** section; rotating retires the previous one at
once, and **Revoke** closes the endpoint again. Until a key exists — and while the
workflow is not **active** — the endpoint gives the same `401` as to an unknown
caller, so a caller learns nothing about which it was. Only a person mints a
key: the route refuses an agent's session ticket, because a show-once secret in
a conversation would be readable by everyone who later reads it.

Each hook proves its caller one of two ways:

- **Bearer token** (the default) — `Authorization: Bearer <token>`. Only a
  salted hash is stored.
- **HMAC signature** — the GitHub and Meta shape: the sender signs the body with
  a shared secret (HMAC-SHA256, hex) and sends the digest in a header you name,
  optionally behind a prefix such as `sha256=`. The secret lives in the
  credential store, generated once or pasted from the sending service. It
  **replaces** the bearer on that hook. A valid signature proves the sender
  holds the secret and the bytes are intact — not that the request is recent;
  only an event id taken from the signed body (a JSON pointer) binds a replay.

Each hook also declares its **body contract**:

- **Body** — *Plain text* (an optional `text` field, up to 4 000 characters) or
  *JSON*, optionally checked against a small schema (`type`, `properties`,
  `required`, `enum`, length and range bounds). Regex keywords, `$ref` and
  combinators are refused, because a caller-shaped regex on a public endpoint is
  a denial-of-service primitive; the schema is trial-compiled when you save it.
- **Max body bytes** — optional. Without it a JSON hook accepts 4 000 bytes and a
  plain-text hook the platform's 64 KiB ingress limit. Over budget answers
  `413`, a schema rejection `400`, each as a fixed sentence that names the class
  and nothing else — and only to a caller whose key already verified.
- **Event id** — a header name or a JSON pointer. A redelivery of the same event
  reaches the *same* run (`202` naming it), and two simultaneous deliveries
  produce one. A call without an event id still fires.
- **Answer** — `202` as soon as the run is queued, or, for a hook set to *Can
  wait for the run*, `?wait=<seconds>` holds the request until the run ends and
  answers `200` with its status and summary (`202` if the wait runs out). The
  wait is clamped by the platform's wait cap. Opting in makes the hook's key a
  *read* credential for those outcomes, which is why it is off by default.

## The run queue [#the-run-queue]

Fired runs enter a queue with a **platform-wide concurrency cap** (16 by
default) and the per-workflow `maxConcurrent`. A run whose target conversation
has a live interactive turn defers 15 s instead of colliding with it. A
**queued** run cancels in place; a **running** run aborts its stream.

**Interruptions resume.** A run cut off by a restart finalizes its turn first,
then **continues where it stopped** when the platform is back — the same
conversation, no fresh instruction. Each continuation counts against its own
budget (5 by default; 0 turns resuming off); once spent, the run fails as
`interrupted_resume_exhausted`. A run someone cancelled deliberately is never
restarted. Tool results from the interrupted turn come back marked as
interrupted, so an agent should check whether a step landed before repeating it.

**Failures retry by their classified reason.** A provider rate limit or
overloaded upstream is retried after the longer of the platform's backoff and
the delay the provider asked for; a retry of a run that already produced work
continues it on the same model. A usage window or spend cap is never retried,
and neither are permanent or unclassified failures. A channel waiting on a run
is told once, at the end, with a fixed notice that never repeats an internal
error.

**Waiting on a run.** `run` returns once the run is queued. With
`wait_seconds` (clamped to the administrator's cap, 120 s by default, at most
300; 0 turns waiting off), `run` and `get` return the final state and summary
when the run ends, or a snapshot at the deadline — not an error, and the right
move then is to ask again later, never to poll in a loop.

## Creator identity [#creator-identity]

Every run executes **as the workflow's creator** — there is no system or service
identity for scheduled work. The stored snapshot of the creator is an audit
record, never authority: at every fire the creator's *current* role and grants
are re-resolved.

- If they cannot be resolved, the fire fails closed.
- If the creator left or lost access, the run fails and the workflow pauses with
  a reason; if their membership record cannot be read at all, it pauses as
  `creator_resolve_failed` — a different remedy, for an operator.
- A paused workflow does not run on its own: a waiting retry or scheduled run is
  cancelled rather than started.
- Editing the instruction or the session setup makes the **editor** the creator,
  so nobody can plant instructions that would run under a stronger user's
  identity.

A workflow can be created on **another agent**: the route takes a target
`agentId` and the tool an `agent_id`, so one agent can provision recurring work
for another. That needs real update access to the target, an unknown target
answers like a forbidden one, and the run still executes as its creator. Prefer
`project` visibility there — a `private` entry stays invisible to the target
agent's own users.

Every run that delivers its instruction opens with one fixed, system-generated
**provenance line** naming the workflow, the creating user and the agent it was
created from. It grants nothing, but lets the receiving agent see who gave the
task and refuse anything outside that authority; a lookalike later in the text
is visibly altered.

## Visibility and access [#visibility-and-access]

`workflow.read` views, `workflow.write` creates, edits, pauses, archives,
restores, deletes and manages channel bindings, and `workflow.dispatch` runs and
cancels — on the routes, the tool and the skill's scripts alike. **An agent can
do everything a member can** with workflows, with exactly that member's
permissions; the skill's scripts run in the agent's shell, so they also need
`server.shell`. The one exception is any operation that carries a secret — issuing
or rotating a bearer token, generating or storing a signing secret, creating a
channel connection — which refuses an agent's session ticket, because the value
would land in a conversation others can read. `private` entries are visible only
to their creator and wildcard-grant holders (the `owner` role by default); an
entry you cannot see answers `404`, never `403`.

## Default templates [#default-templates]

The core packages ship a small set of templates. Each installs as a **draft**
(activation is always explicit), every shipped cron is in UTC, and each is
visible only to users whose grants cover what its runs need.

| Template | Package | Default schedule | What it does |
| --- | --- | --- | --- |
| Daily digest | agent-core | weekdays 09:00 | A recurring briefing on a topic, with carry-over state between runs. |
| Channel assistant | agent-core | manual | Talk to your agent from Telegram or WhatsApp: one continuous thread; install, then bind a channel connection. |
| Learning | agent-core | daily 02:30 | A self-improvement pass over recent activity (below). |
| System maintenance | admin | daily 07:00 | A platform-health report for owners and admins; remediates only within a narrow closed list. |
| Sources digest | brain-core | weekdays 08:00 | What changed across your synced sources since the last run. |
| Web watch | machine-core | daily 09:00 | A browser monitor that reports only real changes. |

A template that declares announce delivery installs with delivery on; routing
still needs a channel binding.

**When a template ships a new version**, an install is a copy, so nothing you
run is rewritten. Every stale copy is paused with a reason, and the calendar
offers **Upgrade** — re-rendered from your stored install answers, previewed
input by input, applied only on **Confirm upgrade**, keeping the run history,
state folder and bindings — while nobody has edited the instruction, or **Merge
with the agent**, which hands your edited copy and the new version to the agent
to reconcile. Either way the new instruction never runs unreviewed: an active
workflow comes out paused, and whoever upgrades becomes its creator. An upgrade
that needs an input the workflow has no answer for refuses and names it. Agents
do the same through the `manage-workflows` upgrade script, with a dry run.

### The Learning workflow [#the-learning-workflow]

The **Learning** template is the deployed self-improvement loop; the daily cron
is only a default. One pass inventories recent conversations, plans, commits,
workflow reports and changed sources within fixed item, depth and byte limits;
curates privacy-safe **linked memory** as its primary output, treating code and
its README as authoritative over stale memory; requests an artifact-only summary
of a few high-value threads through the official summarize operation (never
writing a conversation folder itself); and writes a dated report. With
`AUTO_APPLY` off (the default), edits to identity, docs, config, roles,
credentials, packages and schedules stay proposals. Scheduled Learning never
reads or writes identity files. The `learning` skill works manually too.

## Storage [#storage]

Workflows live in the agent's data folder:

```text
data://agent-core/<agentId>/workflows/<workflowId>/
├── entry.json              the workflow entry
├── state/                  durable scratch space between runs
├── instruction-revisions/  immutable history of the instruction
└── runs/<runId>/
    ├── meta.json           run status, timing, trigger kind
    └── events.jsonl        bounded operational log
```

The transcript is the conversation the run streamed into, linked from the run
and badged as workflow-born in the conversation picker. An agent reads its own
workflows; other agents' workflow folders are unreadable by default, with an
owner/admin override; `runs/**` is read-only for everyone. The instruction
history is write-protected by a
[hard limit](https://docs.neuralisapp.com/package-system/uri-policies.md) no policy edit can lift: no filesystem tool or route can
write it, not even the owning agent or an owner.