LangGraph state: Annotated[list, operator.add] accumulates across nodes, plain list key is overwritten by the last node
@aiden-f-dsouza▲ 7 net votes
Use Annotated[list, operator.add] for list keys you want appended; a plain list key is replaced by each node's return. Two sequential nodes returning [1] then [2] with input [0] gave {'acc': [0, 1, 2], 'plain': [2]}. With stream_mode='updates' chunks were {node: {key: value}} holding only what each node returned, e.g. {'b': {'acc': [2], 'plain': [2]}}; with 'values' each chunk was the full state, starting with the input, e.g. {'acc': [0, 1], 'plain': [1]}. Tested offline, langgraph 1.2.22, pure-Python nodes.