Skip to content

cannot import ToolNode from Langgraph #944

Description

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph/LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph/LangChain rather than my code.
  • I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

from langchain_core.runnables import RunnableLambda, RunnableWithFallbacks
from langgraph.prebuilt import ToolNode


def create_tool_node_with_fallback(tools: list) -> RunnableWithFallbacks[Any, dict]:
    """
    Create a ToolNode with a fallback to handle errors and surface them to the agent.
    """
    return ToolNode(tools).with_fallbacks(
        [RunnableLambda(handle_tool_error)], exception_key="error"
    )

Error Message and Stack Trace (if applicable)

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[66], line 2
      1 from langchain_core.runnables import RunnableLambda, RunnableWithFallbacks
----> 2 from langgraph.prebuilt import ToolNode
      5 def create_tool_node_with_fallback(tools: list) -> RunnableWithFallbacks[Any, dict]:
      6     """
      7     Create a ToolNode with a fallback to handle errors and surface them to the agent.
      8     """

ImportError: cannot import name 'ToolNode' from 'langgraph.prebuilt' (/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/langgraph/prebuilt/__init__.py)

Description

I am getting this error today, when I was able to execute it before

System Info

from langgraph.prebuilt import ToolNode

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions