Using fingerprints (#2456)

* using fingerprints

* passing fingerptins on tools

* fix

* update lock

* Fix type checker errors

---------

Co-authored-by: Brandon Hancock <brandon@brandonhancock.io>
Co-authored-by: Brandon Hancock (bhancock_ai) <109994880+bhancockio@users.noreply.github.com>
Co-authored-by: Lorenze Jay <63378463+lorenzejay@users.noreply.github.com>
This commit is contained in:
João Moura
2025-03-26 14:54:23 -07:00
committed by GitHub
parent 48983773f5
commit e1a73e0c44
10 changed files with 458 additions and 36 deletions

View File

@@ -45,7 +45,7 @@ class TaskEvaluator:
def evaluate(self, task, output) -> TaskEvaluation:
crewai_event_bus.emit(
self, TaskEvaluationEvent(evaluation_type="task_evaluation")
self, TaskEvaluationEvent(evaluation_type="task_evaluation", task=task)
)
evaluation_query = (
f"Assess the quality of the task completed based on the description, expected output, and actual results.\n\n"

View File

@@ -21,6 +21,15 @@ class AgentExecutionStartedEvent(CrewEvent):
model_config = {"arbitrary_types_allowed": True}
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the agent
if hasattr(self.agent, 'fingerprint') and self.agent.fingerprint:
self.source_fingerprint = self.agent.fingerprint.uuid_str
self.source_type = "agent"
if hasattr(self.agent.fingerprint, 'metadata') and self.agent.fingerprint.metadata:
self.fingerprint_metadata = self.agent.fingerprint.metadata
class AgentExecutionCompletedEvent(CrewEvent):
"""Event emitted when an agent completes executing a task"""
@@ -30,6 +39,15 @@ class AgentExecutionCompletedEvent(CrewEvent):
output: str
type: str = "agent_execution_completed"
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the agent
if hasattr(self.agent, 'fingerprint') and self.agent.fingerprint:
self.source_fingerprint = self.agent.fingerprint.uuid_str
self.source_type = "agent"
if hasattr(self.agent.fingerprint, 'metadata') and self.agent.fingerprint.metadata:
self.fingerprint_metadata = self.agent.fingerprint.metadata
class AgentExecutionErrorEvent(CrewEvent):
"""Event emitted when an agent encounters an error during execution"""
@@ -38,3 +56,12 @@ class AgentExecutionErrorEvent(CrewEvent):
task: Any
error: str
type: str = "agent_execution_error"
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the agent
if hasattr(self.agent, 'fingerprint') and self.agent.fingerprint:
self.source_fingerprint = self.agent.fingerprint.uuid_str
self.source_type = "agent"
if hasattr(self.agent.fingerprint, 'metadata') and self.agent.fingerprint.metadata:
self.fingerprint_metadata = self.agent.fingerprint.metadata

View File

@@ -1,4 +1,5 @@
from datetime import datetime
from typing import Any, Dict, Optional
from pydantic import BaseModel, Field
@@ -8,3 +9,6 @@ class CrewEvent(BaseModel):
timestamp: datetime = Field(default_factory=datetime.now)
type: str
source_fingerprint: Optional[str] = None # UUID string of the source entity
source_type: Optional[str] = None # "agent", "task", "crew"
fingerprint_metadata: Optional[Dict[str, Any]] = None # Any relevant metadata

View File

@@ -11,6 +11,16 @@ class CrewKickoffStartedEvent(CrewEvent):
crew_name: Optional[str]
inputs: Optional[Dict[str, Any]]
type: str = "crew_kickoff_started"
crew: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the crew
if self.crew and hasattr(self.crew, 'fingerprint') and self.crew.fingerprint:
self.source_fingerprint = self.crew.fingerprint.uuid_str
self.source_type = "crew"
if hasattr(self.crew.fingerprint, 'metadata') and self.crew.fingerprint.metadata:
self.fingerprint_metadata = self.crew.fingerprint.metadata
class CrewKickoffCompletedEvent(CrewEvent):
@@ -19,6 +29,16 @@ class CrewKickoffCompletedEvent(CrewEvent):
crew_name: Optional[str]
output: Any
type: str = "crew_kickoff_completed"
crew: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the crew
if self.crew and hasattr(self.crew, 'fingerprint') and self.crew.fingerprint:
self.source_fingerprint = self.crew.fingerprint.uuid_str
self.source_type = "crew"
if hasattr(self.crew.fingerprint, 'metadata') and self.crew.fingerprint.metadata:
self.fingerprint_metadata = self.crew.fingerprint.metadata
class CrewKickoffFailedEvent(CrewEvent):
@@ -27,6 +47,16 @@ class CrewKickoffFailedEvent(CrewEvent):
error: str
crew_name: Optional[str]
type: str = "crew_kickoff_failed"
crew: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the crew
if self.crew and hasattr(self.crew, 'fingerprint') and self.crew.fingerprint:
self.source_fingerprint = self.crew.fingerprint.uuid_str
self.source_type = "crew"
if hasattr(self.crew.fingerprint, 'metadata') and self.crew.fingerprint.metadata:
self.fingerprint_metadata = self.crew.fingerprint.metadata
class CrewTrainStartedEvent(CrewEvent):
@@ -37,6 +67,16 @@ class CrewTrainStartedEvent(CrewEvent):
filename: str
inputs: Optional[Dict[str, Any]]
type: str = "crew_train_started"
crew: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the crew
if self.crew and hasattr(self.crew, 'fingerprint') and self.crew.fingerprint:
self.source_fingerprint = self.crew.fingerprint.uuid_str
self.source_type = "crew"
if hasattr(self.crew.fingerprint, 'metadata') and self.crew.fingerprint.metadata:
self.fingerprint_metadata = self.crew.fingerprint.metadata
class CrewTrainCompletedEvent(CrewEvent):
@@ -46,6 +86,16 @@ class CrewTrainCompletedEvent(CrewEvent):
n_iterations: int
filename: str
type: str = "crew_train_completed"
crew: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the crew
if self.crew and hasattr(self.crew, 'fingerprint') and self.crew.fingerprint:
self.source_fingerprint = self.crew.fingerprint.uuid_str
self.source_type = "crew"
if hasattr(self.crew.fingerprint, 'metadata') and self.crew.fingerprint.metadata:
self.fingerprint_metadata = self.crew.fingerprint.metadata
class CrewTrainFailedEvent(CrewEvent):
@@ -54,6 +104,16 @@ class CrewTrainFailedEvent(CrewEvent):
error: str
crew_name: Optional[str]
type: str = "crew_train_failed"
crew: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the crew
if self.crew and hasattr(self.crew, 'fingerprint') and self.crew.fingerprint:
self.source_fingerprint = self.crew.fingerprint.uuid_str
self.source_type = "crew"
if hasattr(self.crew.fingerprint, 'metadata') and self.crew.fingerprint.metadata:
self.fingerprint_metadata = self.crew.fingerprint.metadata
class CrewTestStartedEvent(CrewEvent):
@@ -64,6 +124,16 @@ class CrewTestStartedEvent(CrewEvent):
eval_llm: Optional[Union[str, Any]]
inputs: Optional[Dict[str, Any]]
type: str = "crew_test_started"
crew: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the crew
if self.crew and hasattr(self.crew, 'fingerprint') and self.crew.fingerprint:
self.source_fingerprint = self.crew.fingerprint.uuid_str
self.source_type = "crew"
if hasattr(self.crew.fingerprint, 'metadata') and self.crew.fingerprint.metadata:
self.fingerprint_metadata = self.crew.fingerprint.metadata
class CrewTestCompletedEvent(CrewEvent):
@@ -71,6 +141,16 @@ class CrewTestCompletedEvent(CrewEvent):
crew_name: Optional[str]
type: str = "crew_test_completed"
crew: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the crew
if self.crew and hasattr(self.crew, 'fingerprint') and self.crew.fingerprint:
self.source_fingerprint = self.crew.fingerprint.uuid_str
self.source_type = "crew"
if hasattr(self.crew.fingerprint, 'metadata') and self.crew.fingerprint.metadata:
self.fingerprint_metadata = self.crew.fingerprint.metadata
class CrewTestFailedEvent(CrewEvent):
@@ -79,3 +159,13 @@ class CrewTestFailedEvent(CrewEvent):
error: str
crew_name: Optional[str]
type: str = "crew_test_failed"
crew: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the crew
if self.crew and hasattr(self.crew, 'fingerprint') and self.crew.fingerprint:
self.source_fingerprint = self.crew.fingerprint.uuid_str
self.source_type = "crew"
if hasattr(self.crew.fingerprint, 'metadata') and self.crew.fingerprint.metadata:
self.fingerprint_metadata = self.crew.fingerprint.metadata

View File

@@ -1,4 +1,4 @@
from typing import Optional
from typing import Any, Optional
from crewai.tasks.task_output import TaskOutput
from crewai.utilities.events.base_events import CrewEvent
@@ -9,6 +9,16 @@ class TaskStartedEvent(CrewEvent):
type: str = "task_started"
context: Optional[str]
task: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the task
if hasattr(self.task, 'fingerprint') and self.task.fingerprint:
self.source_fingerprint = self.task.fingerprint.uuid_str
self.source_type = "task"
if hasattr(self.task.fingerprint, 'metadata') and self.task.fingerprint.metadata:
self.fingerprint_metadata = self.task.fingerprint.metadata
class TaskCompletedEvent(CrewEvent):
@@ -16,6 +26,16 @@ class TaskCompletedEvent(CrewEvent):
output: TaskOutput
type: str = "task_completed"
task: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the task
if hasattr(self.task, 'fingerprint') and self.task.fingerprint:
self.source_fingerprint = self.task.fingerprint.uuid_str
self.source_type = "task"
if hasattr(self.task.fingerprint, 'metadata') and self.task.fingerprint.metadata:
self.fingerprint_metadata = self.task.fingerprint.metadata
class TaskFailedEvent(CrewEvent):
@@ -23,6 +43,16 @@ class TaskFailedEvent(CrewEvent):
error: str
type: str = "task_failed"
task: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the task
if hasattr(self.task, 'fingerprint') and self.task.fingerprint:
self.source_fingerprint = self.task.fingerprint.uuid_str
self.source_type = "task"
if hasattr(self.task.fingerprint, 'metadata') and self.task.fingerprint.metadata:
self.fingerprint_metadata = self.task.fingerprint.metadata
class TaskEvaluationEvent(CrewEvent):
@@ -30,3 +60,13 @@ class TaskEvaluationEvent(CrewEvent):
type: str = "task_evaluation"
evaluation_type: str
task: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the task
if hasattr(self.task, 'fingerprint') and self.task.fingerprint:
self.source_fingerprint = self.task.fingerprint.uuid_str
self.source_type = "task"
if hasattr(self.task.fingerprint, 'metadata') and self.task.fingerprint.metadata:
self.fingerprint_metadata = self.task.fingerprint.metadata

View File

@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Any, Callable, Dict
from typing import Any, Callable, Dict, Optional
from .base_events import CrewEvent
@@ -14,9 +14,19 @@ class ToolUsageEvent(CrewEvent):
tool_class: str
run_attempts: int | None = None
delegations: int | None = None
agent: Optional[Any] = None
model_config = {"arbitrary_types_allowed": True}
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the agent
if self.agent and hasattr(self.agent, 'fingerprint') and self.agent.fingerprint:
self.source_fingerprint = self.agent.fingerprint.uuid_str
self.source_type = "agent"
if hasattr(self.agent.fingerprint, 'metadata') and self.agent.fingerprint.metadata:
self.fingerprint_metadata = self.agent.fingerprint.metadata
class ToolUsageStartedEvent(ToolUsageEvent):
"""Event emitted when a tool execution is started"""
@@ -63,3 +73,13 @@ class ToolExecutionErrorEvent(CrewEvent):
tool_name: str
tool_args: Dict[str, Any]
tool_class: Callable
agent: Optional[Any] = None
def __init__(self, **data):
super().__init__(**data)
# Set fingerprint data from the agent
if self.agent and hasattr(self.agent, 'fingerprint') and self.agent.fingerprint:
self.source_fingerprint = self.agent.fingerprint.uuid_str
self.source_type = "agent"
if hasattr(self.agent.fingerprint, 'metadata') and self.agent.fingerprint.metadata:
self.fingerprint_metadata = self.agent.fingerprint.metadata