Skip to content

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

@himadri-bhattacharjee

Description

@himadri-bhattacharjee

Component: Langchain Instrumentation

Description:

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

Steps to Reproduce:

  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

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

Environment:

  • opentelemetry-instrumentation-langchain: 0.53.3 (upto v0.57.0)
  • langgraph-prebuilt: 1.0.8
  • langgraph-supervisor: latest
  • Python: 3.13

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