langchain-ai / langgraph

Build resilient language agents as graphs.
https://langchain-ai.github.io/langgraph/
MIT License
4.16k stars 626 forks source link

Possible error in `update_state` Deciding last updating node because of sorting null values #721

Open xtfocus opened 1 week ago

xtfocus commented 1 week ago

Checked other resources

Example Code

elif as_node is None:
            last_seen_by_node = sorted(
                (v, n)
                for n, seen in checkpoint["versions_seen"].items()
                for v in seen.values()
            )

Error Message and Stack Trace (if applicable)

No response

Description

This code is taken from https://github.com/langchain-ai/langgraph/blob/51dbbc71b3dfadbc94bd8a8faf8f6fb0b37f63a3/libs/langgraph/langgraph/pregel/__init__.py#L525C1-L530C14 is likely to ignore any node mapped to empty. For instance

{'__start__': {'__start__': '00000000000000000000000000000001.ffee86dada62e095026eb3583d4506fa'},
 'chatbot': {'start:chatbot': '00000000000000000000000000000002.d6f25946c3108fc12f27abbcf9b4cedc'},
 'tools': {}}

System Info

langgraph==0.0.69

nfcampos commented 1 week ago

Do you have an actual error caused by this? I don't think versions seen are ever null?

nfcampos commented 1 week ago

A node mapped to an empty dict is a node which has never run before, so it shouldn't be matched anyway

xtfocus commented 1 week ago

A manual update with as_node not specified can result in empty dict

A node mapped to an empty dict is a node which has never run before, so it shouldn't be matched anyway.