langchain-ai/langgraph · error · ValueError

No messages found in input state to tool_edge

Error message

No messages found in input state to tool_edge: {state}

What it means

Guard in tools_condition: the router could not read any messages from the state via the configured messages_key (neither dict key nor attribute). It runs after the model node to decide 'tools' vs 'end', and without messages it cannot inspect the last AIMessage for tool calls.

Solutions

  1. Ensure the state passed to the conditional edge contains the messages key (default 'messages')
  2. Pass the matching messages_key to tools_condition if your schema uses a different field name
  3. Wire the edge from the agent node so state always includes model output messages
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at libs/prebuilt/langgraph/prebuilt/tool_node.py:1656 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/a06db3132f3a6eb0. Report an issue: GitHub.

Appendix: source

Thrown at libs/prebuilt/langgraph/prebuilt/tool_node.py:1656

        def custom_condition(state):
            return tools_condition(state, messages_key="chat_history")
        ```

    !!! note
        This function is designed to work seamlessly with `ToolNode` and standard
        LangGraph patterns. It expects the last message to be an `AIMessage` when
        tool calls are present, which is the standard output format for tool-calling
        language models.
    """
    if isinstance(state, list):
        ai_message = state[-1]
    elif (isinstance(state, dict) and (messages := state.get(messages_key, []))) or (
        messages := getattr(state, messages_key, [])
    ):
        ai_message = messages[-1]
    else:
        msg = f"No messages found in input state to tool_edge: {state}"
        raise ValueError(msg)
    if hasattr(ai_message, "tool_calls") and len(ai_message.tool_calls) > 0:
        return "tools"
    return "__end__"


@dataclass
class ToolRuntime(_DirectlyInjectedToolArg, Generic[ContextT, StateT]):
    """Runtime context automatically injected into tools.

    !!! note

        This is distinct from `Runtime` (from `langgraph.runtime`), which is injected
        into graph nodes and middleware. `ToolRuntime` includes additional tool-specific
        attributes like `config`, `state`, and `tool_call_id` that `Runtime` does not
        have.

    When a tool function has a parameter named `runtime` with type hint
    `ToolRuntime`, the tool execution system will automatically inject an instance

View on GitHub (pinned to 38031739e5)