@@ -320,10 +320,9 @@ async def condition_node_function(
320320 )
321321 ]
322322 ),
323- )
324- ]
323+ ) ]
325324 content = content + condition_content
326-
325+
327326 yield {
328327 "content" : content ,
329328 "status" : "condition_evaluated" ,
@@ -332,7 +331,7 @@ async def condition_node_function(
332331 "conversation_history" : conversation_history ,
333332 "session_id" : session_id ,
334333 }
335-
334+
336335 async def message_node_function (
337336 state : State , node_id : str , node_data : Dict [str , Any ]
338337 ) -> AsyncGenerator [State , None ]:
@@ -365,15 +364,81 @@ async def message_node_function(
365364 "status" : "message_added" ,
366365 "node_outputs" : node_outputs ,
367366 "cycle_count" : state .get ("cycle_count" , 0 ),
367+ "conversation_history" : conversation_history , "session_id" : session_id ,
368+ }
369+
370+ async def delay_node_function (
371+ state : State , node_id : str , node_data : Dict [str , Any ]
372+ ) -> AsyncGenerator [State , None ]:
373+ delay_data = node_data .get ("delay" , {})
374+ delay_value = delay_data .get ("value" , 0 )
375+ delay_unit = delay_data .get ("unit" , "seconds" )
376+ delay_description = delay_data .get ("description" , "" )
377+
378+ # Convert to seconds based on unit
379+ delay_seconds = delay_value
380+ if delay_unit == "minutes" :
381+ delay_seconds = delay_value * 60
382+ elif delay_unit == "hours" :
383+ delay_seconds = delay_value * 3600
384+
385+ label = node_data .get ("label" , "delay_node" )
386+ print (f"\n ⏱️ DELAY-NODE: { delay_value } { delay_unit } - { delay_description } " )
387+
388+ content = state .get ("content" , [])
389+ session_id = state .get ("session_id" , "" )
390+ conversation_history = state .get ("conversation_history" , [])
391+
392+ # Add a message indicating the delay
393+ delay_message = f"Aguardando { delay_value } { delay_unit } ..."
394+ if delay_description :
395+ delay_message += f" ({ delay_description } )"
396+
397+ new_event = Event (
398+ author = label ,
399+ content = Content (parts = [Part (text = delay_message )]),
400+ )
401+ content = content + [new_event ]
402+
403+ # Store node output information
404+ node_outputs = state .get ("node_outputs" , {})
405+ node_outputs [node_id ] = {
406+ "delay_value" : delay_value ,
407+ "delay_unit" : delay_unit ,
408+ "delay_seconds" : delay_seconds ,
409+ "delay_start_time" : datetime .now ().isoformat (),
410+ }
411+
412+ # Actually perform the delay
413+ import asyncio
414+ await asyncio .sleep (delay_seconds )
415+
416+ # Add completion message
417+ complete_message = f"Delay de { delay_value } { delay_unit } concluído."
418+ complete_event = Event (
419+ author = label ,
420+ content = Content (parts = [Part (text = complete_message )]),
421+ )
422+ content = content + [complete_event ]
423+
424+ # Update node outputs with completion information
425+ node_outputs [node_id ]["delay_end_time" ] = datetime .now ().isoformat ()
426+ node_outputs [node_id ]["delay_completed" ] = True
427+
428+ yield {
429+ "content" : content ,
430+ "status" : "delay_completed" ,
431+ "node_outputs" : node_outputs , "cycle_count" : state .get ("cycle_count" , 0 ),
368432 "conversation_history" : conversation_history ,
369433 "session_id" : session_id ,
370434 }
371-
435+
372436 return {
373437 "start-node" : start_node_function ,
374438 "agent-node" : agent_node_function ,
375439 "condition-node" : condition_node_function ,
376440 "message-node" : message_node_function ,
441+ "delay-node" : delay_node_function ,
377442 }
378443
379444 def _evaluate_condition (self , condition : Dict [str , Any ], state : State ) -> bool :
0 commit comments