Hi LangGraph team,
I am encountering a persistent KeyError: '__end__' when running a workflow that uses the recommended END constant for terminal transitions. The error occurs inside the library, specifically at:
File ".../langgraph/graph/_branch.py", line 205, in _finish
r if isinstance(r, Send) else self.ends[r] for r in result
KeyError: '__end__'
Minimal reproducible example:
from langgraph.graph import StateGraph, END
def node_a(state):
return state
def router(state):
return END
workflow = StateGraph(dict)
workflow.add_node("a", node_a)
workflow.set_entry_point("a")
workflow.add_conditional_edges("a", router, {})
workflow.add_edge("a", END)
app = workflow.compile()
for state in app.stream({"input": "test"}):
print(state)
Expected behavior:
The workflow should terminate cleanly when returning END, without raising a KeyError.
Actual behavior:
A KeyError: '__end__' is raised inside the library.
Environment:
- LangGraph version: (e.g., 0.6.8, 0.6.10, latest)
- Python version: (your version)
- OS: (your OS)
Additional context:
- I have tried both the latest and previous versions.
- The error occurs regardless of the workflow complexity.
- The issue appears to be internal to LangGraph’s handling of the END state.
Please advise if there is a workaround or if a fix is planned. Thank you!
