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
importrandomfromlanggraph.graphimportSTART, StateGraphfromlanggraph.typesimportCommandfromtyping_extensionsimportLiteral, TypedDict# Define graph stateclassState(TypedDict):
foo: str# Define the nodesclassMyGraph:
defnode_a(self, state: State) ->Command[Literal["node_b", "node_c"]]:
print("Called A")
value=random.choice(["a", "b"])
# this is a replacement for a conditional edge functionifvalue=="a":
goto="node_b"else:
goto="node_c"# note how Command allows you to BOTH update the graph state AND route to the next nodereturnCommand(
# this is the state updateupdate={"foo": value},
# this is a replacement for an edgegoto=goto,
)
# Nodes B and C are unchangeddefnode_b(self, state: State):
print("Called B")
return {"foo": state["foo"] +"b"}
defnode_c(self, state: State):
print("Called C")
return {"foo": state["foo"] +"c"}
defbuild_graph(self):
builder=StateGraph(State)
builder.add_edge(START, "node_a")
builder.add_node("node_a", self.node_a)
builder.add_node("node_b", self.node_b)
builder.add_node("node_c", self.node_c)
# NOTE: there are no edges between nodes A, B and C!graph=builder.compile()
returngraphfromIPython.displayimportdisplay, Imagegraph=MyGraph().build_graph()
display(Image(graph.get_graph().draw_mermaid_png()))
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
No response
Description
When using command inside a class the edges are not rendered. It works if nodes are outside (or probably if static methods?)
I adapted this code: https://langchain-ai.github.io/langgraph/how-tos/command/#define-graph
And the generated graph is this:
System Info
langgraph version 0.2.61
The text was updated successfully, but these errors were encountered: