This page only applies to newer versions of the framework (v1.x and higher)
Agency Swarm provides two visualization methods:
  1. visualize() - Creates interactive HTML files
  2. get_agency_structure() - Returns ReactFlow-compatible JSON

visualize()

Creates a self-contained HTML file with interactive agency visualization.
def visualize(
    self,
    output_file: str = "agency_visualization.html",
    include_tools: bool = True,
    open_browser: bool = True
) -> str

Parameters

ParameterTypeDefaultDescription
output_filestr"agency_visualization.html"Path to save HTML file
include_toolsboolTrueWhether to include agent tools
open_browserboolTrueWhether to open in browser

Example

from agency_swarm import Agency, Agent, function_tool

@function_tool
def analyze_data(data: str) -> str:
    """Analyze data"""
    return f"Analysis: {data}"

analyst = Agent(
    name="Analyst",
    instructions="You analyze data.",
    tools=[analyze_data]
)

manager = Agent(
    name="Manager",
    instructions="You coordinate work."
)

agency = Agency(
    manager,
    communication_flows=[(manager, analyst)],
    name="Analysis Agency"
)

# Create visualization
html_file = agency.visualize()
print(f"Saved to: {html_file}")