[Python] How to expand multi-agent graph plot in LangGraph

Discussão em 'Python' iniciado por Stack, Junho 29, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using LangGraph do design a multi-agent system where a supervisor agent control worker agents. When I display the graph, the worker agents' graph is collapsed.

    Even though the worker agents' graphs can be shown separately, it would be nicer to expand/unfold these graphs, to give a complete picture of the system.

    from IPython.display import Image, display
    from langgraph.prebuilt import create_react_agent
    from langgraph_supervisor import create_supervisor
    from langchain.chat_models import init_chat_model

    def fn():
    """Do something"""
    pass

    model_config = {"model": "gpt4-o", "model_provider": "openai"}

    worker = create_react_agent(
    model=init_chat_model(**model_config),
    tools=[fn],
    name="worker",
    )

    supervisor = create_supervisor(
    model=init_chat_model(**model_config),
    agents=[worker],
    ).compile()

    print("Supervisor graph:")
    display(Image(supervisor.get_graph().draw_mermaid_png()))
    print("Worker graph:")
    display(Image(worker.get_graph().draw_mermaid_png()))


    [​IMG]

    Continue reading...

Compartilhe esta Página