Skip to content

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

fix: enhance LLM event handling with task and agent metadata (#3422)

Lorenze Jay2633b33afc47
diff --git a/src/crewai/llm.py b/src/crewai/llm.py
index 96fad7c62..73c7b658e 100644
--- a/src/crewai/llm.py
+++ b/src/crewai/llm.py
@@ -950,6 +950,8 @@ class LLM(BaseLLM):
tool_name=function_name,
tool_args=function_args,
error=f"Tool execution error: {str(e)}",
+ from_task=from_task,
+ from_agent=from_agent,
),
)
return None
diff --git a/src/crewai/utilities/constants.py b/src/crewai/utilities/constants.py
index ef66ff87a..184ea6e9b 100644
--- a/src/crewai/utilities/constants.py
+++ b/src/crewai/utilities/constants.py
@@ -16,4 +16,4 @@ class _NotSpecified:
# Unlike `None`, which might be a valid value from the user, `NOT_SPECIFIED` allows
# us to distinguish between "not passed at all" and "explicitly passed None" or "[]".
NOT_SPECIFIED = _NotSpecified()
-CREWAI_BASE_URL = "https://app.crewai.com/"
+CREWAI_BASE_URL = "https://app.crewai.com"
diff --git a/src/crewai/utilities/events/listeners/tracing/trace_batch_manager.py b/src/crewai/utilities/events/listeners/tracing/trace_batch_manager.py
index 3fa38e84e..11d63b175 100644
--- a/src/crewai/utilities/events/listeners/tracing/trace_batch_manager.py
+++ b/src/crewai/utilities/events/listeners/tracing/trace_batch_manager.py
@@ -150,10 +150,10 @@ class TraceBatchManager:
"""Add event to buffer"""
self.event_buffer.append(trace_event)
- def _send_events_to_backend(self):
+ def _send_events_to_backend(self) -> int:
"""Send buffered events to backend with graceful failure handling"""
if not self.plus_api or not self.trace_batch_id or not self.event_buffer:
- return
+ return 500
try:
payload = {
@@ -173,19 +173,22 @@ class TraceBatchManager:
if response is None:
logger.warning("Failed to send trace events. Events will be lost.")
- return
+ return 500
if response.status_code in [200, 201]:
self.event_buffer.clear()
+ return 200
else:
logger.warning(
f"Failed to send events: {response.status_code}. Events will be lost."
)
+ return 500
except Exception as e:
logger.warning(
f"Error sending events to backend: {str(e)}. Events will be lost."
)
+ return 500
def finalize_batch(self) -> Optional[TraceBatch]:
"""Finalize batch and return it for sending"""
@@ -194,7 +197,9 @@ class TraceBatchManager:
self.current_batch.events = self.event_buffer.copy()
if self.event_buffer:
- self._send_events_to_backend()
+ events_sent_to_backend_status = self._send_events_to_backend()
+ if events_sent_to_backend_status == 500:
+ return None
self._finalize_backend_batch()
finalized_batch = self.current_batch