@@ -119,7 +119,7 @@ def msg_content_output(output: Any) -> Union[str, list[dict]]:
119
119
# any existing ToolNode usage.
120
120
try :
121
121
return json .dumps (output , ensure_ascii = False )
122
- except Exception : # noqa: BLE001
122
+ except Exception :
123
123
return str (output )
124
124
125
125
@@ -202,7 +202,7 @@ def _handle_tool_error(
202
202
f"Got unexpected type of `handle_tool_error`. Expected bool, str "
203
203
f"or callable. Received: { flag } "
204
204
)
205
- raise ValueError (msg )
205
+ raise TypeError (msg )
206
206
return content
207
207
208
208
@@ -417,7 +417,7 @@ def tools_by_name(self) -> dict[str, BaseTool]:
417
417
418
418
def _func (
419
419
self ,
420
- input : Union [
420
+ input_ : Union [
421
421
list [AnyMessage ],
422
422
dict [str , Any ],
423
423
BaseModel ,
@@ -426,7 +426,7 @@ def _func(
426
426
* ,
427
427
store : Optional [BaseStore ], # noqa: UP045
428
428
) -> Any :
429
- tool_calls , input_type = self ._parse_input (input , store )
429
+ tool_calls , input_type = self ._parse_input (input_ , store )
430
430
config_list = get_config_list (config , len (tool_calls ))
431
431
input_types = [input_type ] * len (tool_calls )
432
432
with get_executor_for_config (config ) as executor :
@@ -436,7 +436,7 @@ def _func(
436
436
437
437
async def _afunc (
438
438
self ,
439
- input : Union [
439
+ input_ : Union [
440
440
list [AnyMessage ],
441
441
dict [str , Any ],
442
442
BaseModel ,
@@ -445,7 +445,7 @@ async def _afunc(
445
445
* ,
446
446
store : Optional [BaseStore ], # noqa: UP045
447
447
) -> Any :
448
- tool_calls , input_type = self ._parse_input (input , store )
448
+ tool_calls , input_type = self ._parse_input (input_ , store )
449
449
outputs = await asyncio .gather (
450
450
* (self ._arun_one (call , input_type , config ) for call in tool_calls )
451
451
)
@@ -625,24 +625,24 @@ async def _arun_one(
625
625
626
626
def _parse_input (
627
627
self ,
628
- input : Union [
628
+ input_ : Union [
629
629
list [AnyMessage ],
630
630
dict [str , Any ],
631
631
BaseModel ,
632
632
],
633
633
store : BaseStore | None ,
634
634
) -> tuple [list [ToolCall ], Literal ["list" , "dict" , "tool_calls" ]]:
635
635
input_type : Literal ["list" , "dict" , "tool_calls" ]
636
- if isinstance (input , list ):
637
- if isinstance (input [- 1 ], dict ) and input [- 1 ].get ("type" ) == "tool_call" :
636
+ if isinstance (input_ , list ):
637
+ if isinstance (input_ [- 1 ], dict ) and input_ [- 1 ].get ("type" ) == "tool_call" :
638
638
input_type = "tool_calls"
639
- tool_calls = cast ("list[ToolCall]" , input )
639
+ tool_calls = cast ("list[ToolCall]" , input_ )
640
640
return tool_calls , input_type
641
641
input_type = "list"
642
- messages = input
643
- elif isinstance (input , dict ) and (messages := input .get (self ._messages_key , [])):
642
+ messages = input_
643
+ elif isinstance (input_ , dict ) and (messages := input_ .get (self ._messages_key , [])):
644
644
input_type = "dict"
645
- elif messages := getattr (input , self ._messages_key , []):
645
+ elif messages := getattr (input_ , self ._messages_key , []):
646
646
# Assume dataclass-like state that can coerce from dict
647
647
input_type = "dict"
648
648
else :
@@ -651,12 +651,12 @@ def _parse_input(
651
651
652
652
try :
653
653
latest_ai_message = next (m for m in reversed (messages ) if isinstance (m , AIMessage ))
654
- except StopIteration :
654
+ except StopIteration as e :
655
655
msg = "No AIMessage found in input"
656
- raise ValueError (msg )
656
+ raise ValueError (msg ) from e
657
657
658
658
tool_calls = [
659
- self .inject_tool_args (call , input , store ) for call in latest_ai_message .tool_calls
659
+ self .inject_tool_args (call , input_ , store ) for call in latest_ai_message .tool_calls
660
660
]
661
661
return tool_calls , input_type
662
662
@@ -676,19 +676,19 @@ def _validate_tool_call(self, call: ToolCall) -> ToolMessage | None:
676
676
def _inject_state (
677
677
self ,
678
678
tool_call : ToolCall ,
679
- input : Union [
679
+ input_ : Union [
680
680
list [AnyMessage ],
681
681
dict [str , Any ],
682
682
BaseModel ,
683
683
],
684
684
) -> ToolCall :
685
685
state_args = self ._tool_to_state_args [tool_call ["name" ]]
686
- if state_args and isinstance (input , list ):
686
+ if state_args and isinstance (input_ , list ):
687
687
required_fields = list (state_args .values ())
688
688
if (
689
689
len (required_fields ) == 1 and required_fields [0 ] == self ._messages_key
690
690
) or required_fields [0 ] is None :
691
- input = {self ._messages_key : input }
691
+ input_ = {self ._messages_key : input_ }
692
692
else :
693
693
err_msg = (
694
694
f"Invalid input to ToolNode. Tool { tool_call ['name' ]} requires "
@@ -699,14 +699,14 @@ def _inject_state(
699
699
err_msg += f" State should contain fields { required_fields_str } ."
700
700
raise ValueError (err_msg )
701
701
702
- if isinstance (input , dict ):
702
+ if isinstance (input_ , dict ):
703
703
tool_state_args = {
704
- tool_arg : input [state_field ] if state_field else input
704
+ tool_arg : input_ [state_field ] if state_field else input_
705
705
for tool_arg , state_field in state_args .items ()
706
706
}
707
707
else :
708
708
tool_state_args = {
709
- tool_arg : getattr (input , state_field ) if state_field else input
709
+ tool_arg : getattr (input_ , state_field ) if state_field else input_
710
710
for tool_arg , state_field in state_args .items ()
711
711
}
712
712
@@ -737,7 +737,7 @@ def _inject_store(self, tool_call: ToolCall, store: BaseStore | None) -> ToolCal
737
737
def inject_tool_args (
738
738
self ,
739
739
tool_call : ToolCall ,
740
- input : Union [
740
+ input_ : Union [
741
741
list [AnyMessage ],
742
742
dict [str , Any ],
743
743
BaseModel ,
@@ -758,7 +758,7 @@ def inject_tool_args(
758
758
Args:
759
759
tool_call: The tool call dictionary to augment with injected arguments.
760
760
Must contain 'name', 'args', 'id', and 'type' fields.
761
- input : The current graph state to inject into tools requiring state access.
761
+ input_ : The current graph state to inject into tools requiring state access.
762
762
Can be a message list, state dictionary, or BaseModel instance.
763
763
store: The persistent store instance to inject into tools requiring storage.
764
764
Will be None if no store is configured for the graph.
@@ -781,7 +781,7 @@ def inject_tool_args(
781
781
return tool_call
782
782
783
783
tool_call_copy : ToolCall = copy (tool_call )
784
- tool_call_with_state = self ._inject_state (tool_call_copy , input )
784
+ tool_call_with_state = self ._inject_state (tool_call_copy , input_ )
785
785
return self ._inject_store (tool_call_with_state , store )
786
786
787
787
def _validate_tool_command (
0 commit comments