Skip to content

🐛 Bug Report: TypeError: 'ToolNode' object is not iterable in patch.py when using langgraph-supervisor with create_react_agent #3841

@soumen-eric

Description

@soumen-eric

Which component is this bug for?

Langchain Instrumentation

📜 Description

opentelemetry-instrumentation-langchain v0.53.x crashes when langgraph-supervisor's create_supervisor() passes a ToolNode object to
create_react_agent. The instrumentation's monkey-patch in patch.py (line 489) assumes tools is always an iterable list, but ToolNode is not
iterable.

Environment:

  • opentelemetry-instrumentation-langchain: 0.53.3
  • langgraph-prebuilt: 1.0.8
  • langgraph-supervisor: latest
  • Python: 3.13

👟 Reproduction steps

  1. Install opentelemetry-instrumentation-langchain==0.53.3 with langgraph-supervisor
  2. Create a supervisor using create_supervisor() which internally calls create_react_agent with a ToolNode object
  3. Application crashes on startup

Error:
File "/usr/local/lib/python3.13/site-packages/opentelemetry/instrumentation/langchain/patch.py", line 489, in wrapper
for tool in tools:
^^^^^
TypeError: 'ToolNode' object is not iterable

👍 Expected behavior

Should work

👎 Actual Behavior with Screenshots

NA

🤖 Python Version

3.13

📃 Provide any additional context for the Bug.

Root Cause:

In patch.py lines 484-492:
python
tools = kwargs.get("tools")
if tools is None and len(args) > 1:
tools = args[1]
if tools:
tool_definitions = []
for tool in tools: # <-- ToolNode is not iterable
tool_def = _extract_tool_definition(tool)

ToolNode is a LangGraph class that wraps tools but is not itself iterable. It exposes tools via tools_by_name attribute.

Suggested Fix:

python
if tools:
tool_definitions = []
_tools_iter = tools.tools_by_name.values() if hasattr(tools, 'tools_by_name') else tools
for tool in _tools_iter:

Workaround: Pin to opentelemetry-instrumentation-langchain==0.52.6

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions