Graph visualisation of structured response agent is weird and cannot visualise the graph in supervisor agent pattern. #1075

Closed
opened 2026-02-20 17:42:58 -05:00 by yindo · 1 comment
Owner

Originally created by @Kirushikesh on GitHub (Nov 28, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

from langchain.tools import tool
from langchain.agents import create_agent
from langchain.agents import AgentState
from langchain_core.tools import InjectedToolCallId, tool
from langgraph.prebuilt import InjectedState
    
class State1(AgentState):
    information: str

class State2(AgentState):
    information: str

class State3(AgentState):
    information: str

@tool
def get_temperature(query: str, state: Annotated[State2, InjectedState],   
    tool_call_id: Annotated[str, InjectedToolCallId])-> str:
    "This returns the temperature of a location at this moment"
    result = temperature_agent.invoke({
        "messages": [{"role": "user", "content": query}]
    })
    return result["messages"][-1].content

@tool
def get_temperature_celcius(location: str, state: Annotated[State3, InjectedState],   
    tool_call_id: Annotated[str, InjectedToolCallId])-> str:
    "This returns the temperature of a location at this moment in celcius"
    return "25 degree celcius"

@tool
def get_temperature_farenhite(location: str, state: Annotated[State3, InjectedState],   
    tool_call_id: Annotated[str, InjectedToolCallId])-> str:
    "This returns the temperature of a location at this moment in farenhite"
    return "25 degree farenhite"

@tool
def get_location(state: Annotated[State1, InjectedState],   
    tool_call_id: Annotated[str, InjectedToolCallId])-> str:
    "This returns the current location of the user"
    return "new delhi"

@tool(
    "subagent1_name",
    description="subagent1_description"
)
def call_subagent1(query: str, state: Annotated[State1, InjectedState],   
    tool_call_id: Annotated[str, InjectedToolCallId]):
    result = subagent1.invoke({
        "messages": [{"role": "user", "content": query}]
    })
    return result["messages"][-1].content

agent = create_agent(
    model=model, 
    tools=[call_subagent1, get_location],
    state_schema=State1,
    response_format=Handover,
)

subagent1 = create_agent(
    model=model, 
    tools=[get_temperature],
    state_schema=State2
)

temperature_agent = create_agent(
    model=model, 
    tools=[get_temperature_celcius,get_temperature_farenhite],
    state_schema=State3
)

from IPython.display import Image, display
display(Image(agent.get_graph(xray=True).draw_mermaid_png()))

Error Message and Stack Trace (if applicable)


Description

I am just building the supervisor agent pattern for my use case, where the top-level supervisor is to return the output in a structured format. I am seeing two issues,

  1. There is a weird arrow that goes and comes back to the same agent.
  2. As we are encapsulating the agent(s) inside the tool definition for the supervisor agent, is it possible to support/extend visualisation for that too?
Image

System Info

System Information

OS: Linux
OS Version: #1 SMP PREEMPT_DYNAMIC Fri Aug 9 14:06:03 EDT 2024
Python Version: 3.12.12 (main, Oct 14 2025, 21:25:31) [Clang 20.1.4 ]

Package Information

langchain_core: 1.0.4
langchain: 1.0.5
langchain_community: 0.4.1
langsmith: 0.4.42
langchain_classic: 1.0.0
langchain_ibm: 1.0.1
langchain_mcp_adapters: 0.1.13
langchain_openai: 1.0.2
langchain_text_splitters: 1.0.0
langgraph_sdk: 0.2.9

Originally created by @Kirushikesh on GitHub (Nov 28, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/). - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python from langchain.tools import tool from langchain.agents import create_agent from langchain.agents import AgentState from langchain_core.tools import InjectedToolCallId, tool from langgraph.prebuilt import InjectedState class State1(AgentState): information: str class State2(AgentState): information: str class State3(AgentState): information: str @tool def get_temperature(query: str, state: Annotated[State2, InjectedState], tool_call_id: Annotated[str, InjectedToolCallId])-> str: "This returns the temperature of a location at this moment" result = temperature_agent.invoke({ "messages": [{"role": "user", "content": query}] }) return result["messages"][-1].content @tool def get_temperature_celcius(location: str, state: Annotated[State3, InjectedState], tool_call_id: Annotated[str, InjectedToolCallId])-> str: "This returns the temperature of a location at this moment in celcius" return "25 degree celcius" @tool def get_temperature_farenhite(location: str, state: Annotated[State3, InjectedState], tool_call_id: Annotated[str, InjectedToolCallId])-> str: "This returns the temperature of a location at this moment in farenhite" return "25 degree farenhite" @tool def get_location(state: Annotated[State1, InjectedState], tool_call_id: Annotated[str, InjectedToolCallId])-> str: "This returns the current location of the user" return "new delhi" @tool( "subagent1_name", description="subagent1_description" ) def call_subagent1(query: str, state: Annotated[State1, InjectedState], tool_call_id: Annotated[str, InjectedToolCallId]): result = subagent1.invoke({ "messages": [{"role": "user", "content": query}] }) return result["messages"][-1].content agent = create_agent( model=model, tools=[call_subagent1, get_location], state_schema=State1, response_format=Handover, ) subagent1 = create_agent( model=model, tools=[get_temperature], state_schema=State2 ) temperature_agent = create_agent( model=model, tools=[get_temperature_celcius,get_temperature_farenhite], state_schema=State3 ) from IPython.display import Image, display display(Image(agent.get_graph(xray=True).draw_mermaid_png())) ``` ### Error Message and Stack Trace (if applicable) ```shell ``` ### Description I am just building the supervisor agent pattern for my use case, where the top-level supervisor is to return the output in a structured format. I am seeing two issues, 1) There is a weird arrow that goes and comes back to the same agent. 2) As we are encapsulating the agent(s) inside the tool definition for the supervisor agent, is it possible to support/extend visualisation for that too? <img width="209" height="333" alt="Image" src="https://github.com/user-attachments/assets/a1947963-3827-4adf-9cbb-cc090d6cb829" /> ### System Info System Information ------------------ > OS: Linux > OS Version: #1 SMP PREEMPT_DYNAMIC Fri Aug 9 14:06:03 EDT 2024 > Python Version: 3.12.12 (main, Oct 14 2025, 21:25:31) [Clang 20.1.4 ] Package Information ------------------- > langchain_core: 1.0.4 > langchain: 1.0.5 > langchain_community: 0.4.1 > langsmith: 0.4.42 > langchain_classic: 1.0.0 > langchain_ibm: 1.0.1 > langchain_mcp_adapters: 0.1.13 > langchain_openai: 1.0.2 > langchain_text_splitters: 1.0.0 > langgraph_sdk: 0.2.9
yindo added the bugpending labels 2026-02-20 17:42:58 -05:00
yindo closed this issue 2026-02-20 17:42:59 -05:00
Author
Owner

@sydney-runkle commented on GitHub (Jan 9, 2026):

  1. the self loop is actually intentional, if structured output via tool calling is used. if the validation of the structured output fails, we want to be able to jump back to the model and retry!
  2. right now there's no way to visualize the subgraph w/in the tool -- this is difficult bc you'd want to be able to visualize a multitude of agent subgraphs...

going to close for now - we have some other issues open covering devx for subgraph tracing + viz that I think cover your request 👍

@sydney-runkle commented on GitHub (Jan 9, 2026): 1. the self loop is actually intentional, if structured output via tool calling is used. if the validation of the structured output fails, we want to be able to jump back to the model and retry! 2. right now there's no way to visualize the subgraph w/in the tool -- this is difficult bc you'd want to be able to visualize a multitude of agent subgraphs... going to close for now - we have some other issues open covering devx for subgraph tracing + viz that I think cover your request 👍
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#1075