@@ -1407,11 +1407,15 @@ def chat(self, prompt, temperature=0.2, tools=None, output_json=None, output_pyd
14071407 validated_response = self ._apply_guardrail_with_retry (response_text , original_prompt , temperature , tools , task_name , task_description , task_id )
14081408 # Execute callback after validation
14091409 self ._execute_callback_and_display (original_prompt , validated_response , time .time () - start_time , task_name , task_description , task_id )
1410+ # Ensure proper cleanup of telemetry system to prevent hanging
1411+ self ._cleanup_telemetry ()
14101412 return validated_response
14111413 except Exception as e :
14121414 logging .error (f"Agent { self .name } : Guardrail validation failed: { e } " )
14131415 # Rollback chat history on guardrail failure
14141416 self .chat_history = self .chat_history [:chat_history_length ]
1417+ # Ensure proper cleanup of telemetry system to prevent hanging
1418+ self ._cleanup_telemetry ()
14151419 return None
14161420
14171421 reflection_prompt = f"""
@@ -1524,6 +1528,8 @@ def __init__(self, data):
15241528 display_error (f"Unexpected error in chat: { e } " , console = self .console )
15251529 # Rollback chat history
15261530 self .chat_history = self .chat_history [:chat_history_length ]
1531+ # Ensure proper cleanup of telemetry system to prevent hanging
1532+ self ._cleanup_telemetry ()
15271533 return None
15281534
15291535 def clean_json_output (self , output : str ) -> str :
@@ -1641,6 +1647,8 @@ async def achat(self, prompt: str, temperature=0.2, tools=None, output_json=None
16411647 if logging .getLogger ().getEffectiveLevel () == logging .DEBUG :
16421648 total_time = time .time () - start_time
16431649 logging .debug (f"Agent.achat failed in { total_time :.2f} seconds: { str (e )} " )
1650+ # Ensure proper cleanup of telemetry system to prevent hanging
1651+ self ._cleanup_telemetry ()
16441652 return None
16451653
16461654 # For OpenAI client
@@ -1818,17 +1826,23 @@ async def achat(self, prompt: str, temperature=0.2, tools=None, output_json=None
18181826 validated_response = self ._apply_guardrail_with_retry (response_text , original_prompt , temperature , tools , task_name , task_description , task_id )
18191827 # Execute callback after validation
18201828 self ._execute_callback_and_display (original_prompt , validated_response , time .time () - start_time , task_name , task_description , task_id )
1829+ # Ensure proper cleanup of telemetry system to prevent hanging
1830+ self ._cleanup_telemetry ()
18211831 return validated_response
18221832 except Exception as e :
18231833 logging .error (f"Agent { self .name } : Guardrail validation failed for OpenAI client: { e } " )
18241834 # Rollback chat history on guardrail failure
18251835 self .chat_history = self .chat_history [:chat_history_length ]
1836+ # Ensure proper cleanup of telemetry system to prevent hanging
1837+ self ._cleanup_telemetry ()
18261838 return None
18271839 except Exception as e :
18281840 display_error (f"Error in chat completion: { e } " )
18291841 if logging .getLogger ().getEffectiveLevel () == logging .DEBUG :
18301842 total_time = time .time () - start_time
18311843 logging .debug (f"Agent.achat failed in { total_time :.2f} seconds: { str (e )} " )
1844+ # Ensure proper cleanup of telemetry system to prevent hanging
1845+ self ._cleanup_telemetry ()
18321846 return None
18331847 except Exception as e :
18341848 display_error (f"Error in achat: { e } " )
0 commit comments