@@ -113,6 +113,7 @@ async def _handle_stream_events(self, input: RunAgentInput) -> AsyncGenerator[st
113113 "thread_id" : thread_id ,
114114 "thinking_process" : None ,
115115 "node_name" : None ,
116+ "has_function_streaming" : False ,
116117 }
117118 self .active_run = INITIAL_ACTIVE_RUN
118119
@@ -485,6 +486,9 @@ async def _handle_single_event(self, event: Any, state: State) -> AsyncGenerator
485486 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" )
486487 is_tool_call_end_event = has_current_stream and current_stream .get ("tool_call_id" ) and not tool_call_data
487488
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+
488492 reasoning_data = resolve_reasoning_content (event ["data" ]["chunk" ]) if event ["data" ]["chunk" ] else None
489493 message_content = resolve_message_content (event ["data" ]["chunk" ].content ) if event ["data" ]["chunk" ] and event ["data" ]["chunk" ].content else None
490494 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
649653 CustomEvent (type = EventType .CUSTOM , name = event ["name" ], value = event ["data" ], raw_event = event )
650654 )
651655
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+
652685 def handle_thinking_event (self , reasoning_data : LangGraphReasoning ) -> Generator [str , Any , str | None ]:
653686 if not reasoning_data or "type" not in reasoning_data or "text" not in reasoning_data :
654687 return ""
0 commit comments