langchain-ai/langgraph · error · ValueError

Must specify non-null arguments for both 'left' and…

Error message

Must specify non-null arguments for both 'left' and 'right'. Only received: '{'left' if left else 'right'}'.

What it means

Raised by the _add_messages wrapper when only one of `left`/`right` is provided. The reducer semantics require both the existing messages (left) and the incoming messages (right) to merge; passing just one is a caller error, typically from invoking add_messages directly.

Solutions

  1. Pass both existing and new messages: add_messages(left, right)
  2. If one side is genuinely empty, pass an empty list [] rather than None
  3. In state annotations, let the graph invoke the reducer automatically instead of calling it manually
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at libs/langgraph/langgraph/graph/message.py:52 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of langchain-ai/langgraph@38031739e5 (2026-08-26). Data as JSON: /api/errors/e78c5b0599d44dda. Report an issue: GitHub.

Appendix: source

Thrown at libs/langgraph/langgraph/graph/message.py:52

)

Messages = list[MessageLikeRepresentation] | MessageLikeRepresentation

REMOVE_ALL_MESSAGES = "__remove_all__"


def _add_messages_wrapper(func: Callable) -> Callable[[Messages, Messages], Messages]:
    def _add_messages(
        left: Messages | None = None, right: Messages | None = None, **kwargs: Any
    ) -> Messages | Callable[[Messages, Messages], Messages]:
        if left is not None and right is not None:
            return func(left, right, **kwargs)
        elif left is not None or right is not None:
            msg = (
                f"Must specify non-null arguments for both 'left' and 'right'. Only "
                f"received: '{'left' if left else 'right'}'."
            )
            raise ValueError(msg)
        else:
            return partial(func, **kwargs)

    _add_messages.__doc__ = func.__doc__
    return cast(Callable[[Messages, Messages], Messages], _add_messages)


@_add_messages_wrapper
def add_messages(
    left: Messages,
    right: Messages,
    *,
    format: Literal["langchain-openai"] | None = None,
) -> Messages:
    """Merges two lists of messages, updating existing messages by ID.

    By default, this ensures the state is "append-only", unless the
    new message has the same ID as an existing message.

View on GitHub (pinned to 38031739e5)