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
In the section "Setting the order of state updates" you told that we want to control the ordering within each step, and you use sorting_reducer for it. But as I understand this reducer will sort all the steps in the graph globally. The easy way to check it is to rename node a to node z and re-execute the same code:
defsorting_reducer(left, right):
""" Combines and sorts the values in a list"""ifnotisinstance(left, list):
left= [left]
ifnotisinstance(right, list):
right= [right]
returnsorted(left+right, reverse=False)
classState(TypedDict):
# sorting_reducer will sort the values in statestate: Annotated[list, sorting_reducer]
# Add nodesbuilder=StateGraph(State)
# Initialize each node with node_secret builder.add_node("z", ReturnNodeValue("I'm Z"))
builder.add_node("b", ReturnNodeValue("I'm B"))
builder.add_node("b2", ReturnNodeValue("I'm B2"))
builder.add_node("c", ReturnNodeValue("I'm C"))
builder.add_node("d", ReturnNodeValue("I'm D"))
# Flowbuilder.add_edge(START, "z")
builder.add_edge("z", "b")
builder.add_edge("z", "c")
builder.add_edge("b", "b2")
builder.add_edge(["b2", "c"], "d")
builder.add_edge("d", END)
graph=builder.compile()
graph.invoke({"state": []})
Then you will see that after each super-step we will get the list of all steps sorted globally:
Adding I'm Z to []Adding I'm B to ["I'm Z"]
Adding I'm C to ["I'm Z"]Adding I'm B2 to ["I'm B", "I'm C", "I'm Z"]Adding I'm D to ["I'm B", "I'm B2", "I'm C", "I'm Z"]
{'state': ["I'm B", "I'm B2", "I'm C", "I'm D", "I'm Z"]}
Maybe the more correct way to do what you describe as the goal of this section is to implement the method similar to the example from LangGraph documentation, where you use additional sink node after super-step with multiple sub-steps and change the order of sub-steps in this sink node.
Thank you.
The text was updated successfully, but these errors were encountered:
Hi @rlancemartin,
In the section "Setting the order of state updates" you told that we want to control the ordering within each step, and you use
sorting_reducer
for it. But as I understand this reducer will sort all the steps in the graph globally. The easy way to check it is to rename nodea
to nodez
and re-execute the same code:Then you will see that after each super-step we will get the list of all steps sorted globally:
Maybe the more correct way to do what you describe as the goal of this section is to implement the method similar to the example from LangGraph documentation, where you use additional sink node after super-step with multiple sub-steps and change the order of sub-steps in this sink node.
Thank you.
The text was updated successfully, but these errors were encountered: