Skip to content

prebuilt==1.0.5 breaks create_react_agent when passing a list of BaseTool #6477

@grahonan

Description

@grahonan

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

"""
Demo script showing bug in langgraph-prebuilt==1.0.5
"""

from langchain_community.vectorstores import FAISS
from langchain_openai import OpenAIEmbeddings
from langchain_core.documents import Document
from langchain_core.tools.retriever import create_retriever_tool
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from langchain_core.runnables import RunnableConfig
from langchain_core.messages import HumanMessage

# Create sample documents for the vector store
documents = [
    Document(
        page_content="The Colosseum in Rome is an iconic ancient amphitheater built in 70-80 AD. It could hold up to 80,000 spectators and was used for gladiatorial contests and public spectacles.",
        metadata={"source": "colosseum_info", "title": "The Colosseum"}
    ),
    Document(
        page_content="The Leaning Tower of Pisa is a freestanding bell tower located in Pisa. Construction began in 1173 and the tower is famous for its unintended tilt caused by soft ground.",
        metadata={"source": "pisa_tower", "title": "Leaning Tower of Pisa"}
    ),
    Document(
        page_content="The Trevi Fountain in Rome is the largest Baroque fountain in the city. Completed in 1762, tradition says throwing a coin into the fountain ensures a return to Rome.",
        metadata={"source": "trevi_fountain", "title": "Trevi Fountain"}
    ),
]

# Create embeddings and vector store
print("Creating vector store with embeddings...")
embeddings = OpenAIEmbeddings()
vectorstore = FAISS.from_documents(documents, embeddings)

# Create a VectorStoreRetriever
print("Creating VectorStoreRetriever...")
retriever = vectorstore.as_retriever(
    search_type="similarity",
    search_kwargs={"k": 3}  # Return top 3 most relevant documents
)

# Create a retrieval tool using create_retrieval_tool
print("Creating retrieval tool...")
retrieval_tool = create_retriever_tool(
    retriever=retriever,
    name="italian_monument_knowledge_base",
    description="Searches and returns information about monuments in Italy."
)

# Initialize the LLM
print("Initializing LLM...")
llm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo")

# Create the ReAct agent with the retrieval tool
print("Creating ReAct agent...")
tools = [retrieval_tool]
agent = create_react_agent(
    llm,
    tools=tools,
)

runnable = RunnableConfig(
    callbacks=None,
    configurable={"thread_id": "thread-id"},
)

# Ask questions using the agent
print("\n" + "="*80)
print("ASKING QUESTION TO THE AGENT")
print("="*80 + "\n")

questions = [
    "Tell me about the Colosseum in Rome.",
    "When was the Leaning Tower of Pisa built?",
    "What is the tradition associated with the Trevi Fountain?"
]

for question in questions:
    print(f"\n{'='*80}")
    print(f"Question: {question}")
    print(f"{'='*80}\n")
    messages = [HumanMessage(content=question)]
    try:
        response = agent.invoke({"messages": messages}, config=runnable)
        print(f"\nFinal Answer: {response["messages"][-1].content}\n")
    except Exception as e:
        print(f"Error: {e}\n")

print("\n" + "="*80)
print("DEMO COMPLETE")
print("="*80)

Error Message and Stack Trace (if applicable)

$ python ../demo_retrieval_agent.py
Creating vector store with embeddings...
Creating VectorStoreRetriever...
Creating retrieval tool...
Initializing LLM...
Creating ReAct agent...
/Users/grayson/Documents/connext-bot-git/connext-bot/../demo_retrieval_agent.py:57: LangGraphDeprecatedSinceV10: create_react_agent has been moved to `langchain.agents`. Please update your import to `from langchain.agents import create_agent`. Deprecated in LangGraph V1.0 to be removed in V2.0.
  agent = create_react_agent(
Traceback (most recent call last):
  File "/Users/grayson/Documents/connext-bot-git/connext-bot/../demo_retrieval_agent.py", line 57, in <module>
    agent = create_react_agent(
            ^^^^^^^^^^^^^^^^^^^
  File "/Users/grayson/Documents/connext-bot-git/venv/lib/python3.12/site-packages/typing_extensions.py", line 3004, in wrapper
    return arg(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/grayson/Documents/connext-bot-git/venv/lib/python3.12/site-packages/langgraph/prebuilt/chat_agent_executor.py", line 549, in create_react_agent
    tool_node = ToolNode([t for t in tools if not isinstance(t, dict)])
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/grayson/Documents/connext-bot-git/venv/lib/python3.12/site-packages/langgraph/prebuilt/tool_node.py", line 766, in __init__
    self._injected_args[tool_.name] = _get_all_injected_args(tool_)
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/grayson/Documents/connext-bot-git/venv/lib/python3.12/site-packages/langgraph/prebuilt/tool_node.py", line 1801, in _get_all_injected_args
    func_annotations = get_type_hints(func, include_extras=True) if func else {}
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/typing.py", line 2300, in get_type_hints
    raise TypeError('{!r} is not a module, class, method, '
TypeError: functools.partial(<function _get_relevant_documents at 0x13a72d4e0>, retriever=VectorStoreRetriever(tags=['FAISS', 'OpenAIEmbeddings'], vectorstore=<langchain_community.vectorstores.faiss.FAISS object at 0x13c4b3020>, search_kwargs={'k': 3}), document_prompt=PromptTemplate(input_variables=['page_content'], input_types={}, partial_variables={}, template='{page_content}'), document_separator='\n\n', response_format='content') is not a module, class, method, or function.

Description

prebuilt==1.0.5 introduces a bug for users of create_react_agent. create_react_agent fails when passing in a list of BaseTools with the stack trace shown.

The attached reproducer code will fail with the stack trace shown with langgraph-prebuilt==1.0.5 and the packages below:

langchain                     1.0.7
langchain-classic             1.0.0
langchain-community           0.4.1
langchain-core                1.0.5
langchain-google-community    3.0.1
langchain-ollama              1.0.0
langchain-openai              1.0.3
langchain-text-splitters      1.0.0
langdetect                    1.0.9
langgraph                     1.0.3
langgraph-checkpoint          3.0.1
langgraph-prebuilt            1.0.5
langgraph-sdk                 0.2.9
langsmith                     0.4.45

If you run pip install langgraph-prebuilt==1.0.4 and re-run the reproducer code, it will run without errors.

$ pip install langgraph-prebuilt==1.0.4
Collecting langgraph-prebuilt==1.0.4
[...]
      Successfully uninstalled langgraph-prebuilt-1.0.5
Successfully installed langgraph-prebuilt-1.0.4

$ python ../demo_retrieval_agent.py
Creating vector store with embeddings...
Creating VectorStoreRetriever...
Creating retrieval tool...
Initializing LLM...
Creating ReAct agent...
/Users/grayson/Documents/connext-bot-git/connext-bot/../demo_retrieval_agent.py:58: LangGraphDeprecatedSinceV10: create_react_agent has been moved to `langchain.agents`. Please update your import to `from langchain.agents import create_agent`. Deprecated in LangGraph V1.0 to be removed in V2.0.
  agent = create_react_agent(

================================================================================
ASKING QUESTION TO THE AGENT
================================================================================


================================================================================
Question: Tell me about the Colosseum in Rome.
================================================================================
[...]

Final Answer: The tradition associated with the Trevi Fountain in Rome is that if you throw a coin into the fountain, it ensures your return to Rome.


================================================================================
DEMO COMPLETE
================================================================================

System Info

$ python -m langchain_core.sys_info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 24.6.0: Wed Oct 15 21:12:06 PDT 2025; root:xnu-11417.140.69.703.14~1/RELEASE_ARM64_T6000
Python Version: 3.12.9 (v3.12.9:fdb81425a9a, Feb 4 2025, 12:21:36) [Clang 13.0.0 (clang-1300.0.29.30)]

Package Information

langchain_core: 1.0.5
langchain: 1.0.7
langchain_community: 0.4.1
langsmith: 0.4.45
langchain_classic: 1.0.0
langchain_google_community: 3.0.1
langchain_ollama: 1.0.0
langchain_openai: 1.0.3
langchain_text_splitters: 1.0.0
langgraph_sdk: 0.2.9

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.12.13
beautifulsoup4: 4.12.3
dataclasses-json: 0.6.7
google-api-core: 2.28.1
google-api-python-client: 2.163.0
google-auth: 2.43.0
google-auth-httplib2: 0.2.0
google-auth-oauthlib: 1.2.1
google-cloud-core: 2.5.0
google-cloud-modelarmor: 0.3.0
grpcio: 1.76.0
httpx: 0.27.2
httpx-sse: 0.4.3
jsonpatch: 1.33
langgraph: 1.0.3
numpy: 2.2.6
ollama: 0.6.1
openai: 2.8.1
orjson: 3.11.4
packaging: 24.2
pandas: 2.3.0
pyarrow: 22.0.0
pydantic: 2.10.3
pydantic-settings: 2.12.0
pytest: 8.3.4
PyYAML: 6.0.3
pyyaml: 6.0.3
requests: 2.32.5
requests-toolbelt: 1.0.0
rich: 13.9.4
sqlalchemy: 2.0.44
SQLAlchemy: 2.0.44
tenacity: 9.1.2
tiktoken: 0.11.0
typing-extensions: 4.15.0
zstandard: 0.25.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpendingawaiting review/confirmation by maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions