Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/crewai/src/crewai/agents/crew_agent_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import contextvars
import inspect
import logging
import traceback
from typing import TYPE_CHECKING, Annotated, Any, Literal, cast
import warnings

Expand Down Expand Up @@ -1006,7 +1007,7 @@ def _execute_single_native_tool_call(

result = format_native_tool_output_for_agent(output_tool, raw_result)
except Exception as e:
result = f"Error executing tool: {e}"
result = f"Error executing tool: {e}\nTraceback:\n{traceback.format_exc(limit=5)}"
raw_tool_result = result
if self.task:
self.task.increment_tools_errors()
Expand Down
11 changes: 6 additions & 5 deletions lib/crewai/src/crewai/experimental/agent_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import inspect
import json
import threading
import traceback
from typing import TYPE_CHECKING, Any, Literal, TypeVar, cast
from uuid import uuid4

Expand Down Expand Up @@ -1611,13 +1612,13 @@ def execute_tool_action(self) -> Literal["tool_completed", "tool_result_is_final
)
except Exception as e:
if self.agent and self.agent.verbose:
PRINTER.print(content=f"Error in tool execution: {e}", color="red")
PRINTER.print(content=f"Error in tool execution: {e}\n{traceback.format_exc(limit=5)}", color="red")
if self.task:
self.task.increment_tools_errors()

error_observation = f"\nObservation: Error executing tool: {e}"
error_observation = f"\nObservation: Error executing tool: {e}\nTraceback:\n{traceback.format_exc(limit=5)}"
action.text += error_observation
action.result = str(e)
action.result = str(e) + f"\nTraceback:\n{traceback.format_exc(limit=5)}"
self._append_message_to_state(action.text)

reasoning_prompt = I18N_DEFAULT.slice("post_tool_reasoning")
Expand Down Expand Up @@ -1736,7 +1737,7 @@ def execute_native_tool(
ordered_results[idx] = {
"call_id": call_id,
"func_name": func_name,
"result": f"Error executing tool: {e}",
"result": f"Error executing tool: {e}\nTraceback:\n{traceback.format_exc(limit=5)}",
"from_cache": False,
"original_tool": None,
}
Expand Down Expand Up @@ -1999,7 +2000,7 @@ def _execute_single_native_tool_call(self, tool_call: Any) -> dict[str, Any]:
output_tool, raw_result
)
except Exception as e:
result = f"Error executing tool: {e}"
result = f"Error executing tool: {e}\nTraceback:\n{traceback.format_exc(limit=5)}"
raw_tool_result = result
if self.task:
self.task.increment_tools_errors()
Expand Down
7 changes: 4 additions & 3 deletions lib/crewai/src/crewai/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
TypedDict,
cast,
)
import traceback

from dotenv import load_dotenv
from pydantic import BaseModel, Field, model_validator
Expand Down Expand Up @@ -1755,11 +1756,11 @@ def _handle_tool_call(
return result
except Exception as e:
fn = available_functions.get(function_name, lambda: None)
logging.error(f"Error executing function '{function_name}': {e}")
logging.error(f"Error executing function '{function_name}': {e}\n{traceback.format_exc(limit=5)}")
crewai_event_bus.emit(
self,
event=LLMCallFailedEvent(
error=f"Tool execution error: {e!s}",
error=f"Tool execution error: {e!s}\nTraceback:\n{traceback.format_exc(limit=5)}",
from_task=from_task,
from_agent=from_agent,
call_id=get_current_call_id(),
Expand All @@ -1770,7 +1771,7 @@ def _handle_tool_call(
event=ToolUsageErrorEvent(
tool_name=function_name,
tool_args=function_args,
error=f"Tool execution error: {e!s}",
error=f"Tool execution error: {e!s}\nTraceback:\n{traceback.format_exc(limit=5)}",
from_task=from_task,
from_agent=from_agent,
),
Expand Down
3 changes: 2 additions & 1 deletion lib/crewai/src/crewai/utilities/agent_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import inspect
import json
import re
import traceback
from typing import TYPE_CHECKING, Any, Final, Literal, TypedDict

from crewai_core.printer import PRINTER, ColoredText, Printer
Expand Down Expand Up @@ -1546,7 +1547,7 @@ def execute_single_native_tool_call(

result = format_native_tool_output_for_agent(output_tool, raw_result)
except Exception as e:
result = f"Error executing tool: {e}"
result = f"Error executing tool: {e}\nTraceback:\n{traceback.format_exc(limit=5)}"
raw_tool_result = result
if task:
task.increment_tools_errors()
Expand Down