fix(core): make self positional-only in _run/_arun to allow "self" as tool input key#35043
fix(core): make self positional-only in _run/_arun to allow "self" as tool input key#35043Varun Chawla (veeceey) wants to merge 2 commits intolangchain-ai:masterfrom
self positional-only in _run/_arun to allow "self" as tool input key#35043Conversation
Merging this PR will not alter performance
|
Manual test resultsRan Targeted tests ( Full test_tools.py suite (regression check): No failures, no regressions. The positional-only |
cff4401 to
a0b8fac
Compare
|
All tests passing, ready for review/merge |
|
Hi maintainers, friendly ping on this PR. It's been open a few days now and all checks are passing. Would appreciate it whenever you get a chance to review. Thank you for your time! |
|
Quick ping -- this one's been green for a while now. Happy to address any feedback if needed. Thanks for your time! |
e6a9285 to
9c560b8
Compare
…lf" as tool input key
When a tool is invoked with input containing a key named "self" (e.g.
`tool.invoke({"self": 2})`), the keyword argument collides with the
bound method receiver, raising `TypeError: got multiple values for
argument 'self'`.
Adding the positional-only marker (`/`) after `self` in `_run` and
`_arun` across `BaseTool`, `StructuredTool`, and `Tool` lets Python
route user-supplied `"self"` into `**kwargs` instead of conflicting
with the method's own receiver.
Closes langchain-ai#34900
9c560b8 to
af81693
Compare
Summary
BaseToolfailing withTypeError: got multiple values for argument 'self'when tool input contains a key named"self"(e.g.tool.invoke({"self": 2}))/) afterselfin_runand_arunacrossBaseTool,StructuredTool, andTool, so Python routes user-supplied"self"into**kwargsinstead of conflicting with the method receiverCloses #34900
Test plan
test_tool_invoke_with_self_keyword_in_inputverifies sync invocation with"self"in inputtest_tool_ainvoke_with_self_keyword_in_inputverifies async invocation with"self"in inputReview notes
The change is minimal -- just adding
/afterselfin the method signatures. This is a non-breaking change: all existing subclass overrides of_run/_aruncontinue to work exactly as before. The positional-only marker only affects whether Python allowsself=...as a keyword argument at the call site; it does not change how the method is dispatched or overridden.Note that user-defined
BaseToolsubclasses that override_runwithoutself, /will still hit this issue if they receive"self"as a keyword argument. However, the built-in tool classes (StructuredTool,Tool) and the@tooldecorator -- which cover the vast majority of usage -- are all fixed.