Workflows
A workflow runs an automation every time its trigger fires: review each opened pull request, triage each support email, send a daily digest, or draft and revise a change until a human merges it. You describe it as a small YAML file with one trigger and a graph of steps. Tangle starts the sandboxes, drives the agents and remembers where every run is, so a run can wait hours for a person or an event and continue where it stopped.
Workflows run on Tangle Platform at id.tangle.tools. You author and run them with the tangle workflows commands or in the Platform app.
The Sandbox SDKs have no workflow API; a workflow’s agent.run and script.run steps start sandboxes for you.
How a workflow is built
- Trigger (
on): what starts a run. A provider event such as a GitHub pull request or a Slack message, a cron schedule, or the workflow’s own webhook. One per workflow. - Steps (
do): the nodes of the graph.agent.runruns an agent in a sandbox, or makes a single model call with no sandbox.script.runruns your TypeScript in a new sandbox.integration.invokecalls a connected provider such as GitHub or Gmail.notifyposts a signed webhook.decisionwaits for a person.wait.timerandwait.eventwait for a time or an event.workflow.runstarts a child workflow.parallelandforeachfan out. - Graph (
id,needs,join): a plain list runs top to bottom. Addidandneedsto run steps in parallel, join them, route errors, or loop with guarded back-edges.maxNodeVisitsbounds a loop. - Expressions (
${...}): string values can read the trigger and earlier steps, such as"${trigger.payload.pull_request.number}"or"${steps.draft.text}". - Durable runs: a run that reaches a
decision, awaitor aworkflow.runparks with statuswaitingand frees its worker. It resumes when the wait ends. Every step’s output is kept for you to inspect. - Revisions: every update adds a revision. You can read old revisions and roll back to one.
The Sandbox dashboard lists your workflows and lets you enable, disable or delete them. The Platform app adds authoring, the full run history, decision approvals and revision history.
Your first workflow
1. Log in with the CLI
curl -fsSL https://sandbox.tangle.tools/install.sh | sh
tangle auth login --api-key "$TANGLE_API_KEY"Use the same sk-tan- key as for sandboxes, from id.tangle.tools/app/keys.
tangle workflows talks to Tangle Platform; --base-url on these commands, or TANGLE_PLATFORM_URL, names that host.
2. Write a definition
Save this as hello.yml. It writes a greeting every weekday morning with one model call and no sandbox:
name: hello-workflow
on:
schedule:
cron: "0 9 * * 1-5"
timezone: UTC
do:
- agent.run:
topology: { inference: {} }
profile:
name: greeter
prompt:
systemPrompt: "You write short, cheerful greetings."
prompt: "Write a one-line good-morning greeting."3. Validate and create
tangle workflows validate hello.yml
tangle workflows create hello.ymlvalidate compiles the file without saving it and reports every error with its path. create prints the new workflow id.
4. Run it and watch
A manual run works with any trigger, so you do not have to wait for the schedule:
tangle workflows run <id> --wait
tangle workflows runs <id>
tangle workflows events <id> <run-id>
tangle workflows run-detail <id> <run-id>run --wait starts a run and prints its result. runs lists the history, events follows a run’s progress and run-detail shows one run step by step.
The other commands are list, get, update <id> file.yml, enable, disable, delete and schema, which prints the JSON Schema. Workflow commands lists them all.
5. Or start from a template
tangle workflows templates lists the shipped templates, such as pull request review, issue triage and a daily digest, and tangle workflows init <template-id> writes one to a file you can edit.
See Workflow templates.
Connect a provider
A workflow that touches a SaaS account uses a connection: a provider_event trigger, an integration.invoke step, a provider wait.event, or a connections: [...] grant on agent.run or script.run.
A connection is an authorization, by OAuth or API key, between your Tangle account and one provider account such as GitHub, Slack, Gmail or Stripe. It is created once, stored on Tangle Platform and named by provider (connection: github). Neither the YAML nor a sandbox ever holds the provider’s tokens.
Connect a provider on the Integrations page, or with tangle hub connect github. One connection serves every workflow you own.
A workflow that names a provider with no active connection fails validation when you save it: validate and create both report it, so you find out before the trigger fires.
Example: a pull request review loop
A review is drafted, critiqued and revised in a guarded loop until the critic approves. Only then is it posted to GitHub.
name: pr-review-loop
description: Draft a PR review, critique it, revise until the critic approves, then post it
# 12 visits cover about three draft, critique and steer rounds.
maxNodeVisits: 12
on:
provider_event:
connection: github
event: pull_request
actions: [opened, ready_for_review]
when:
path: trigger.payload.pull_request.draft
op: eq
value: false
do:
# The guarded back-edge from steer is draft's only dependency, so draft runs first.
- id: draft
needs:
- id: steer
when: { path: "steps.critique.text", op: contains, value: "VERDICT: revise" }
agent.run:
profile: code-reviewer
source:
repo: "${trigger.payload.repository.full_name}"
pr: "${trigger.payload.pull_request.number}"
maxRounds: 3
prompt: "Review this pull request and produce a complete, structured review as your final output. Steering notes from the last critique (empty on the first pass): ${steps.steer.text}"
- id: critique
agent.run:
topology: { inference: {} }
profile:
name: review-critic
prompt:
systemPrompt: "You check a draft PR review for accuracy and tone. End your response with exactly one line: VERDICT: approve or VERDICT: revise."
prompt: "Check this draft review: ${steps.draft.text}"
# steer is skipped unless the verdict was revise, which ends the loop on approve.
- id: steer
if: { path: "steps.critique.text", op: contains, value: "VERDICT: revise" }
agent.run:
topology: { inference: {} }
profile:
name: steering-editor
prompt:
systemPrompt: "You turn review feedback into short, actionable steering notes."
prompt: |
The critic asked for changes: ${steps.critique.text}
Write steering notes for the next draft.
# publish re-arms every round; its if lets it fire only on the approving round.
- id: publish
needs: [critique]
if: { path: "steps.critique.text", op: contains, value: "VERDICT: approve" }
integration.invoke:
path: github.pulls.reviews.create
identity: app # post as the bot, not as the person who connected GitHub
input:
owner: "${trigger.payload.repository.owner.login}"
repo: "${trigger.payload.repository.name}"
pull_number: "${trigger.payload.pull_request.number}"
event: COMMENT
body: "${steps.draft.text}"How the loop works:
- The back-edge controls the cycle.
draftdeclaresneeds: [{ id: steer, when: ... }]. Every cycle must carry at least one guarded edge, so the compiler accepts this loop, and the guard (VERDICT: revise) is what runsdraftagain. - A guard is judged on each successful completion of the step it watches. When a guard is false, its edge is closed for that completion only and is judged again the next time its source completes successfully. Inside a loop, a guarded edge fires on the round its condition first holds. A failed step never reopens a closed edge, because it produced no output to judge.
- The budget stops a loop that never converges.
maxNodeVisits: 12fails the run withCYCLE_BUDGET_EXCEEDED, so a critic that never approves cannot spend without limit. - Steps are addressed by id or by index.
${steps.draft.text}, an edgewhenand a step-levelifall acceptsteps.<id>.fieldorsteps[N].field. A hyphenated id needs the quoted form,${steps["my-id"].text}. The id form survives reordering thedolist. - An
ifreads only steps that are certain to have run. That is every step the action depends on throughneeds, directly or further back. Withjoin: anyorany_failed, only the steps common to every branch count, because which branch ran is unknown. The compiler rejects anifthat reads any other step, since it would resolve to nothing and skip the action without saying so.
identity: app posts the review as the Tangle Hub GitHub App, so it does not carry the authority of the person who connected GitHub. GitHub refuses a REQUEST_CHANGES review from that person on a pull request they opened, which is the case an always-on reviewer exists to cover.
event: APPROVE is not available under identity: app; the YAML reference explains why and lists the actions it applies to.
This example needs a connected GitHub account (connection: github). The identity: app step also needs the Tangle Hub GitHub App installed on the repository and write access for you, and fails with a clear error when either is missing.
To try the same draft, review, steer and publish loop without a connection, start from the ralph-loop template in Workflow templates.
Next
- Workflow YAML reference: every trigger, step, expression and limit.
- Run, inspect and trace workflows: runs, decisions, artifacts and revisions.
- Workflow templates: the shipped templates.
- Workflow commands: every
tangle workflowscommand.