Skip to content
LlamaAgents
Agent Workflows

Drawing a Workflow

Workflows can be visualized from the same type annotations the runtime uses for validation. That makes diagrams useful in two different moments: before a run, to see every possible path, and after a run, to see what actually happened.

There are two main ways to visualize a workflow.

First install:

Terminal window
pip install llama-index-utils-workflow

Then import and use:

from llama_index.utils.workflow import (
draw_all_possible_flows,
draw_all_possible_flows_mermaid,
draw_most_recent_execution,
draw_most_recent_execution_mermaid,
)
# Draw every statically possible path as HTML
draw_all_possible_flows(MyWorkflow, filename="all_paths.html")
# Draw the same static graph as Mermaid
mermaid = draw_all_possible_flows_mermaid(MyWorkflow)
# Draw one completed execution as HTML
w = MyWorkflow()
handler = w.run(topic="Pirates")
await handler
draw_most_recent_execution(handler, filename="most_recent.html")
# Draw the same completed execution as Mermaid
execution_mermaid = draw_most_recent_execution_mermaid(handler)

draw_all_possible_flows accepts either a workflow class or a workflow instance. The execution functions take a WorkflowHandler, so you need to run the workflow first.

Long event names can make diagrams hard to read. Pass max_label_length=... to truncate node labels:

draw_all_possible_flows(MyWorkflow, filename="all_paths.html", max_label_length=24)

By default, static diagrams include child workflows. Pass include_child_workflows=False if you want only the parent workflow graph.

The WorkflowServer serves a debugger UI at /. Use it when you want to run a workflow, inspect events, and send human-in-the-loop responses from a browser.

Using this server app, you can visualize and run your workflows:

workflow debugger

Setting up the server is straightforward:

import asyncio
from workflows import Workflow, step
from workflows.events import StartEvent, StopEvent
from llama_agents.server import WorkflowServer
class MyWorkflow(Workflow):
@step
async def my_step(self, ev: StartEvent) -> StopEvent:
return StopEvent(result="Done!")
async def main():
server = WorkflowServer()
server.add_workflow("my_workflow", MyWorkflow())
await server.serve("0.0.0.0", 8080)
if __name__ == "__main__":
asyncio.run(main())
Note for AI agents: this documentation is built for programmatic access. - Overview of all docs: https://developers.llamaindex.ai/llms.txt - Any page is available as raw Markdown by appending index.md to its URL — e.g. https://developers.llamaindex.ai/llamaparse/parse/getting_started/index.md - Agent-friendly REST search APIs live under https://developers.llamaindex.ai/api/ — search (BM25 full-text), grep (regex), read (fetch a page), and list (browse the doc tree). See https://developers.llamaindex.ai/llms.txt for parameters. - A hosted documentation MCP server is available at https://developers.llamaindex.ai/mcp. If you support MCP, you can ask the user to install it for browsing these docs directly (an alternative to the REST API). Setup: https://developers.llamaindex.ai/python/shared/mcp/