Skip to content

Commit 2c93361

Browse files
Merge pull request #1002 from MervinPraison/claude/pr-999-20250718-1529
Fix: Add comprehensive telemetry cleanup to prevent agent termination hang
2 parents 0da581b + e33f992 commit 2c93361

File tree

1 file changed

+14
-0
lines changed
  • src/praisonai-agents/praisonaiagents/agent

1 file changed

+14
-0
lines changed

src/praisonai-agents/praisonaiagents/agent/agent.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,19 +1300,27 @@ def chat(self, prompt, temperature=0.2, tools=None, output_json=None, output_pyd
13001300
# Apply guardrail validation for custom LLM response
13011301
try:
13021302
validated_response = self._apply_guardrail_with_retry(response_text, prompt, temperature, tools, task_name, task_description, task_id)
1303+
# Ensure proper cleanup of telemetry system to prevent hanging
1304+
self._cleanup_telemetry()
13031305
return validated_response
13041306
except Exception as e:
13051307
logging.error(f"Agent {self.name}: Guardrail validation failed for custom LLM: {e}")
13061308
# Rollback chat history on guardrail failure
13071309
self.chat_history = self.chat_history[:chat_history_length]
1310+
# Ensure proper cleanup of telemetry system to prevent hanging
1311+
self._cleanup_telemetry()
13081312
return None
13091313
except Exception as e:
13101314
# Rollback chat history if LLM call fails
13111315
self.chat_history = self.chat_history[:chat_history_length]
13121316
display_error(f"Error in LLM chat: {e}")
1317+
# Ensure proper cleanup of telemetry system to prevent hanging
1318+
self._cleanup_telemetry()
13131319
return None
13141320
except Exception as e:
13151321
display_error(f"Error in LLM chat: {e}")
1322+
# Ensure proper cleanup of telemetry system to prevent hanging
1323+
self._cleanup_telemetry()
13161324
return None
13171325
else:
13181326
# Use the new _build_messages helper method
@@ -1396,11 +1404,15 @@ def chat(self, prompt, temperature=0.2, tools=None, output_json=None, output_pyd
13961404
validated_reasoning = self._apply_guardrail_with_retry(response.choices[0].message.reasoning_content, original_prompt, temperature, tools, task_name, task_description, task_id)
13971405
# Execute callback after validation
13981406
self._execute_callback_and_display(original_prompt, validated_reasoning, time.time() - start_time, task_name, task_description, task_id)
1407+
# Ensure proper cleanup of telemetry system to prevent hanging
1408+
self._cleanup_telemetry()
13991409
return validated_reasoning
14001410
except Exception as e:
14011411
logging.error(f"Agent {self.name}: Guardrail validation failed for reasoning content: {e}")
14021412
# Rollback chat history on guardrail failure
14031413
self.chat_history = self.chat_history[:chat_history_length]
1414+
# Ensure proper cleanup of telemetry system to prevent hanging
1415+
self._cleanup_telemetry()
14041416
return None
14051417
# Apply guardrail to regular response
14061418
try:
@@ -1849,6 +1861,8 @@ async def achat(self, prompt: str, temperature=0.2, tools=None, output_json=None
18491861
if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
18501862
total_time = time.time() - start_time
18511863
logging.debug(f"Agent.achat failed in {total_time:.2f} seconds: {str(e)}")
1864+
# Ensure proper cleanup of telemetry system to prevent hanging
1865+
self._cleanup_telemetry()
18521866
return None
18531867

18541868
async def _achat_completion(self, response, tools, reasoning_steps=False):

0 commit comments

Comments
 (0)