mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 23:58:34 +00:00
70 lines
1.7 KiB
Python
70 lines
1.7 KiB
Python
from datetime import datetime
|
|
from typing import Any, Callable, Dict, Optional, Union
|
|
|
|
from .base_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
|
|
|
|
This event contains the result of the tool execution, allowing listeners
|
|
to access the output directly without implementing workarounds.
|
|
"""
|
|
|
|
started_at: datetime
|
|
finished_at: datetime
|
|
from_cache: bool = False
|
|
result: Any = None # Tool execution result
|
|
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
|