Why can't I decide which node to navigate to at runtime based on the value of state? #287

Closed
opened 2026-02-20 17:35:16 -05:00 by yindo · 3 comments
Owner

Originally created by @teatimekon on GitHub (Oct 21, 2024).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph/LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph/LangChain rather than my code.
  • I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

#This is my route funciton:
def route_to_agent(self,state):
        if not state["next_agent"]: 
            return self.entry_agent_node
        last_message = state["messages"][-1]
        if isinstance(last_message,AIMessage):
            return END
        return state["next_agent"]

#This how I define conditional edges  
self.graph.add_conditional_edges(
            START,
            self.route_to_agent,
            {agent.name: agent.name for agent in self.agent_factory.get_all_agents().values()}
        )
for agent in self.agent_factory.get_all_agents().values():
    self.graph.add_conditional_edges(
        agent.name,
        self.route_to_agent,
        {next_agent: next_agent for next_agent in agent.next_agents}
    )

Error Message and Stack Trace (if applicable)

No response

Description

how can I define rightly?

System Info

raceback (most recent call last):
File "/Users/zuoyuxuan/Documents/Code/QINIU/agent_flow/swarm_workflow.py", line 47, in
graph = graph.compile(checkpointer=memory)
File "/Users/zuoyuxuan/anaconda3/envs/agent_flow/lib/python3.10/site-packages/langgraph/graph/state.py", line 430, in compile
self.validate(
File "/Users/zuoyuxuan/anaconda3/envs/agent_flow/lib/python3.10/site-packages/langgraph/graph/graph.py", line 396, in validate
raise ValueError(f"Found edge ending at unknown node {target}")
ValueError: Found edge ending at unknown node None

Originally created by @teatimekon on GitHub (Oct 21, 2024). ### Checked other resources - [X] I added a very descriptive title to this issue. - [X] I searched the [LangGraph](https://langchain-ai.github.io/langgraph/)/LangChain documentation with the integrated search. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I am sure that this is a bug in LangGraph/LangChain rather than my code. - [X] I am sure this is better as an issue [rather than a GitHub discussion](https://github.com/langchain-ai/langgraph/discussions/new/choose), since this is a LangGraph bug and not a design question. ### Example Code ```python #This is my route funciton: def route_to_agent(self,state): if not state["next_agent"]: return self.entry_agent_node last_message = state["messages"][-1] if isinstance(last_message,AIMessage): return END return state["next_agent"] #This how I define conditional edges self.graph.add_conditional_edges( START, self.route_to_agent, {agent.name: agent.name for agent in self.agent_factory.get_all_agents().values()} ) for agent in self.agent_factory.get_all_agents().values(): self.graph.add_conditional_edges( agent.name, self.route_to_agent, {next_agent: next_agent for next_agent in agent.next_agents} ) ``` ### Error Message and Stack Trace (if applicable) _No response_ ### Description how can I define rightly? ### System Info raceback (most recent call last): File "/Users/zuoyuxuan/Documents/Code/QINIU/agent_flow/swarm_workflow.py", line 47, in <module> graph = graph.compile(checkpointer=memory) File "/Users/zuoyuxuan/anaconda3/envs/agent_flow/lib/python3.10/site-packages/langgraph/graph/state.py", line 430, in compile self.validate( File "/Users/zuoyuxuan/anaconda3/envs/agent_flow/lib/python3.10/site-packages/langgraph/graph/graph.py", line 396, in validate raise ValueError(f"Found edge ending at unknown node `{target}`") ValueError: Found edge ending at unknown node `None`
yindo closed this issue 2026-02-20 17:35:16 -05:00
Author
Owner

@vbarda commented on GitHub (Oct 21, 2024):

@teatimekon the error you're seeing suggests that somewhere in your code you're adding edge like this: graph.add_edge("node", None). please provide a full reproducible example

@vbarda commented on GitHub (Oct 21, 2024): @teatimekon the error you're seeing suggests that somewhere in your code you're adding edge like this: `graph.add_edge("node", None)`. please provide a full reproducible example
Author
Owner

@teatimekon commented on GitHub (Oct 21, 2024):

@teatimekon the error you're seeing suggests that somewhere in your code you're adding edge like this: graph.add_edge("node", None). please provide a full reproducible example

thank you!I just find one tiny mistake in my code ! sry to bother you

@teatimekon commented on GitHub (Oct 21, 2024): > @teatimekon the error you're seeing suggests that somewhere in your code you're adding edge like this: `graph.add_edge("node", None)`. please provide a full reproducible example thank you!I just find one tiny mistake in my code ! sry to bother you
Author
Owner

@vbarda commented on GitHub (Oct 21, 2024):

@teatimekon no problem -- glad you resolved it!

@vbarda commented on GitHub (Oct 21, 2024): @teatimekon no problem -- glad you resolved it!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#287