@@ -130,7 +130,8 @@ async def handle_events(self, thread_id: str, events: AsyncIterable[WorkflowEven
130130 descriptive_title = f"Connected to { event .data .target } "
131131 handoff_result_task = CustomTask (title = descriptive_title , icon = "check-circle-filled" )
132132 taskResultUpdate = TaskItem (thread_id = thread_id ,id = f"tsk_{ uuid .uuid4 ().hex [:8 ]} " , task = handoff_result_task , created_at = datetime .now ())
133- yield ThreadItemAddedEvent (item = taskResultUpdate )
133+ yield ThreadItemAddedEvent (item = taskResultUpdate )
134+ continue
134135
135136 if event .type == "output" :
136137 if isinstance (event .data , AgentResponseUpdate ) \
@@ -152,6 +153,9 @@ async def handle_events(self, thread_id: str, events: AsyncIterable[WorkflowEven
152153 #force this to be FunctionCallContent
153154 function_call_content = event .data .contents [0 ] #type: ignore
154155
156+ #skip any framework handoff_to_ function call
157+ if function_call_content .name and function_call_content .name .startswith ("handoff_to_" ):
158+ continue
155159
156160 if function_call_content .name :
157161 call_id = function_call_content .call_id
@@ -166,9 +170,16 @@ async def handle_events(self, thread_id: str, events: AsyncIterable[WorkflowEven
166170 and event .data .contents \
167171 and isinstance (event .data .contents , list ) \
168172 and all (item .type == "function_result" for item in event .data .contents ):
173+
169174 function_result_content = event .data .contents [0 ] #type: ignore
175+
176+ #skip any framework handoff_to_ function call. check if result dict has the key "handoff_to"
177+ if function_result_content .result and isinstance (function_result_content .result , dict ) and function_result_content .result .get ("handoff_to" ):
178+ continue
179+
170180 if function_result_content .call_id :
171- tool_name = self .tool_name_id_map .get (function_result_content .call_id , function_result_content .call_id )
181+
182+ tool_name = self .tool_name_id_map .get (function_result_content .call_id , function_result_content .name )
172183 descriptive_title = event_description_map [tool_name ]["end" ] if tool_name in event_description_map else tool_name
173184 function_result_task = CustomTask (title = descriptive_title , icon = "check-circle-filled" )
174185 taskResultUpdate = TaskItem (thread_id = thread_id ,id = function_result_content .call_id , task = function_result_task , created_at = datetime .now ())
@@ -182,7 +193,7 @@ async def handle_events(self, thread_id: str, events: AsyncIterable[WorkflowEven
182193 function_approval_content : Content = event .data .contents [0 ].function_call #type: ignore
183194 tool_name = function_approval_content .name
184195 parsed_args = function_approval_content .arguments
185- function_approval_content .call_id
196+ call_id = function_approval_content .call_id
186197 # approval_request_widget = build_approval_request(tool_name=tool_name, tool_args=parsed_args, call_id=function_approval_content.call_id, request_id=function_approval_content.id)
187198 # Server Managed Widget Item
188199 # widget_item = WidgetItem(
@@ -200,18 +211,19 @@ async def handle_events(self, thread_id: str, events: AsyncIterable[WorkflowEven
200211 args = {
201212 "tool_name" : tool_name ,
202213 "tool_args" : parsed_args ,
203- "call_id" : function_approval_content . call_id ,
214+ "call_id" : call_id ,
204215 "request_id" : function_approval_content .id
205216 }
206217 )
207218 #CustomThreadItemDoneEvent is a chatkit custom thread item type to support client widget. we disable pylance to avoid linting error
208219 yield CustomThreadItemDoneEvent (type = "thread.item.done" , item = client_widget_item ) #type: ignore
220+ continue
209221
210222
211- else :
212- event_description = event_description_map .get (event .type , event .type )
213- progressUpdate = ProgressUpdateEvent (text = event_description , icon = "atom" )
214- yield progressUpdate
223+ # Handle other event types as progress updates with event type as description
224+ event_description = event_description_map .get (event .type , event .type )
225+ progressUpdate = ProgressUpdateEvent (text = event_description , icon = "atom" )
226+ yield progressUpdate
215227
216228 # Finalize the message
217229 if self .message_started :
0 commit comments