Render the workflow graph and per-unit loop diagrams.
Diagram rendering only needs the compiled graph topology, so the LLM is
never called. The provider is still read from the environment via
Config() rather than pinned to a local Ollama, so the command works
wherever the package is installed.
Source code in ontocast/cli/plot_graph.py
| @click.command()
@click.option(
"--output-dir",
type=click.Path(file_okay=False, path_type=Path),
default=Path("docs/assets"),
show_default=True,
help="Directory to write diagrams into. Created if absent.",
)
def main(output_dir: Path) -> None:
"""Render the workflow graph and per-unit loop diagrams.
Diagram rendering only needs the compiled graph topology, so the LLM is
never called. The provider is still read from the environment via
``Config()`` rather than pinned to a local Ollama, so the command works
wherever the package is installed.
"""
output_dir = Path(output_dir)
output_dir.mkdir(parents=True, exist_ok=True)
config = Config()
config.tool_config.path_config.ontology_directory = None
toolbox = ToolBox(config)
app = create_agent_graph(toolbox)
graph = app.get_graph()
mmd_data = graph.draw_mermaid(frontmatter_config=frontmatter_config)
(output_dir / "graph.mmd").write_text(mmd_data)
graph_stem = str(output_dir / "graph")
try:
pgv_module = importlib.import_module("pygraphviz")
draw_graphviz(pgv_module, graph, graph_stem, ("svg", "png"), rankdir="TB")
draw_graphviz(pgv_module, graph, graph_stem, ("svg", "png"), rankdir="LR")
write_atomic_loop_diagrams(pgv_module, output_dir)
except ImportError as e:
logger.info(f"pygraphviz not available, skipping graphviz output: {e}")
try:
from langchain_core.runnables.graph import MermaidDrawMethod
png_data = graph.draw_mermaid_png(
draw_method=MermaidDrawMethod.API,
frontmatter_config=frontmatter_config,
padding=20,
)
(output_dir / "graph.preview.png").write_bytes(png_data)
except ImportError as e:
logger.info(f"MermaidDrawMethod not available, skipping mermaid PNG: {e}")
|