# Mermaid Agent Flow Diagram Cheat Sheet

An agent’s steps, and what kind of step each one is.

## A flow block

A flow is a block that owns the steps inside it. The end keyword closes it.

```mermaid
agentflow-beta TB
  flow worker["Worker"]
    job["Do the job"]@{ shape: task }
  end
```

![An agent flow diagram with one group called Worker containing a single step, Do the job.](/diagrams/agentflow/flow.svg)

## What kind of step is it

The word after shape: says what the step is. input, task, tool, decision, action and refdoc are the six.

```mermaid
agentflow-beta LR
  brief["Brief"]@{ shape: input }
  draft["Draft copy"]@{ shape: task }
  check["spell_check"]@{ shape: tool }
  guide["Style guide"]@{ shape: refdoc }
  ship["Publish"]@{ shape: action }
  ok["Ready?"]@{ shape: decision }
  brief --> draft --> check --> ship
  ok --> ship
```

![A left-to-right agent flow of six steps: a brief, a draft, a spell check tool, a style guide, a publish action and a ready decision.](/diagrams/agentflow/shapes.svg)

## Arrow forms

A labelled arrow says why. A cross is a retry, and a dotted line points at something to read.

```mermaid
agentflow-beta TB
  check["Tests pass?"]@{ shape: decision }
  ship["Ship it"]@{ shape: action }
  fix["Fix the build"]@{ shape: task }
  logs["Build logs"]@{ shape: refdoc }
  check -- yes --> ship
  check -- no --> fix
  fix --x check
  fix -.- logs
```

![A decision asking whether the tests pass, branching to Ship it on yes and to Fix the build on no, with a dotted line from the fix to a box of build logs.](/diagrams/agentflow/arrows.svg)

## Nesting flows

A flow can hold other flows. The inner ones are the sub-agents.

```mermaid
agentflow-beta TB
  flow team["Content Team"]
    flow researcher["Researcher"]
      gather["Gather sources"]@{ shape: task }
    end
    flow writer["Writer"]
      compose["Compose draft"]@{ shape: task }
    end
    researcher --> writer
  end
```

![A flow called Content Team containing two flows, Researcher and Writer, joined by an arrow, each holding one step.](/diagrams/agentflow/nested.svg)

## Draw it in Mernyx.

Open a .mmd file, move a node on the canvas, and the source comes with it. Native on macOS, no browser involved.
