Skip to content

fix(langchain): handle ToolNode in create_react_agent tool iteration#4081

Open
dvirski wants to merge 1 commit intomainfrom
fix(langchain)-handle-ToolNode-in-create_react_agent-tool-iteration
Open

fix(langchain): handle ToolNode in create_react_agent tool iteration#4081
dvirski wants to merge 1 commit intomainfrom
fix(langchain)-handle-ToolNode-in-create_react_agent-tool-iteration

Conversation

@dvirski
Copy link
Copy Markdown

@dvirski dvirski commented May 6, 2026

Fixes #3841 — TypeError: ToolNode object is not iterable when using langgraph-supervisor with create_react_agent
Fixes #3921 — same root cause as #3841, duplicate issue

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced agent creation wrapper to more reliably handle tools from LangChain, including improved tool extraction and definition generation.
  • Tests

    • Added regression test to verify create_react_agent functionality with ToolNode input and tool definition accuracy.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Dvir Rezenman seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ff3a8d0a-ff4c-4560-8c90-1dbae548c17a

📥 Commits

Reviewing files that changed from the base of the PR and between abbcc11 and 0ef2899.

📒 Files selected for processing (2)
  • packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/patch.py
  • packages/opentelemetry-instrumentation-langchain/tests/test_langgraph.py

📝 Walkthrough

Walkthrough

The pull request enhances the OpenTelemetry LangChain instrumentation to robustly handle tools wrapped in LangChain's ToolNode by introducing a fallback iteration mechanism that checks for tools_by_name.values() before using tools directly. A regression test validates this functionality.

Changes

Agent Tool Wrapper Enhancement

Layer / File(s) Summary
Core Implementation
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/patch.py
Agent creation wrapper modified to extract tools via tools_by_name.values() when available, with fallback to original tools iterable, ensuring GEN_AI_TOOL_DEFINITIONS are correctly populated for ToolNode-wrapped tools.
Test Coverage
packages/opentelemetry-instrumentation-langchain/tests/test_langgraph.py
New regression test test_create_react_agent_with_toolnode verifies that create_react_agent accepts ToolNode as tools input and correctly emits both tool definitions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A ToolNode hops through LangChain's door,
The wrapper now knows what's inside its core—
tools_by_name unlocks the way,
While tests ensure the tools will stay! 🛠️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main fix: handling ToolNode in the create_react_agent tool iteration, which aligns directly with the core changes in the patch.py file.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix(langchain)-handle-ToolNode-in-create_react_agent-tool-iteration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dvirski dvirski requested a review from netanel-tl May 6, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants