Skip to content

Why Branching requires Annotation in state in LangGraph #596

Answered by hinthornw
arvindkrbhatt asked this question in Q&A
Discussion options

You must be logged in to vote

This is a great question! I'll try to update our docs in a couple places to better explain this, since it does seem non-obvious.

The short answer is that in general annotations of state keys (aka channels) define reducers, reducers let the graph know how to apply an update to the state. By default we don't really know the preferred way and so overwrite any channel when it is present in an update.

If no reducer is provided, and the graph has no branching, this is OK, since there is only ever one update to be applied in a given superstep.

However if there is branching, the update becomes undefined, since the StateGraph contract does not guarantee an ordering of the updates - if both branche…

Replies: 5 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by hwchase17
Comment options

You must be logged in to vote
1 reply
@hinthornw
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants