AAnvio
Workflows & Automation

Workflow DAGs

File-defined dependsOn graphs of agent, transform, conditional, and parallel nodes, executed by the standalone DagExecutor.

5 min read

A Workflow is a directed acyclic graph (DAG) of nodes, each declaring which other nodes it dependsOn. The executor (DagExecutor in packages/workflows/src/dag-executor.ts) runs all nodes whose dependencies are satisfied in parallel batches, until the graph is fully resolved. Workflows are defined as files — Markdown (frontmatter + docs body) or YAML — under workspace/workflows/.

This is a standalone engine in @anvio/workflows, separate from (but composable with) Blueprints and the Automation Engine.

Real example: workspace/workflows/example-dag.md

---
apiVersion: anvio.io/v1
kind: Workflow
metadata:
  slug: example-dag
  version: "1.0.0"
  catalog: private
spec:
  description: Demonstrates dependsOn DAG with parallel branches
  inputs:
    topic:
      type: string
      default: architecture
  nodes:
    - id: gather-a
      type: transform
      template: "Finding A for {{inputs.topic}}"
    - id: gather-b
      type: transform
      template: "Finding B for {{inputs.topic}}"
    - id: merge
      type: transform
      dependsOn: [gather-a, gather-b]
      template: |
        # DAG Report — {{date}}
        - {{nodes.gather-a.output}}
        - {{nodes.gather-b.output}}
  outputs:
    summary:
      from: nodes.merge.output
---

# Example DAG

Parallel gather nodes merge into a single report. Run with:

```bash
anvio workflow run example-dag topic=monorepo
```

For a .md workflow file, everything above the second --- is YAML frontmatter holding the actual Workflow spec; the Markdown body below it is human-readable documentation only — the executor never reads it.

The graph this produces

Rendering diagram…

gather-a and gather-b have no dependsOn, so the executor runs them in the same parallel batch. merge depends on both, so it waits for that batch to finish, then runs in the next batch, reading {{nodes.gather-a.output}} and {{nodes.gather-b.output}} via template interpolation.

Node types

workflowNodeTypeSchema (packages/core/src/schemas/workflow.schema.ts) defines 10 node types:

TypeBehavior
transformRenders template (or input) against the current context; pure string transform, no side effects
agentCalls runAgent(node.agent, input) — runs a named agent with rendered input
blueprintCalls runBlueprint(node.blueprint, inputs) — delegates to a Blueprint run
workflowCalls run(node.workflow, inputs) recursively — nests another DAG
channelRenders message/input — represents sending to a channel (output only in the executor; actual delivery is wired by the caller)
hookCalls runHook(hookPath, payload) if a hook runner is configured
parallelRuns node.steps/node.nodes concurrently via Promise.all, joins outputs with newlines
conditionalRenders condition; if it evaluates to the literal string "true" or "1", runs the then branch, else the else branch
mcpCalls mcpBridge.callTool({ serverId, toolName, arguments }) if an MCP bridge is configured
batchNot implemented in the executor — returns status: 'skipped', output [batch not configured]

Every node also supports onFailure: 'halt' | 'continue' (default halt) — controls whether a failed node stops the whole run or lets independent branches continue.

batch nodes are a recognized schema type but the DagExecutor always returns them as skipped with [batch not configured] — there's no batch runner wired into the executor today. Don't rely on type: batch nodes actually doing anything yet.

Template interpolation

Templates use {{expr}} placeholders resolved by a small interpolator built into the executor:

  • {{date}} → today's date, YYYY-MM-DD
  • {{inputs.<name>}} → a resolved workflow input
  • {{nodes.<id>.output}} → another node's output (only available once that node has completed)

Unresolvable paths render as an empty string rather than throwing — useful for optional fields, but worth testing your templates carefully since a typo silently produces "" instead of an error.

Execution model

Rendering diagram…

If no ready nodes exist but pending nodes remain (a cycle, or a dependency typo), the run returns status: 'failed' immediately rather than hanging.

--dry-run skips execution entirely: every node is reported as status: 'skipped' with output [dry-run] {type}, useful for validating a graph's shape without side effects.

Registry & file resolution

WorkflowRegistry.load(slug) (packages/workflows/src/workflow-registry.ts) checks, per directory (workspace first, then bundled), extensions in this order: .md, .yaml, .yml. First match wins — parsed with parseWorkflowMd for Markdown or parseWorkflowDefinition (from YAML) otherwise.

workspace/workflows/     # Your DAG definitions (kind: Workflow)
  example-dag.md
configs/workflows/       # Bundled catalog (if repoRoot is passed to createWorkflowRegistry)

CLI

anvio workflow list
anvio workflow validate workspace/workflows/example-dag.md
anvio workflow run example-dag topic=monorepo
anvio workflow run example-dag --dry-run

Composing with Blueprints

A Blueprint step can delegate to a workflow via type: workflow:

steps:
  - id: pipeline
    type: workflow
    workflow: example-dag

The platform wires runWorkflow into the BlueprintExecutor's dependencies when a workflow registry is available, so a blueprint step and a workflow node can call into each other (workflow to blueprint, blueprint to workflow) without special-casing.

Events

A completed workflow run emits anvio.workflow.completed.v1 on the event bus. The Automation Engine can trigger on this via trigger: { type: workflow, event: workflow.completed }.

From workflow to skill

A DAG that runs successfully and deterministically more than once is a good candidate to convert into a Skill — turning "run this graph" into "follow these instructions directly." The real conversion example in this repo:

ArtifactPath
Source workflowworkspace/workflows/example-dag.md
Derived skillworkspace/skills/dag-report-skill.md (metadata.sourceWorkflow: example-dag)

Authoring checklist from the source docs: keep workflow nodes to 7 or fewer for skill-sized procedures, name the skill slug to match the workflow slug for 1:1 conversions, and add metadata.sourceWorkflow to the skill frontmatter so the relationship is traceable.

Edit on GitHub

Last updated on

On this page