mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
- Add new events for tool usage: ToolSelectionErrorEvent, ToolValidateInputErrorEvent - Improve error tracking and event emission in ToolUsage and LLM classes - Update AgentExecutionStartedEvent to use task_prompt instead of inputs - Add comprehensive test coverage for new event types and error scenarios
65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
from datetime import datetime
|
|
from typing import Any, Callable, Dict
|
|
|
|
from .crew_events import CrewEvent
|
|
|
|
|
|
class ToolUsageEvent(CrewEvent):
|
|
"""Base event for tool usage tracking"""
|
|
|
|
agent_key: str
|
|
agent_role: str
|
|
tool_name: str
|
|
tool_args: Dict[str, Any] | str
|
|
tool_class: str
|
|
run_attempts: int | None = None
|
|
delegations: int | None = None
|
|
|
|
model_config = {"arbitrary_types_allowed": True}
|
|
|
|
|
|
class ToolUsageStartedEvent(ToolUsageEvent):
|
|
"""Event emitted when a tool execution is started"""
|
|
|
|
type: str = "tool_usage_started"
|
|
|
|
|
|
class ToolUsageFinishedEvent(ToolUsageEvent):
|
|
"""Event emitted when a tool execution is completed"""
|
|
|
|
started_at: datetime
|
|
finished_at: datetime
|
|
from_cache: bool = False
|
|
type: str = "tool_usage_finished"
|
|
|
|
|
|
class ToolUsageErrorEvent(ToolUsageEvent):
|
|
"""Event emitted when a tool execution encounters an error"""
|
|
|
|
error: Any
|
|
type: str = "tool_usage_error"
|
|
|
|
|
|
class ToolValidateInputErrorEvent(ToolUsageEvent):
|
|
"""Event emitted when a tool input validation encounters an error"""
|
|
|
|
error: Any
|
|
type: str = "tool_validate_input_error"
|
|
|
|
|
|
class ToolSelectionErrorEvent(ToolUsageEvent):
|
|
"""Event emitted when a tool selection encounters an error"""
|
|
|
|
error: Any
|
|
type: str = "tool_selection_error"
|
|
|
|
|
|
class ToolExecutionErrorEvent(CrewEvent):
|
|
"""Event emitted when a tool execution encounters an error"""
|
|
|
|
error: Any
|
|
type: str = "tool_execution_error"
|
|
tool_name: str
|
|
tool_args: Dict[str, Any]
|
|
tool_class: Callable
|