fix(langchain): handle ToolNode in create_agent_wrapper tool extraction#3973
fix(langchain): handle ToolNode in create_agent_wrapper tool extraction#3973RRocaP wants to merge 1 commit intotraceloop:mainfrom
Conversation
When langgraph-supervisor passes a ToolNode object to create_react_agent, the instrumentation crashes with: TypeError: 'ToolNode' object is not iterable ToolNode wraps tools but does not implement __iter__. It exposes individual tools via the tools_by_name attribute (dict of name->tool). This fix checks for tools_by_name before iterating, falling back to the original iterable behavior for lists, tuples, and other iterables. Fixes traceloop#3921
|
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe patch updates the agent wrapper's tool extraction logic to handle ToolNode objects, which lack direct iterability. The code now checks for a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
Fixes #3921
Problem
When
langgraph-supervisor'screate_supervisor()passes aToolNodeobject to
create_react_agent, the instrumentation crashes:ToolNodewraps tools but does not implement__iter__. It exposestools via
tools_by_name(adict[str, BaseTool]).Fix
Before iterating, check if the
toolsobject has atools_by_nameattribute. If so, iterate over its
.values(). Otherwise, iteratenormally (preserving existing behavior for lists/tuples).
Files changed
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/patch.pyTest plan
create_supervisor()withToolNodeno longer crashesSummary by CodeRabbit