You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
fromenumimportEnumfromlangchain_core.messagesimportHumanMessagefromlanggraph.graphimportStateGraph, START, ENDfromlanggraph.prebuiltimportcreate_react_agentfromtypingimportLiteralfromtyping_extensionsimportTypedDictfromlangchain_openaiimportChatOpenAIfromlanggraph.graphimportMessagesState, ENDfromlanggraph.typesimportCommandclassMembers(Enum):
researcher="researcher"coder="coder"members= [Members.researcher, Members.coder]
# Our team supervisor is an LLM node. It just picks the next agent to process# and decides when the work is completedoptions=members+ ["FINISH"]
system_prompt= (
"You are a supervisor tasked with managing a conversation between the"f" following workers: {members}. Given the following user request,"" respond with the worker to act next. Each worker will perform a"" task and respond with their results and status. When finished,"" respond with FINISH."
)
classRouter(TypedDict):
"""Worker to route to next. If no workers needed, route to FINISH."""next: Literal[*options]
llm=ChatOpenAI(model="gpt-4o")
defsupervisor_node(state: MessagesState) ->Command[Literal[*members, "__end__"]]:
messages= [
{"role": "system", "content": system_prompt},
] +state["messages"]
response=llm.with_structured_output(Router).invoke(messages)
goto=response["next"]
ifgoto=="FINISH":
goto=ENDreturnCommand(goto=goto)
research_agent=create_react_agent(
llm, tools=[], state_modifier="You are a researcher. DO NOT do any math."
)
defresearch_node(state: MessagesState) ->Command[Literal["supervisor"]]:
result=research_agent.invoke(state)
returnCommand(
update={
"messages": [
HumanMessage(content=result["messages"][-1].content, name="researcher")
]
},
goto="supervisor",
)
# NOTE: THIS PERFORMS ARBITRARY CODE EXECUTION, WHICH CAN BE UNSAFE WHEN NOT SANDBOXEDcode_agent=create_react_agent(llm, tools=[])
defcode_node(state: MessagesState) ->Command[Literal["supervisor"]]:
result=code_agent.invoke(state)
returnCommand(
update={
"messages": [
HumanMessage(content=result["messages"][-1].content, name="coder")
]
},
goto="supervisor",
)
builder=StateGraph(MessagesState)
builder.add_edge(START, "supervisor")
builder.add_node("supervisor", supervisor_node)
builder.add_node("researcher", research_node)
builder.add_node("coder", code_node)
graph=builder.compile()
Error Message and Stack Trace (if applicable)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[4], line 90
88 builder.add_node("researcher", research_node)
89 builder.add_node("coder", code_node)
---> 90 graph = builder.compile()
File ~/projects/ditto/poc/assignments/venv/lib/python3.11/site-packages/langgraph/graph/state.py:510, in StateGraph.compile(self, checkpointer, store, interrupt_before, interrupt_after, debug)
507 interrupt_after = interrupt_after or []
509 # validate the graph
--> 510 self.validate(
511 interrupt=(
512 (interrupt_before if interrupt_before != "*"else []) + interrupt_after
513 if interrupt_after != "*"
514 else []
515 )
516 )
518 # prepare output channels
519 output_channels = (
520 "__root__"
521 if len(self.schemas[self.output]) == 1
(...)
527 ]
528 )
File ~/projects/ditto/poc/assignments/venv/lib/python3.11/site-packages/langgraph/graph/graph.py:405, in Graph.validate(self, interrupt)
403 fortargetin all_targets:
404 if target not in self.nodes and target != END:
--> 405 raise ValueError(f"Found edge ending at unknown node `{target}`")
406 # validate interrupts
407 if interrupt:
ValueError: Found edge ending at unknown node `Members.coder`
Description
I'm trying to use an Enum for my node/agent names to make the code more maintainable, but it seems the graph is looking for a node with the actual name of the enum variable not the value.
System Info
System Information
OS: Darwin
OS Version: Darwin Kernel Version 22.5.0: Mon Apr 24 20:51:50 PDT 2023; root:xnu-8796.121.2~5/RELEASE_X86_64
Python Version: 3.11.6 (v3.11.6:8b6ee5ba3b, Oct 2 2023, 11:18:21) [Clang 13.0.0 (clang-1300.0.29.30)]
hm, i can't reproduce the exact issue you're running, but i would recommend using StrEnum instead of Enum. if you still want to use enums. let me know if this resolves it
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
Description
I'm trying to use an Enum for my node/agent names to make the code more maintainable, but it seems the graph is looking for a node with the actual name of the enum variable not the value.
System Info
System Information
Package Information
Optional packages not installed
Other Dependencies
The text was updated successfully, but these errors were encountered: