2. Steps in a flow
An arrow (-->) sets the order of steps. a --> b runs b after a.
Code:
agentflow TB
flow blog["Blog post"]
research["Research"]@{ instruction: "Find three recent sources on the topic." }
outline["Outline"]@{ instruction: "Turn the sources into a five-point outline." }
draft["Draft"]@{ instruction: "Write a 600-word post from the outline." }
research --> outline --> draft
end
You can chain arrows on one line, as above, or write one arrow per line. Both mean the same.
Fan out and join
& lists several nodes on one side of an arrow. A task continues along every arrow that leaves it, so a --> b & c runs both b and c.
Code:
agentflow TB
flow launch["Launch"]
brief["Brief"]@{ instruction: "Summarise the product launch in five bullet points." }
tweet["Tweet"]@{ instruction: "Write a launch tweet from the brief." }
email["Email"]@{ instruction: "Write a launch email from the brief." }
review["Review"]@{ instruction: "Check the tweet and the email for tone and accuracy." }
brief --> tweet & email
tweet & email --> review
end
Don't add an arrow that skips a step. With brief --> review here, review would get the work from brief twice, so it's an error.
Code:
agentflow TB
flow launch["Launch"]
brief["Brief"]@{ instruction: "Summarise the product launch in five bullet points." }
tweet["Tweet"]@{ instruction: "Write a launch tweet from the brief." }
review["Review"]@{ instruction: "Check the tweet for tone and accuracy." }
brief --> tweet --> review
brief --> review
end
The arrow from "brief" to "review" skips a step: "brief" already reaches "review" through "tweet". Remove this arrow.
Flows after flows
An arrow can point at a whole flow. research --> write starts write when research finishes.
Code:
agentflow TB
flow research["Research"]
find["Find sources"]@{ instruction: "Find three recent sources on the topic." }
notes["Take notes"]@{ instruction: "Write short notes on each source." }
find --> notes
end
flow write["Write"]
draft["Draft"]@{ instruction: "Write a 600-word post from the notes." }
end
research --> write
If a flow has an arrow to the next flow, its last step can't also have an arrow leaving the flow. See the common mistake on the flow page.
Flows inside flows
A flow can hold other flows. An arrow can't point into a flow from outside it. Point it at the flow instead.
Code:
agentflow TB
flow team["Team"]
plan["Plan"]@{ instruction: "Split the work into two parts." }
flow writers["Writers"]
write["Write"]@{ instruction: "Write the first part." }
end
plan --> write
end
"plan" can't connect to "write", because "write" is inside flow "writers". Point the arrow at flow "writers" instead.
Next: 3. Branching with decisions.