@@ -113,6 +113,7 @@ async def _handle_stream_events(self, input: RunAgentInput) -> AsyncGenerator[st
113
113
"thread_id" : thread_id ,
114
114
"thinking_process" : None ,
115
115
"node_name" : None ,
116
+ "has_function_streaming" : False ,
116
117
}
117
118
self .active_run = INITIAL_ACTIVE_RUN
118
119
@@ -485,6 +486,9 @@ async def _handle_single_event(self, event: Any, state: State) -> AsyncGenerator
485
486
is_tool_call_args_event = has_current_stream and current_stream .get ("tool_call_id" ) and tool_call_data and tool_call_data .get ("args" )
486
487
is_tool_call_end_event = has_current_stream and current_stream .get ("tool_call_id" ) and not tool_call_data
487
488
489
+ if is_tool_call_start_event or is_tool_call_end_event or is_tool_call_args_event :
490
+ self .active_run ["has_function_streaming" ] = True
491
+
488
492
reasoning_data = resolve_reasoning_content (event ["data" ]["chunk" ]) if event ["data" ]["chunk" ] else None
489
493
message_content = resolve_message_content (event ["data" ]["chunk" ].content ) if event ["data" ]["chunk" ] and event ["data" ]["chunk" ].content else None
490
494
is_message_content_event = tool_call_data is None and message_content
@@ -649,6 +653,35 @@ async def _handle_single_event(self, event: Any, state: State) -> AsyncGenerator
649
653
CustomEvent (type = EventType .CUSTOM , name = event ["name" ], value = event ["data" ], raw_event = event )
650
654
)
651
655
656
+ elif event_type == LangGraphEventTypes .OnToolEnd :
657
+ if self .active_run ["has_function_streaming" ]:
658
+ return
659
+ tool_call_output = event ["data" ]["output" ]
660
+ yield self ._dispatch_event (
661
+ ToolCallStartEvent (
662
+ type = EventType .TOOL_CALL_START ,
663
+ tool_call_id = tool_call_output .tool_call_id ,
664
+ tool_call_name = tool_call_output .name ,
665
+ parent_message_id = tool_call_output .id ,
666
+ raw_event = event ,
667
+ )
668
+ )
669
+ yield self ._dispatch_event (
670
+ ToolCallArgsEvent (
671
+ type = EventType .TOOL_CALL_ARGS ,
672
+ tool_call_id = tool_call_output .tool_call_id ,
673
+ delta = json .dumps (event ["data" ]["input" ]),
674
+ raw_event = event
675
+ )
676
+ )
677
+ yield self ._dispatch_event (
678
+ ToolCallEndEvent (
679
+ type = EventType .TOOL_CALL_END ,
680
+ tool_call_id = tool_call_output .tool_call_id ,
681
+ raw_event = event
682
+ )
683
+ )
684
+
652
685
def handle_thinking_event (self , reasoning_data : LangGraphReasoning ) -> Generator [str , Any , str | None ]:
653
686
if not reasoning_data or "type" not in reasoning_data or "text" not in reasoning_data :
654
687
return ""
0 commit comments