mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 09:08:31 +00:00
chore: apply ruff linting fixes to events module
fix: apply ruff linting to events
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from crewai.utilities.serialization import to_serializable
|
from crewai.utilities.serialization import to_serializable
|
||||||
@@ -10,11 +11,11 @@ class BaseEvent(BaseModel):
|
|||||||
|
|
||||||
timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
||||||
type: str
|
type: str
|
||||||
source_fingerprint: Optional[str] = None # UUID string of the source entity
|
source_fingerprint: str | None = None # UUID string of the source entity
|
||||||
source_type: Optional[str] = (
|
source_type: str | None = (
|
||||||
None # "agent", "task", "crew", "memory", "entity_memory", "short_term_memory", "long_term_memory", "external_memory"
|
None # "agent", "task", "crew", "memory", "entity_memory", "short_term_memory", "long_term_memory", "external_memory"
|
||||||
)
|
)
|
||||||
fingerprint_metadata: Optional[Dict[str, Any]] = None # Any relevant metadata
|
fingerprint_metadata: dict[str, Any] | None = None # Any relevant metadata
|
||||||
|
|
||||||
def to_json(self, exclude: set[str] | None = None):
|
def to_json(self, exclude: set[str] | None = None):
|
||||||
"""
|
"""
|
||||||
@@ -28,13 +29,13 @@ class BaseEvent(BaseModel):
|
|||||||
"""
|
"""
|
||||||
return to_serializable(self, exclude=exclude)
|
return to_serializable(self, exclude=exclude)
|
||||||
|
|
||||||
def _set_task_params(self, data: Dict[str, Any]):
|
def _set_task_params(self, data: dict[str, Any]):
|
||||||
if "from_task" in data and (task := data["from_task"]):
|
if "from_task" in data and (task := data["from_task"]):
|
||||||
self.task_id = task.id
|
self.task_id = task.id
|
||||||
self.task_name = task.name or task.description
|
self.task_name = task.name or task.description
|
||||||
self.from_task = None
|
self.from_task = None
|
||||||
|
|
||||||
def _set_agent_params(self, data: Dict[str, Any]):
|
def _set_agent_params(self, data: dict[str, Any]):
|
||||||
task = data.get("from_task", None)
|
task = data.get("from_task", None)
|
||||||
agent = task.agent if task else data.get("from_agent", None)
|
agent = task.agent if task else data.get("from_agent", None)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
from collections.abc import Callable
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from typing import Any, Callable, Dict, List, Type, TypeVar, cast
|
from typing import Any, TypeVar, cast
|
||||||
|
|
||||||
from blinker import Signal
|
from blinker import Signal
|
||||||
|
|
||||||
@@ -25,17 +26,17 @@ class CrewAIEventsBus:
|
|||||||
if cls._instance is None:
|
if cls._instance is None:
|
||||||
with cls._lock:
|
with cls._lock:
|
||||||
if cls._instance is None: # prevent race condition
|
if cls._instance is None: # prevent race condition
|
||||||
cls._instance = super(CrewAIEventsBus, cls).__new__(cls)
|
cls._instance = super().__new__(cls)
|
||||||
cls._instance._initialize()
|
cls._instance._initialize()
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
||||||
def _initialize(self) -> None:
|
def _initialize(self) -> None:
|
||||||
"""Initialize the event bus internal state"""
|
"""Initialize the event bus internal state"""
|
||||||
self._signal = Signal("crewai_event_bus")
|
self._signal = Signal("crewai_event_bus")
|
||||||
self._handlers: Dict[Type[BaseEvent], List[Callable]] = {}
|
self._handlers: dict[type[BaseEvent], list[Callable]] = {}
|
||||||
|
|
||||||
def on(
|
def on(
|
||||||
self, event_type: Type[EventT]
|
self, event_type: type[EventT]
|
||||||
) -> Callable[[Callable[[Any, EventT], None]], Callable[[Any, EventT], None]]:
|
) -> Callable[[Callable[[Any, EventT], None]], Callable[[Any, EventT], None]]:
|
||||||
"""
|
"""
|
||||||
Decorator to register an event handler for a specific event type.
|
Decorator to register an event handler for a specific event type.
|
||||||
@@ -61,6 +62,18 @@ class CrewAIEventsBus:
|
|||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _call_handler(
|
||||||
|
handler: Callable, source: Any, event: BaseEvent, event_type: type
|
||||||
|
) -> None:
|
||||||
|
"""Call a single handler with error handling."""
|
||||||
|
try:
|
||||||
|
handler(source, event)
|
||||||
|
except Exception as e:
|
||||||
|
print(
|
||||||
|
f"[EventBus Error] Handler '{handler.__name__}' failed for event '{event_type.__name__}': {e}"
|
||||||
|
)
|
||||||
|
|
||||||
def emit(self, source: Any, event: BaseEvent) -> None:
|
def emit(self, source: Any, event: BaseEvent) -> None:
|
||||||
"""
|
"""
|
||||||
Emit an event to all registered handlers
|
Emit an event to all registered handlers
|
||||||
@@ -72,17 +85,12 @@ class CrewAIEventsBus:
|
|||||||
for event_type, handlers in self._handlers.items():
|
for event_type, handlers in self._handlers.items():
|
||||||
if isinstance(event, event_type):
|
if isinstance(event, event_type):
|
||||||
for handler in handlers:
|
for handler in handlers:
|
||||||
try:
|
self._call_handler(handler, source, event, event_type)
|
||||||
handler(source, event)
|
|
||||||
except Exception as e:
|
|
||||||
print(
|
|
||||||
f"[EventBus Error] Handler '{handler.__name__}' failed for event '{event_type.__name__}': {e}"
|
|
||||||
)
|
|
||||||
|
|
||||||
self._signal.send(source, event=event)
|
self._signal.send(source, event=event)
|
||||||
|
|
||||||
def register_handler(
|
def register_handler(
|
||||||
self, event_type: Type[EventTypes], handler: Callable[[Any, EventTypes], None]
|
self, event_type: type[EventTypes], handler: Callable[[Any, EventTypes], None]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Register an event handler for a specific event type"""
|
"""Register an event handler for a specific event type"""
|
||||||
if event_type not in self._handlers:
|
if event_type not in self._handlers:
|
||||||
|
|||||||
@@ -1,15 +1,30 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from typing import Any, Dict
|
from typing import Any
|
||||||
|
|
||||||
from pydantic import Field, PrivateAttr
|
from pydantic import Field, PrivateAttr
|
||||||
from crewai.llm import LLM
|
|
||||||
from crewai.task import Task
|
|
||||||
from crewai.telemetry.telemetry import Telemetry
|
|
||||||
from crewai.utilities import Logger
|
|
||||||
from crewai.utilities.constants import EMITTER_COLOR
|
|
||||||
from crewai.events.base_event_listener import BaseEventListener
|
from crewai.events.base_event_listener import BaseEventListener
|
||||||
|
from crewai.events.types.agent_events import (
|
||||||
|
AgentExecutionCompletedEvent,
|
||||||
|
AgentExecutionStartedEvent,
|
||||||
|
LiteAgentExecutionCompletedEvent,
|
||||||
|
LiteAgentExecutionErrorEvent,
|
||||||
|
LiteAgentExecutionStartedEvent,
|
||||||
|
)
|
||||||
|
from crewai.events.types.crew_events import (
|
||||||
|
CrewKickoffCompletedEvent,
|
||||||
|
CrewKickoffFailedEvent,
|
||||||
|
CrewKickoffStartedEvent,
|
||||||
|
CrewTestCompletedEvent,
|
||||||
|
CrewTestFailedEvent,
|
||||||
|
CrewTestResultEvent,
|
||||||
|
CrewTestStartedEvent,
|
||||||
|
CrewTrainCompletedEvent,
|
||||||
|
CrewTrainFailedEvent,
|
||||||
|
CrewTrainStartedEvent,
|
||||||
|
)
|
||||||
from crewai.events.types.knowledge_events import (
|
from crewai.events.types.knowledge_events import (
|
||||||
KnowledgeQueryCompletedEvent,
|
KnowledgeQueryCompletedEvent,
|
||||||
KnowledgeQueryFailedEvent,
|
KnowledgeQueryFailedEvent,
|
||||||
@@ -25,34 +40,21 @@ from crewai.events.types.llm_events import (
|
|||||||
LLMStreamChunkEvent,
|
LLMStreamChunkEvent,
|
||||||
)
|
)
|
||||||
from crewai.events.types.llm_guardrail_events import (
|
from crewai.events.types.llm_guardrail_events import (
|
||||||
LLMGuardrailStartedEvent,
|
|
||||||
LLMGuardrailCompletedEvent,
|
LLMGuardrailCompletedEvent,
|
||||||
)
|
LLMGuardrailStartedEvent,
|
||||||
from crewai.events.utils.console_formatter import ConsoleFormatter
|
|
||||||
|
|
||||||
from crewai.events.types.agent_events import (
|
|
||||||
AgentExecutionCompletedEvent,
|
|
||||||
AgentExecutionStartedEvent,
|
|
||||||
LiteAgentExecutionCompletedEvent,
|
|
||||||
LiteAgentExecutionErrorEvent,
|
|
||||||
LiteAgentExecutionStartedEvent,
|
|
||||||
)
|
)
|
||||||
from crewai.events.types.logging_events import (
|
from crewai.events.types.logging_events import (
|
||||||
AgentLogsStartedEvent,
|
|
||||||
AgentLogsExecutionEvent,
|
AgentLogsExecutionEvent,
|
||||||
|
AgentLogsStartedEvent,
|
||||||
)
|
)
|
||||||
from crewai.events.types.crew_events import (
|
from crewai.events.utils.console_formatter import ConsoleFormatter
|
||||||
CrewKickoffCompletedEvent,
|
from crewai.llm import LLM
|
||||||
CrewKickoffFailedEvent,
|
from crewai.task import Task
|
||||||
CrewKickoffStartedEvent,
|
from crewai.telemetry.telemetry import Telemetry
|
||||||
CrewTestCompletedEvent,
|
from crewai.utilities import Logger
|
||||||
CrewTestFailedEvent,
|
from crewai.utilities.constants import EMITTER_COLOR
|
||||||
CrewTestResultEvent,
|
|
||||||
CrewTestStartedEvent,
|
from .listeners.memory_listener import MemoryListener
|
||||||
CrewTrainCompletedEvent,
|
|
||||||
CrewTrainFailedEvent,
|
|
||||||
CrewTrainStartedEvent,
|
|
||||||
)
|
|
||||||
from .types.flow_events import (
|
from .types.flow_events import (
|
||||||
FlowCreatedEvent,
|
FlowCreatedEvent,
|
||||||
FlowFinishedEvent,
|
FlowFinishedEvent,
|
||||||
@@ -61,26 +63,24 @@ from .types.flow_events import (
|
|||||||
MethodExecutionFinishedEvent,
|
MethodExecutionFinishedEvent,
|
||||||
MethodExecutionStartedEvent,
|
MethodExecutionStartedEvent,
|
||||||
)
|
)
|
||||||
|
from .types.reasoning_events import (
|
||||||
|
AgentReasoningCompletedEvent,
|
||||||
|
AgentReasoningFailedEvent,
|
||||||
|
AgentReasoningStartedEvent,
|
||||||
|
)
|
||||||
from .types.task_events import TaskCompletedEvent, TaskFailedEvent, TaskStartedEvent
|
from .types.task_events import TaskCompletedEvent, TaskFailedEvent, TaskStartedEvent
|
||||||
from .types.tool_usage_events import (
|
from .types.tool_usage_events import (
|
||||||
ToolUsageErrorEvent,
|
ToolUsageErrorEvent,
|
||||||
ToolUsageFinishedEvent,
|
ToolUsageFinishedEvent,
|
||||||
ToolUsageStartedEvent,
|
ToolUsageStartedEvent,
|
||||||
)
|
)
|
||||||
from .types.reasoning_events import (
|
|
||||||
AgentReasoningStartedEvent,
|
|
||||||
AgentReasoningCompletedEvent,
|
|
||||||
AgentReasoningFailedEvent,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .listeners.memory_listener import MemoryListener
|
|
||||||
|
|
||||||
|
|
||||||
class EventListener(BaseEventListener):
|
class EventListener(BaseEventListener):
|
||||||
_instance = None
|
_instance = None
|
||||||
_telemetry: Telemetry = PrivateAttr(default_factory=lambda: Telemetry())
|
_telemetry: Telemetry = PrivateAttr(default_factory=lambda: Telemetry())
|
||||||
logger = Logger(verbose=True, default_color=EMITTER_COLOR)
|
logger = Logger(verbose=True, default_color=EMITTER_COLOR)
|
||||||
execution_spans: Dict[Task, Any] = Field(default_factory=dict)
|
execution_spans: dict[Task, Any] = Field(default_factory=dict)
|
||||||
next_chunk = 0
|
next_chunk = 0
|
||||||
text_stream = StringIO()
|
text_stream = StringIO()
|
||||||
knowledge_retrieval_in_progress = False
|
knowledge_retrieval_in_progress = False
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
from typing import Union
|
|
||||||
|
|
||||||
from crewai.events.types.agent_events import (
|
from crewai.events.types.agent_events import (
|
||||||
AgentExecutionCompletedEvent,
|
AgentExecutionCompletedEvent,
|
||||||
AgentExecutionErrorEvent,
|
AgentExecutionErrorEvent,
|
||||||
AgentExecutionStartedEvent,
|
AgentExecutionStartedEvent,
|
||||||
LiteAgentExecutionCompletedEvent,
|
LiteAgentExecutionCompletedEvent,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .types.crew_events import (
|
from .types.crew_events import (
|
||||||
CrewKickoffCompletedEvent,
|
CrewKickoffCompletedEvent,
|
||||||
CrewKickoffFailedEvent,
|
CrewKickoffFailedEvent,
|
||||||
@@ -24,6 +23,14 @@ from .types.flow_events import (
|
|||||||
MethodExecutionFinishedEvent,
|
MethodExecutionFinishedEvent,
|
||||||
MethodExecutionStartedEvent,
|
MethodExecutionStartedEvent,
|
||||||
)
|
)
|
||||||
|
from .types.knowledge_events import (
|
||||||
|
KnowledgeQueryCompletedEvent,
|
||||||
|
KnowledgeQueryFailedEvent,
|
||||||
|
KnowledgeQueryStartedEvent,
|
||||||
|
KnowledgeRetrievalCompletedEvent,
|
||||||
|
KnowledgeRetrievalStartedEvent,
|
||||||
|
KnowledgeSearchQueryFailedEvent,
|
||||||
|
)
|
||||||
from .types.llm_events import (
|
from .types.llm_events import (
|
||||||
LLMCallCompletedEvent,
|
LLMCallCompletedEvent,
|
||||||
LLMCallFailedEvent,
|
LLMCallFailedEvent,
|
||||||
@@ -34,6 +41,21 @@ from .types.llm_guardrail_events import (
|
|||||||
LLMGuardrailCompletedEvent,
|
LLMGuardrailCompletedEvent,
|
||||||
LLMGuardrailStartedEvent,
|
LLMGuardrailStartedEvent,
|
||||||
)
|
)
|
||||||
|
from .types.memory_events import (
|
||||||
|
MemoryQueryCompletedEvent,
|
||||||
|
MemoryQueryFailedEvent,
|
||||||
|
MemoryQueryStartedEvent,
|
||||||
|
MemoryRetrievalCompletedEvent,
|
||||||
|
MemoryRetrievalStartedEvent,
|
||||||
|
MemorySaveCompletedEvent,
|
||||||
|
MemorySaveFailedEvent,
|
||||||
|
MemorySaveStartedEvent,
|
||||||
|
)
|
||||||
|
from .types.reasoning_events import (
|
||||||
|
AgentReasoningCompletedEvent,
|
||||||
|
AgentReasoningFailedEvent,
|
||||||
|
AgentReasoningStartedEvent,
|
||||||
|
)
|
||||||
from .types.task_events import (
|
from .types.task_events import (
|
||||||
TaskCompletedEvent,
|
TaskCompletedEvent,
|
||||||
TaskFailedEvent,
|
TaskFailedEvent,
|
||||||
@@ -44,77 +66,53 @@ from .types.tool_usage_events import (
|
|||||||
ToolUsageFinishedEvent,
|
ToolUsageFinishedEvent,
|
||||||
ToolUsageStartedEvent,
|
ToolUsageStartedEvent,
|
||||||
)
|
)
|
||||||
from .types.reasoning_events import (
|
|
||||||
AgentReasoningStartedEvent,
|
|
||||||
AgentReasoningCompletedEvent,
|
|
||||||
AgentReasoningFailedEvent,
|
|
||||||
)
|
|
||||||
from .types.knowledge_events import (
|
|
||||||
KnowledgeRetrievalStartedEvent,
|
|
||||||
KnowledgeRetrievalCompletedEvent,
|
|
||||||
KnowledgeQueryStartedEvent,
|
|
||||||
KnowledgeQueryCompletedEvent,
|
|
||||||
KnowledgeQueryFailedEvent,
|
|
||||||
KnowledgeSearchQueryFailedEvent,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .types.memory_events import (
|
EventTypes = (
|
||||||
MemorySaveStartedEvent,
|
CrewKickoffStartedEvent
|
||||||
MemorySaveCompletedEvent,
|
| CrewKickoffCompletedEvent
|
||||||
MemorySaveFailedEvent,
|
| CrewKickoffFailedEvent
|
||||||
MemoryQueryStartedEvent,
|
| CrewTestStartedEvent
|
||||||
MemoryQueryCompletedEvent,
|
| CrewTestCompletedEvent
|
||||||
MemoryQueryFailedEvent,
|
| CrewTestFailedEvent
|
||||||
MemoryRetrievalStartedEvent,
|
| CrewTrainStartedEvent
|
||||||
MemoryRetrievalCompletedEvent,
|
| CrewTrainCompletedEvent
|
||||||
|
| CrewTrainFailedEvent
|
||||||
|
| AgentExecutionStartedEvent
|
||||||
|
| AgentExecutionCompletedEvent
|
||||||
|
| LiteAgentExecutionCompletedEvent
|
||||||
|
| TaskStartedEvent
|
||||||
|
| TaskCompletedEvent
|
||||||
|
| TaskFailedEvent
|
||||||
|
| FlowStartedEvent
|
||||||
|
| FlowFinishedEvent
|
||||||
|
| MethodExecutionStartedEvent
|
||||||
|
| MethodExecutionFinishedEvent
|
||||||
|
| MethodExecutionFailedEvent
|
||||||
|
| AgentExecutionErrorEvent
|
||||||
|
| ToolUsageFinishedEvent
|
||||||
|
| ToolUsageErrorEvent
|
||||||
|
| ToolUsageStartedEvent
|
||||||
|
| LLMCallStartedEvent
|
||||||
|
| LLMCallCompletedEvent
|
||||||
|
| LLMCallFailedEvent
|
||||||
|
| LLMStreamChunkEvent
|
||||||
|
| LLMGuardrailStartedEvent
|
||||||
|
| LLMGuardrailCompletedEvent
|
||||||
|
| AgentReasoningStartedEvent
|
||||||
|
| AgentReasoningCompletedEvent
|
||||||
|
| AgentReasoningFailedEvent
|
||||||
|
| KnowledgeRetrievalStartedEvent
|
||||||
|
| KnowledgeRetrievalCompletedEvent
|
||||||
|
| KnowledgeQueryStartedEvent
|
||||||
|
| KnowledgeQueryCompletedEvent
|
||||||
|
| KnowledgeQueryFailedEvent
|
||||||
|
| KnowledgeSearchQueryFailedEvent
|
||||||
|
| MemorySaveStartedEvent
|
||||||
|
| MemorySaveCompletedEvent
|
||||||
|
| MemorySaveFailedEvent
|
||||||
|
| MemoryQueryStartedEvent
|
||||||
|
| MemoryQueryCompletedEvent
|
||||||
|
| MemoryQueryFailedEvent
|
||||||
|
| MemoryRetrievalStartedEvent
|
||||||
|
| MemoryRetrievalCompletedEvent
|
||||||
)
|
)
|
||||||
|
|
||||||
EventTypes = Union[
|
|
||||||
CrewKickoffStartedEvent,
|
|
||||||
CrewKickoffCompletedEvent,
|
|
||||||
CrewKickoffFailedEvent,
|
|
||||||
CrewTestStartedEvent,
|
|
||||||
CrewTestCompletedEvent,
|
|
||||||
CrewTestFailedEvent,
|
|
||||||
CrewTrainStartedEvent,
|
|
||||||
CrewTrainCompletedEvent,
|
|
||||||
CrewTrainFailedEvent,
|
|
||||||
AgentExecutionStartedEvent,
|
|
||||||
AgentExecutionCompletedEvent,
|
|
||||||
LiteAgentExecutionCompletedEvent,
|
|
||||||
TaskStartedEvent,
|
|
||||||
TaskCompletedEvent,
|
|
||||||
TaskFailedEvent,
|
|
||||||
FlowStartedEvent,
|
|
||||||
FlowFinishedEvent,
|
|
||||||
MethodExecutionStartedEvent,
|
|
||||||
MethodExecutionFinishedEvent,
|
|
||||||
MethodExecutionFailedEvent,
|
|
||||||
AgentExecutionErrorEvent,
|
|
||||||
ToolUsageFinishedEvent,
|
|
||||||
ToolUsageErrorEvent,
|
|
||||||
ToolUsageStartedEvent,
|
|
||||||
LLMCallStartedEvent,
|
|
||||||
LLMCallCompletedEvent,
|
|
||||||
LLMCallFailedEvent,
|
|
||||||
LLMStreamChunkEvent,
|
|
||||||
LLMGuardrailStartedEvent,
|
|
||||||
LLMGuardrailCompletedEvent,
|
|
||||||
AgentReasoningStartedEvent,
|
|
||||||
AgentReasoningCompletedEvent,
|
|
||||||
AgentReasoningFailedEvent,
|
|
||||||
KnowledgeRetrievalStartedEvent,
|
|
||||||
KnowledgeRetrievalCompletedEvent,
|
|
||||||
KnowledgeQueryStartedEvent,
|
|
||||||
KnowledgeQueryCompletedEvent,
|
|
||||||
KnowledgeQueryFailedEvent,
|
|
||||||
KnowledgeSearchQueryFailedEvent,
|
|
||||||
MemorySaveStartedEvent,
|
|
||||||
MemorySaveCompletedEvent,
|
|
||||||
MemorySaveFailedEvent,
|
|
||||||
MemoryQueryStartedEvent,
|
|
||||||
MemoryQueryCompletedEvent,
|
|
||||||
MemoryQueryFailedEvent,
|
|
||||||
MemoryRetrievalStartedEvent,
|
|
||||||
MemoryRetrievalCompletedEvent,
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
This module contains various event listener implementations
|
This module contains various event listener implementations
|
||||||
for handling memory, tracing, and other event-driven functionality.
|
for handling memory, tracing, and other event-driven functionality.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
from crewai.events.base_event_listener import BaseEventListener
|
from crewai.events.base_event_listener import BaseEventListener
|
||||||
from crewai.events.types.memory_events import (
|
from crewai.events.types.memory_events import (
|
||||||
|
MemoryQueryCompletedEvent,
|
||||||
|
MemoryQueryFailedEvent,
|
||||||
MemoryRetrievalCompletedEvent,
|
MemoryRetrievalCompletedEvent,
|
||||||
MemoryRetrievalStartedEvent,
|
MemoryRetrievalStartedEvent,
|
||||||
MemoryQueryFailedEvent,
|
|
||||||
MemoryQueryCompletedEvent,
|
|
||||||
MemorySaveStartedEvent,
|
|
||||||
MemorySaveCompletedEvent,
|
MemorySaveCompletedEvent,
|
||||||
MemorySaveFailedEvent,
|
MemorySaveFailedEvent,
|
||||||
|
MemorySaveStartedEvent,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from dataclasses import dataclass, field, asdict
|
|
||||||
from datetime import datetime, timezone
|
|
||||||
from typing import Dict, Any
|
|
||||||
import uuid
|
import uuid
|
||||||
|
from dataclasses import asdict, dataclass, field
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -13,7 +13,7 @@ class TraceEvent:
|
|||||||
default_factory=lambda: datetime.now(timezone.utc).isoformat()
|
default_factory=lambda: datetime.now(timezone.utc).isoformat()
|
||||||
)
|
)
|
||||||
type: str = ""
|
type: str = ""
|
||||||
event_data: Dict[str, Any] = field(default_factory=dict)
|
event_data: dict[str, Any] = field(default_factory=dict)
|
||||||
|
|
||||||
def to_dict(self) -> Dict[str, Any]:
|
def to_dict(self) -> dict[str, Any]:
|
||||||
return asdict(self)
|
return asdict(self)
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
This module contains all event types used throughout the CrewAI system
|
This module contains all event types used throughout the CrewAI system
|
||||||
for monitoring and extending agent, crew, task, and tool execution.
|
for monitoring and extending agent, crew, task, and tool execution.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -2,14 +2,15 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, Dict, List, Optional, Sequence, Union
|
from collections.abc import Sequence
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from pydantic import model_validator
|
from pydantic import ConfigDict, model_validator
|
||||||
|
|
||||||
from crewai.agents.agent_builder.base_agent import BaseAgent
|
from crewai.agents.agent_builder.base_agent import BaseAgent
|
||||||
|
from crewai.events.base_events import BaseEvent
|
||||||
from crewai.tools.base_tool import BaseTool
|
from crewai.tools.base_tool import BaseTool
|
||||||
from crewai.tools.structured_tool import CrewStructuredTool
|
from crewai.tools.structured_tool import CrewStructuredTool
|
||||||
from crewai.events.base_events import BaseEvent
|
|
||||||
|
|
||||||
|
|
||||||
class AgentExecutionStartedEvent(BaseEvent):
|
class AgentExecutionStartedEvent(BaseEvent):
|
||||||
@@ -17,11 +18,11 @@ class AgentExecutionStartedEvent(BaseEvent):
|
|||||||
|
|
||||||
agent: BaseAgent
|
agent: BaseAgent
|
||||||
task: Any
|
task: Any
|
||||||
tools: Optional[Sequence[Union[BaseTool, CrewStructuredTool]]]
|
tools: Sequence[BaseTool | CrewStructuredTool] | None
|
||||||
task_prompt: str
|
task_prompt: str
|
||||||
type: str = "agent_execution_started"
|
type: str = "agent_execution_started"
|
||||||
|
|
||||||
model_config = {"arbitrary_types_allowed": True}
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||||
|
|
||||||
@model_validator(mode="after")
|
@model_validator(mode="after")
|
||||||
def set_fingerprint_data(self):
|
def set_fingerprint_data(self):
|
||||||
@@ -45,7 +46,7 @@ class AgentExecutionCompletedEvent(BaseEvent):
|
|||||||
output: str
|
output: str
|
||||||
type: str = "agent_execution_completed"
|
type: str = "agent_execution_completed"
|
||||||
|
|
||||||
model_config = {"arbitrary_types_allowed": True}
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||||
|
|
||||||
@model_validator(mode="after")
|
@model_validator(mode="after")
|
||||||
def set_fingerprint_data(self):
|
def set_fingerprint_data(self):
|
||||||
@@ -69,7 +70,7 @@ class AgentExecutionErrorEvent(BaseEvent):
|
|||||||
error: str
|
error: str
|
||||||
type: str = "agent_execution_error"
|
type: str = "agent_execution_error"
|
||||||
|
|
||||||
model_config = {"arbitrary_types_allowed": True}
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||||
|
|
||||||
@model_validator(mode="after")
|
@model_validator(mode="after")
|
||||||
def set_fingerprint_data(self):
|
def set_fingerprint_data(self):
|
||||||
@@ -89,18 +90,18 @@ class AgentExecutionErrorEvent(BaseEvent):
|
|||||||
class LiteAgentExecutionStartedEvent(BaseEvent):
|
class LiteAgentExecutionStartedEvent(BaseEvent):
|
||||||
"""Event emitted when a LiteAgent starts executing"""
|
"""Event emitted when a LiteAgent starts executing"""
|
||||||
|
|
||||||
agent_info: Dict[str, Any]
|
agent_info: dict[str, Any]
|
||||||
tools: Optional[Sequence[Union[BaseTool, CrewStructuredTool]]]
|
tools: Sequence[BaseTool | CrewStructuredTool] | None
|
||||||
messages: Union[str, List[Dict[str, str]]]
|
messages: str | list[dict[str, str]]
|
||||||
type: str = "lite_agent_execution_started"
|
type: str = "lite_agent_execution_started"
|
||||||
|
|
||||||
model_config = {"arbitrary_types_allowed": True}
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||||
|
|
||||||
|
|
||||||
class LiteAgentExecutionCompletedEvent(BaseEvent):
|
class LiteAgentExecutionCompletedEvent(BaseEvent):
|
||||||
"""Event emitted when a LiteAgent completes execution"""
|
"""Event emitted when a LiteAgent completes execution"""
|
||||||
|
|
||||||
agent_info: Dict[str, Any]
|
agent_info: dict[str, Any]
|
||||||
output: str
|
output: str
|
||||||
type: str = "lite_agent_execution_completed"
|
type: str = "lite_agent_execution_completed"
|
||||||
|
|
||||||
@@ -108,7 +109,7 @@ class LiteAgentExecutionCompletedEvent(BaseEvent):
|
|||||||
class LiteAgentExecutionErrorEvent(BaseEvent):
|
class LiteAgentExecutionErrorEvent(BaseEvent):
|
||||||
"""Event emitted when a LiteAgent encounters an error during execution"""
|
"""Event emitted when a LiteAgent encounters an error during execution"""
|
||||||
|
|
||||||
agent_info: Dict[str, Any]
|
agent_info: dict[str, Any]
|
||||||
error: str
|
error: str
|
||||||
type: str = "lite_agent_execution_error"
|
type: str = "lite_agent_execution_error"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from crewai.events.base_events import BaseEvent
|
from crewai.events.base_events import BaseEvent
|
||||||
|
|
||||||
@@ -11,8 +11,8 @@ else:
|
|||||||
class CrewBaseEvent(BaseEvent):
|
class CrewBaseEvent(BaseEvent):
|
||||||
"""Base class for crew events with fingerprint handling"""
|
"""Base class for crew events with fingerprint handling"""
|
||||||
|
|
||||||
crew_name: Optional[str]
|
crew_name: str | None
|
||||||
crew: Optional[Crew] = None
|
crew: Crew | None = None
|
||||||
|
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
super().__init__(**data)
|
super().__init__(**data)
|
||||||
@@ -38,7 +38,7 @@ class CrewBaseEvent(BaseEvent):
|
|||||||
class CrewKickoffStartedEvent(CrewBaseEvent):
|
class CrewKickoffStartedEvent(CrewBaseEvent):
|
||||||
"""Event emitted when a crew starts execution"""
|
"""Event emitted when a crew starts execution"""
|
||||||
|
|
||||||
inputs: Optional[Dict[str, Any]]
|
inputs: dict[str, Any] | None
|
||||||
type: str = "crew_kickoff_started"
|
type: str = "crew_kickoff_started"
|
||||||
|
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ class CrewTrainStartedEvent(CrewBaseEvent):
|
|||||||
|
|
||||||
n_iterations: int
|
n_iterations: int
|
||||||
filename: str
|
filename: str
|
||||||
inputs: Optional[Dict[str, Any]]
|
inputs: dict[str, Any] | None
|
||||||
type: str = "crew_train_started"
|
type: str = "crew_train_started"
|
||||||
|
|
||||||
|
|
||||||
@@ -85,8 +85,8 @@ class CrewTestStartedEvent(CrewBaseEvent):
|
|||||||
"""Event emitted when a crew starts testing"""
|
"""Event emitted when a crew starts testing"""
|
||||||
|
|
||||||
n_iterations: int
|
n_iterations: int
|
||||||
eval_llm: Optional[Union[str, Any]]
|
eval_llm: str | Any | None
|
||||||
inputs: Optional[Dict[str, Any]]
|
inputs: dict[str, Any] | None
|
||||||
type: str = "crew_test_started"
|
type: str = "crew_test_started"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Any, Dict, Optional, Union
|
from typing import Any
|
||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ class FlowStartedEvent(FlowEvent):
|
|||||||
"""Event emitted when a flow starts execution"""
|
"""Event emitted when a flow starts execution"""
|
||||||
|
|
||||||
flow_name: str
|
flow_name: str
|
||||||
inputs: Optional[Dict[str, Any]] = None
|
inputs: dict[str, Any] | None = None
|
||||||
type: str = "flow_started"
|
type: str = "flow_started"
|
||||||
|
|
||||||
|
|
||||||
@@ -32,8 +32,8 @@ class MethodExecutionStartedEvent(FlowEvent):
|
|||||||
|
|
||||||
flow_name: str
|
flow_name: str
|
||||||
method_name: str
|
method_name: str
|
||||||
state: Union[Dict[str, Any], BaseModel]
|
state: dict[str, Any] | BaseModel
|
||||||
params: Optional[Dict[str, Any]] = None
|
params: dict[str, Any] | None = None
|
||||||
type: str = "method_execution_started"
|
type: str = "method_execution_started"
|
||||||
|
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ class MethodExecutionFinishedEvent(FlowEvent):
|
|||||||
flow_name: str
|
flow_name: str
|
||||||
method_name: str
|
method_name: str
|
||||||
result: Any = None
|
result: Any = None
|
||||||
state: Union[Dict[str, Any], BaseModel]
|
state: dict[str, Any] | BaseModel
|
||||||
type: str = "method_execution_finished"
|
type: str = "method_execution_finished"
|
||||||
|
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ class FlowFinishedEvent(FlowEvent):
|
|||||||
"""Event emitted when a flow completes execution"""
|
"""Event emitted when a flow completes execution"""
|
||||||
|
|
||||||
flow_name: str
|
flow_name: str
|
||||||
result: Optional[Any] = None
|
result: Any | None = None
|
||||||
type: str = "flow_finished"
|
type: str = "flow_finished"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from crewai.events.base_events import BaseEvent
|
|
||||||
|
|
||||||
from crewai.agents.agent_builder.base_agent import BaseAgent
|
from crewai.agents.agent_builder.base_agent import BaseAgent
|
||||||
|
from crewai.events.base_events import BaseEvent
|
||||||
|
|
||||||
|
|
||||||
class KnowledgeRetrievalStartedEvent(BaseEvent):
|
class KnowledgeRetrievalStartedEvent(BaseEvent):
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Any
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
@@ -7,14 +7,14 @@ from crewai.events.base_events import BaseEvent
|
|||||||
|
|
||||||
|
|
||||||
class LLMEventBase(BaseEvent):
|
class LLMEventBase(BaseEvent):
|
||||||
task_name: Optional[str] = None
|
task_name: str | None = None
|
||||||
task_id: Optional[str] = None
|
task_id: str | None = None
|
||||||
|
|
||||||
agent_id: Optional[str] = None
|
agent_id: str | None = None
|
||||||
agent_role: Optional[str] = None
|
agent_role: str | None = None
|
||||||
|
|
||||||
from_task: Optional[Any] = None
|
from_task: Any | None = None
|
||||||
from_agent: Optional[Any] = None
|
from_agent: Any | None = None
|
||||||
|
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
super().__init__(**data)
|
super().__init__(**data)
|
||||||
@@ -38,11 +38,11 @@ class LLMCallStartedEvent(LLMEventBase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
type: str = "llm_call_started"
|
type: str = "llm_call_started"
|
||||||
model: Optional[str] = None
|
model: str | None = None
|
||||||
messages: Optional[Union[str, List[Dict[str, Any]]]] = None
|
messages: str | list[dict[str, Any]] | None = None
|
||||||
tools: Optional[List[dict[str, Any]]] = None
|
tools: list[dict[str, Any]] | None = None
|
||||||
callbacks: Optional[List[Any]] = None
|
callbacks: list[Any] | None = None
|
||||||
available_functions: Optional[Dict[str, Any]] = None
|
available_functions: dict[str, Any] | None = None
|
||||||
|
|
||||||
|
|
||||||
class LLMCallCompletedEvent(LLMEventBase):
|
class LLMCallCompletedEvent(LLMEventBase):
|
||||||
@@ -52,7 +52,7 @@ class LLMCallCompletedEvent(LLMEventBase):
|
|||||||
messages: str | list[dict[str, Any]] | None = None
|
messages: str | list[dict[str, Any]] | None = None
|
||||||
response: Any
|
response: Any
|
||||||
call_type: LLMCallType
|
call_type: LLMCallType
|
||||||
model: Optional[str] = None
|
model: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class LLMCallFailedEvent(LLMEventBase):
|
class LLMCallFailedEvent(LLMEventBase):
|
||||||
@@ -64,13 +64,13 @@ class LLMCallFailedEvent(LLMEventBase):
|
|||||||
|
|
||||||
class FunctionCall(BaseModel):
|
class FunctionCall(BaseModel):
|
||||||
arguments: str
|
arguments: str
|
||||||
name: Optional[str] = None
|
name: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class ToolCall(BaseModel):
|
class ToolCall(BaseModel):
|
||||||
id: Optional[str] = None
|
id: str | None = None
|
||||||
function: FunctionCall
|
function: FunctionCall
|
||||||
type: Optional[str] = None
|
type: str | None = None
|
||||||
index: int
|
index: int
|
||||||
|
|
||||||
|
|
||||||
@@ -79,4 +79,4 @@ class LLMStreamChunkEvent(LLMEventBase):
|
|||||||
|
|
||||||
type: str = "llm_stream_chunk"
|
type: str = "llm_stream_chunk"
|
||||||
chunk: str
|
chunk: str
|
||||||
tool_call: Optional[ToolCall] = None
|
tool_call: ToolCall | None = None
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
from collections.abc import Callable
|
||||||
from inspect import getsource
|
from inspect import getsource
|
||||||
from typing import Any, Callable, Optional, Union
|
from typing import Any
|
||||||
|
|
||||||
from crewai.events.base_events import BaseEvent
|
from crewai.events.base_events import BaseEvent
|
||||||
|
|
||||||
@@ -13,12 +14,12 @@ class LLMGuardrailStartedEvent(BaseEvent):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
type: str = "llm_guardrail_started"
|
type: str = "llm_guardrail_started"
|
||||||
guardrail: Union[str, Callable]
|
guardrail: str | Callable
|
||||||
retry_count: int
|
retry_count: int
|
||||||
|
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
from crewai.tasks.llm_guardrail import LLMGuardrail
|
|
||||||
from crewai.tasks.hallucination_guardrail import HallucinationGuardrail
|
from crewai.tasks.hallucination_guardrail import HallucinationGuardrail
|
||||||
|
from crewai.tasks.llm_guardrail import LLMGuardrail
|
||||||
|
|
||||||
super().__init__(**data)
|
super().__init__(**data)
|
||||||
|
|
||||||
@@ -41,5 +42,5 @@ class LLMGuardrailCompletedEvent(BaseEvent):
|
|||||||
type: str = "llm_guardrail_completed"
|
type: str = "llm_guardrail_completed"
|
||||||
success: bool
|
success: bool
|
||||||
result: Any
|
result: Any
|
||||||
error: Optional[str] = None
|
error: str | None = None
|
||||||
retry_count: int
|
retry_count: int
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
"""Agent logging events that don't reference BaseAgent to avoid circular imports."""
|
"""Agent logging events that don't reference BaseAgent to avoid circular imports."""
|
||||||
|
|
||||||
from typing import Any, Optional
|
from typing import Any
|
||||||
|
|
||||||
|
from pydantic import ConfigDict
|
||||||
|
|
||||||
from crewai.events.base_events import BaseEvent
|
from crewai.events.base_events import BaseEvent
|
||||||
|
|
||||||
@@ -9,7 +11,7 @@ class AgentLogsStartedEvent(BaseEvent):
|
|||||||
"""Event emitted when agent logs should be shown at start"""
|
"""Event emitted when agent logs should be shown at start"""
|
||||||
|
|
||||||
agent_role: str
|
agent_role: str
|
||||||
task_description: Optional[str] = None
|
task_description: str | None = None
|
||||||
verbose: bool = False
|
verbose: bool = False
|
||||||
type: str = "agent_logs_started"
|
type: str = "agent_logs_started"
|
||||||
|
|
||||||
@@ -22,4 +24,4 @@ class AgentLogsExecutionEvent(BaseEvent):
|
|||||||
verbose: bool = False
|
verbose: bool = False
|
||||||
type: str = "agent_logs_execution"
|
type: str = "agent_logs_execution"
|
||||||
|
|
||||||
model_config = {"arbitrary_types_allowed": True}
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Any, Dict, Optional
|
from typing import Any
|
||||||
|
|
||||||
from crewai.events.base_events import BaseEvent
|
from crewai.events.base_events import BaseEvent
|
||||||
|
|
||||||
@@ -7,12 +7,12 @@ class MemoryBaseEvent(BaseEvent):
|
|||||||
"""Base event for memory operations"""
|
"""Base event for memory operations"""
|
||||||
|
|
||||||
type: str
|
type: str
|
||||||
task_id: Optional[str] = None
|
task_id: str | None = None
|
||||||
task_name: Optional[str] = None
|
task_name: str | None = None
|
||||||
from_task: Optional[Any] = None
|
from_task: Any | None = None
|
||||||
from_agent: Optional[Any] = None
|
from_agent: Any | None = None
|
||||||
agent_role: Optional[str] = None
|
agent_role: str | None = None
|
||||||
agent_id: Optional[str] = None
|
agent_id: str | None = None
|
||||||
|
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
super().__init__(**data)
|
super().__init__(**data)
|
||||||
@@ -26,7 +26,7 @@ class MemoryQueryStartedEvent(MemoryBaseEvent):
|
|||||||
type: str = "memory_query_started"
|
type: str = "memory_query_started"
|
||||||
query: str
|
query: str
|
||||||
limit: int
|
limit: int
|
||||||
score_threshold: Optional[float] = None
|
score_threshold: float | None = None
|
||||||
|
|
||||||
|
|
||||||
class MemoryQueryCompletedEvent(MemoryBaseEvent):
|
class MemoryQueryCompletedEvent(MemoryBaseEvent):
|
||||||
@@ -36,7 +36,7 @@ class MemoryQueryCompletedEvent(MemoryBaseEvent):
|
|||||||
query: str
|
query: str
|
||||||
results: Any
|
results: Any
|
||||||
limit: int
|
limit: int
|
||||||
score_threshold: Optional[float] = None
|
score_threshold: float | None = None
|
||||||
query_time_ms: float
|
query_time_ms: float
|
||||||
|
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ class MemoryQueryFailedEvent(MemoryBaseEvent):
|
|||||||
type: str = "memory_query_failed"
|
type: str = "memory_query_failed"
|
||||||
query: str
|
query: str
|
||||||
limit: int
|
limit: int
|
||||||
score_threshold: Optional[float] = None
|
score_threshold: float | None = None
|
||||||
error: str
|
error: str
|
||||||
|
|
||||||
|
|
||||||
@@ -54,9 +54,9 @@ class MemorySaveStartedEvent(MemoryBaseEvent):
|
|||||||
"""Event emitted when a memory save operation is started"""
|
"""Event emitted when a memory save operation is started"""
|
||||||
|
|
||||||
type: str = "memory_save_started"
|
type: str = "memory_save_started"
|
||||||
value: Optional[str] = None
|
value: str | None = None
|
||||||
metadata: Optional[Dict[str, Any]] = None
|
metadata: dict[str, Any] | None = None
|
||||||
agent_role: Optional[str] = None
|
agent_role: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class MemorySaveCompletedEvent(MemoryBaseEvent):
|
class MemorySaveCompletedEvent(MemoryBaseEvent):
|
||||||
@@ -64,8 +64,8 @@ class MemorySaveCompletedEvent(MemoryBaseEvent):
|
|||||||
|
|
||||||
type: str = "memory_save_completed"
|
type: str = "memory_save_completed"
|
||||||
value: str
|
value: str
|
||||||
metadata: Optional[Dict[str, Any]] = None
|
metadata: dict[str, Any] | None = None
|
||||||
agent_role: Optional[str] = None
|
agent_role: str | None = None
|
||||||
save_time_ms: float
|
save_time_ms: float
|
||||||
|
|
||||||
|
|
||||||
@@ -73,9 +73,9 @@ class MemorySaveFailedEvent(MemoryBaseEvent):
|
|||||||
"""Event emitted when a memory save operation fails"""
|
"""Event emitted when a memory save operation fails"""
|
||||||
|
|
||||||
type: str = "memory_save_failed"
|
type: str = "memory_save_failed"
|
||||||
value: Optional[str] = None
|
value: str | None = None
|
||||||
metadata: Optional[Dict[str, Any]] = None
|
metadata: dict[str, Any] | None = None
|
||||||
agent_role: Optional[str] = None
|
agent_role: str | None = None
|
||||||
error: str
|
error: str
|
||||||
|
|
||||||
|
|
||||||
@@ -83,13 +83,13 @@ class MemoryRetrievalStartedEvent(MemoryBaseEvent):
|
|||||||
"""Event emitted when memory retrieval for a task prompt starts"""
|
"""Event emitted when memory retrieval for a task prompt starts"""
|
||||||
|
|
||||||
type: str = "memory_retrieval_started"
|
type: str = "memory_retrieval_started"
|
||||||
task_id: Optional[str] = None
|
task_id: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class MemoryRetrievalCompletedEvent(MemoryBaseEvent):
|
class MemoryRetrievalCompletedEvent(MemoryBaseEvent):
|
||||||
"""Event emitted when memory retrieval for a task prompt completes successfully"""
|
"""Event emitted when memory retrieval for a task prompt completes successfully"""
|
||||||
|
|
||||||
type: str = "memory_retrieval_completed"
|
type: str = "memory_retrieval_completed"
|
||||||
task_id: Optional[str] = None
|
task_id: str | None = None
|
||||||
memory_content: str
|
memory_content: str
|
||||||
retrieval_time_ms: float
|
retrieval_time_ms: float
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
from crewai.events.base_events import BaseEvent
|
from crewai.events.base_events import BaseEvent
|
||||||
from typing import Any, Optional
|
|
||||||
|
|
||||||
|
|
||||||
class ReasoningEvent(BaseEvent):
|
class ReasoningEvent(BaseEvent):
|
||||||
@@ -9,10 +10,10 @@ class ReasoningEvent(BaseEvent):
|
|||||||
attempt: int = 1
|
attempt: int = 1
|
||||||
agent_role: str
|
agent_role: str
|
||||||
task_id: str
|
task_id: str
|
||||||
task_name: Optional[str] = None
|
task_name: str | None = None
|
||||||
from_task: Optional[Any] = None
|
from_task: Any | None = None
|
||||||
agent_id: Optional[str] = None
|
agent_id: str | None = None
|
||||||
from_agent: Optional[Any] = None
|
from_agent: Any | None = None
|
||||||
|
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
super().__init__(**data)
|
super().__init__(**data)
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
from typing import Any, Optional
|
from typing import Any
|
||||||
|
|
||||||
from crewai.tasks.task_output import TaskOutput
|
|
||||||
from crewai.events.base_events import BaseEvent
|
from crewai.events.base_events import BaseEvent
|
||||||
|
from crewai.tasks.task_output import TaskOutput
|
||||||
|
|
||||||
|
|
||||||
class TaskStartedEvent(BaseEvent):
|
class TaskStartedEvent(BaseEvent):
|
||||||
"""Event emitted when a task starts"""
|
"""Event emitted when a task starts"""
|
||||||
|
|
||||||
type: str = "task_started"
|
type: str = "task_started"
|
||||||
context: Optional[str]
|
context: str | None
|
||||||
task: Optional[Any] = None
|
task: Any | None = None
|
||||||
|
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
super().__init__(**data)
|
super().__init__(**data)
|
||||||
@@ -29,7 +29,7 @@ class TaskCompletedEvent(BaseEvent):
|
|||||||
|
|
||||||
output: TaskOutput
|
output: TaskOutput
|
||||||
type: str = "task_completed"
|
type: str = "task_completed"
|
||||||
task: Optional[Any] = None
|
task: Any | None = None
|
||||||
|
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
super().__init__(**data)
|
super().__init__(**data)
|
||||||
@@ -49,7 +49,7 @@ class TaskFailedEvent(BaseEvent):
|
|||||||
|
|
||||||
error: str
|
error: str
|
||||||
type: str = "task_failed"
|
type: str = "task_failed"
|
||||||
task: Optional[Any] = None
|
task: Any | None = None
|
||||||
|
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
super().__init__(**data)
|
super().__init__(**data)
|
||||||
@@ -69,7 +69,7 @@ class TaskEvaluationEvent(BaseEvent):
|
|||||||
|
|
||||||
type: str = "task_evaluation"
|
type: str = "task_evaluation"
|
||||||
evaluation_type: str
|
evaluation_type: str
|
||||||
task: Optional[Any] = None
|
task: Any | None = None
|
||||||
|
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
super().__init__(**data)
|
super().__init__(**data)
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
from collections.abc import Callable
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Callable, Dict, Optional
|
from typing import Any
|
||||||
|
|
||||||
|
from pydantic import ConfigDict
|
||||||
|
|
||||||
from crewai.events.base_events import BaseEvent
|
from crewai.events.base_events import BaseEvent
|
||||||
|
|
||||||
@@ -7,21 +10,21 @@ from crewai.events.base_events import BaseEvent
|
|||||||
class ToolUsageEvent(BaseEvent):
|
class ToolUsageEvent(BaseEvent):
|
||||||
"""Base event for tool usage tracking"""
|
"""Base event for tool usage tracking"""
|
||||||
|
|
||||||
agent_key: Optional[str] = None
|
agent_key: str | None = None
|
||||||
agent_role: Optional[str] = None
|
agent_role: str | None = None
|
||||||
agent_id: Optional[str] = None
|
agent_id: str | None = None
|
||||||
tool_name: str
|
tool_name: str
|
||||||
tool_args: Dict[str, Any] | str
|
tool_args: dict[str, Any] | str
|
||||||
tool_class: Optional[str] = None
|
tool_class: str | None = None
|
||||||
run_attempts: int | None = None
|
run_attempts: int | None = None
|
||||||
delegations: int | None = None
|
delegations: int | None = None
|
||||||
agent: Optional[Any] = None
|
agent: Any | None = None
|
||||||
task_name: Optional[str] = None
|
task_name: str | None = None
|
||||||
task_id: Optional[str] = None
|
task_id: str | None = None
|
||||||
from_task: Optional[Any] = None
|
from_task: Any | None = None
|
||||||
from_agent: Optional[Any] = None
|
from_agent: Any | None = None
|
||||||
|
|
||||||
model_config = {"arbitrary_types_allowed": True}
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||||
|
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
super().__init__(**data)
|
super().__init__(**data)
|
||||||
@@ -81,9 +84,9 @@ class ToolExecutionErrorEvent(BaseEvent):
|
|||||||
error: Any
|
error: Any
|
||||||
type: str = "tool_execution_error"
|
type: str = "tool_execution_error"
|
||||||
tool_name: str
|
tool_name: str
|
||||||
tool_args: Dict[str, Any]
|
tool_args: dict[str, Any]
|
||||||
tool_class: Callable
|
tool_class: Callable
|
||||||
agent: Optional[Any] = None
|
agent: Any | None = None
|
||||||
|
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
super().__init__(**data)
|
super().__init__(**data)
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
from typing import Any, Dict, Optional
|
from typing import Any, ClassVar
|
||||||
|
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
from rich.live import Live
|
||||||
from rich.panel import Panel
|
from rich.panel import Panel
|
||||||
|
from rich.syntax import Syntax
|
||||||
from rich.text import Text
|
from rich.text import Text
|
||||||
from rich.tree import Tree
|
from rich.tree import Tree
|
||||||
from rich.live import Live
|
|
||||||
from rich.syntax import Syntax
|
|
||||||
|
|
||||||
|
|
||||||
class ConsoleFormatter:
|
class ConsoleFormatter:
|
||||||
current_crew_tree: Optional[Tree] = None
|
current_crew_tree: Tree | None = None
|
||||||
current_task_branch: Optional[Tree] = None
|
current_task_branch: Tree | None = None
|
||||||
current_agent_branch: Optional[Tree] = None
|
current_agent_branch: Tree | None = None
|
||||||
current_tool_branch: Optional[Tree] = None
|
current_tool_branch: Tree | None = None
|
||||||
current_flow_tree: Optional[Tree] = None
|
current_flow_tree: Tree | None = None
|
||||||
current_method_branch: Optional[Tree] = None
|
current_method_branch: Tree | None = None
|
||||||
current_lite_agent_branch: Optional[Tree] = None
|
current_lite_agent_branch: Tree | None = None
|
||||||
tool_usage_counts: Dict[str, int] = {}
|
tool_usage_counts: ClassVar[dict[str, int]] = {}
|
||||||
current_reasoning_branch: Optional[Tree] = None # Track reasoning status
|
current_reasoning_branch: Tree | None = None # Track reasoning status
|
||||||
_live_paused: bool = False
|
_live_paused: bool = False
|
||||||
current_llm_tool_tree: Optional[Tree] = None
|
current_llm_tool_tree: Tree | None = None
|
||||||
|
|
||||||
def __init__(self, verbose: bool = False):
|
def __init__(self, verbose: bool = False):
|
||||||
self.console = Console(width=None)
|
self.console = Console(width=None)
|
||||||
@@ -29,7 +29,7 @@ class ConsoleFormatter:
|
|||||||
# instance so the previous render is replaced instead of writing a new one.
|
# instance so the previous render is replaced instead of writing a new one.
|
||||||
# Once any non-Tree renderable is printed we stop the Live session so the
|
# Once any non-Tree renderable is printed we stop the Live session so the
|
||||||
# final Tree persists on the terminal.
|
# final Tree persists on the terminal.
|
||||||
self._live: Optional[Live] = None
|
self._live: Live | None = None
|
||||||
|
|
||||||
def create_panel(self, content: Text, title: str, style: str = "blue") -> Panel:
|
def create_panel(self, content: Text, title: str, style: str = "blue") -> Panel:
|
||||||
"""Create a standardized panel with consistent styling."""
|
"""Create a standardized panel with consistent styling."""
|
||||||
@@ -45,7 +45,7 @@ class ConsoleFormatter:
|
|||||||
title: str,
|
title: str,
|
||||||
name: str,
|
name: str,
|
||||||
status_style: str = "blue",
|
status_style: str = "blue",
|
||||||
tool_args: Dict[str, Any] | str = "",
|
tool_args: dict[str, Any] | str = "",
|
||||||
**fields,
|
**fields,
|
||||||
) -> Text:
|
) -> Text:
|
||||||
"""Create standardized status content with consistent formatting."""
|
"""Create standardized status content with consistent formatting."""
|
||||||
@@ -70,7 +70,7 @@ class ConsoleFormatter:
|
|||||||
prefix: str,
|
prefix: str,
|
||||||
name: str,
|
name: str,
|
||||||
style: str = "blue",
|
style: str = "blue",
|
||||||
status: Optional[str] = None,
|
status: str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Update tree label with consistent formatting."""
|
"""Update tree label with consistent formatting."""
|
||||||
label = Text()
|
label = Text()
|
||||||
@@ -115,7 +115,7 @@ class ConsoleFormatter:
|
|||||||
self._live.update(tree, refresh=True)
|
self._live.update(tree, refresh=True)
|
||||||
return # Nothing else to do
|
return # Nothing else to do
|
||||||
|
|
||||||
# Case 2: blank line while a live session is running – ignore so we
|
# Case 2: blank line while a live session is running - ignore so we
|
||||||
# don't break the in-place rendering behaviour
|
# don't break the in-place rendering behaviour
|
||||||
if len(args) == 0 and self._live:
|
if len(args) == 0 and self._live:
|
||||||
return
|
return
|
||||||
@@ -156,7 +156,7 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def update_crew_tree(
|
def update_crew_tree(
|
||||||
self,
|
self,
|
||||||
tree: Optional[Tree],
|
tree: Tree | None,
|
||||||
crew_name: str,
|
crew_name: str,
|
||||||
source_id: str,
|
source_id: str,
|
||||||
status: str = "completed",
|
status: str = "completed",
|
||||||
@@ -196,7 +196,7 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
self.print_panel(content, title, style)
|
self.print_panel(content, title, style)
|
||||||
|
|
||||||
def create_crew_tree(self, crew_name: str, source_id: str) -> Optional[Tree]:
|
def create_crew_tree(self, crew_name: str, source_id: str) -> Tree | None:
|
||||||
"""Create and initialize a new crew tree with initial status."""
|
"""Create and initialize a new crew tree with initial status."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return None
|
||||||
@@ -220,8 +220,8 @@ class ConsoleFormatter:
|
|||||||
return tree
|
return tree
|
||||||
|
|
||||||
def create_task_branch(
|
def create_task_branch(
|
||||||
self, crew_tree: Optional[Tree], task_id: str, task_name: Optional[str] = None
|
self, crew_tree: Tree | None, task_id: str, task_name: str | None = None
|
||||||
) -> Optional[Tree]:
|
) -> Tree | None:
|
||||||
"""Create and initialize a task branch."""
|
"""Create and initialize a task branch."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return None
|
||||||
@@ -255,11 +255,11 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def update_task_status(
|
def update_task_status(
|
||||||
self,
|
self,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
task_id: str,
|
task_id: str,
|
||||||
agent_role: str,
|
agent_role: str,
|
||||||
status: str = "completed",
|
status: str = "completed",
|
||||||
task_name: Optional[str] = None,
|
task_name: str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Update task status in the tree."""
|
"""Update task status in the tree."""
|
||||||
if not self.verbose or crew_tree is None:
|
if not self.verbose or crew_tree is None:
|
||||||
@@ -306,8 +306,8 @@ class ConsoleFormatter:
|
|||||||
self.print_panel(content, panel_title, style)
|
self.print_panel(content, panel_title, style)
|
||||||
|
|
||||||
def create_agent_branch(
|
def create_agent_branch(
|
||||||
self, task_branch: Optional[Tree], agent_role: str, crew_tree: Optional[Tree]
|
self, task_branch: Tree | None, agent_role: str, crew_tree: Tree | None
|
||||||
) -> Optional[Tree]:
|
) -> Tree | None:
|
||||||
"""Create and initialize an agent branch."""
|
"""Create and initialize an agent branch."""
|
||||||
if not self.verbose or not task_branch or not crew_tree:
|
if not self.verbose or not task_branch or not crew_tree:
|
||||||
return None
|
return None
|
||||||
@@ -325,9 +325,9 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def update_agent_status(
|
def update_agent_status(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
agent_role: str,
|
agent_role: str,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
status: str = "completed",
|
status: str = "completed",
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Update agent status in the tree."""
|
"""Update agent status in the tree."""
|
||||||
@@ -336,7 +336,7 @@ class ConsoleFormatter:
|
|||||||
# altering the tree. Keeping it a no-op avoids duplicate status lines.
|
# altering the tree. Keeping it a no-op avoids duplicate status lines.
|
||||||
return
|
return
|
||||||
|
|
||||||
def create_flow_tree(self, flow_name: str, flow_id: str) -> Optional[Tree]:
|
def create_flow_tree(self, flow_name: str, flow_id: str) -> Tree | None:
|
||||||
"""Create and initialize a flow tree."""
|
"""Create and initialize a flow tree."""
|
||||||
content = self.create_status_content(
|
content = self.create_status_content(
|
||||||
"Starting Flow Execution", flow_name, "blue", ID=flow_id
|
"Starting Flow Execution", flow_name, "blue", ID=flow_id
|
||||||
@@ -356,7 +356,7 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
return flow_tree
|
return flow_tree
|
||||||
|
|
||||||
def start_flow(self, flow_name: str, flow_id: str) -> Optional[Tree]:
|
def start_flow(self, flow_name: str, flow_id: str) -> Tree | None:
|
||||||
"""Initialize a flow execution tree."""
|
"""Initialize a flow execution tree."""
|
||||||
flow_tree = Tree("")
|
flow_tree = Tree("")
|
||||||
flow_label = Text()
|
flow_label = Text()
|
||||||
@@ -376,7 +376,7 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def update_flow_status(
|
def update_flow_status(
|
||||||
self,
|
self,
|
||||||
flow_tree: Optional[Tree],
|
flow_tree: Tree | None,
|
||||||
flow_name: str,
|
flow_name: str,
|
||||||
flow_id: str,
|
flow_id: str,
|
||||||
status: str = "completed",
|
status: str = "completed",
|
||||||
@@ -423,11 +423,11 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def update_method_status(
|
def update_method_status(
|
||||||
self,
|
self,
|
||||||
method_branch: Optional[Tree],
|
method_branch: Tree | None,
|
||||||
flow_tree: Optional[Tree],
|
flow_tree: Tree | None,
|
||||||
method_name: str,
|
method_name: str,
|
||||||
status: str = "running",
|
status: str = "running",
|
||||||
) -> Optional[Tree]:
|
) -> Tree | None:
|
||||||
"""Update method status in the flow tree."""
|
"""Update method status in the flow tree."""
|
||||||
if not flow_tree:
|
if not flow_tree:
|
||||||
return None
|
return None
|
||||||
@@ -480,7 +480,7 @@ class ConsoleFormatter:
|
|||||||
def handle_llm_tool_usage_started(
|
def handle_llm_tool_usage_started(
|
||||||
self,
|
self,
|
||||||
tool_name: str,
|
tool_name: str,
|
||||||
tool_args: Dict[str, Any] | str,
|
tool_args: dict[str, Any] | str,
|
||||||
):
|
):
|
||||||
# Create status content for the tool usage
|
# Create status content for the tool usage
|
||||||
content = self.create_status_content(
|
content = self.create_status_content(
|
||||||
@@ -520,11 +520,11 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_tool_usage_started(
|
def handle_tool_usage_started(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
tool_name: str,
|
tool_name: str,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
tool_args: Dict[str, Any] | str = "",
|
tool_args: dict[str, Any] | str = "",
|
||||||
) -> Optional[Tree]:
|
) -> Tree | None:
|
||||||
"""Handle tool usage started event."""
|
"""Handle tool usage started event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return None
|
||||||
@@ -569,9 +569,9 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_tool_usage_finished(
|
def handle_tool_usage_finished(
|
||||||
self,
|
self,
|
||||||
tool_branch: Optional[Tree],
|
tool_branch: Tree | None,
|
||||||
tool_name: str,
|
tool_name: str,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle tool usage finished event."""
|
"""Handle tool usage finished event."""
|
||||||
if not self.verbose or tool_branch is None:
|
if not self.verbose or tool_branch is None:
|
||||||
@@ -600,10 +600,10 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_tool_usage_error(
|
def handle_tool_usage_error(
|
||||||
self,
|
self,
|
||||||
tool_branch: Optional[Tree],
|
tool_branch: Tree | None,
|
||||||
tool_name: str,
|
tool_name: str,
|
||||||
error: str,
|
error: str,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle tool usage error event."""
|
"""Handle tool usage error event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
@@ -631,9 +631,9 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_llm_call_started(
|
def handle_llm_call_started(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> Optional[Tree]:
|
) -> Tree | None:
|
||||||
"""Handle LLM call started event."""
|
"""Handle LLM call started event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return None
|
||||||
@@ -672,9 +672,9 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_llm_call_completed(
|
def handle_llm_call_completed(
|
||||||
self,
|
self,
|
||||||
tool_branch: Optional[Tree],
|
tool_branch: Tree | None,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle LLM call completed event."""
|
"""Handle LLM call completed event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
@@ -736,7 +736,7 @@ class ConsoleFormatter:
|
|||||||
self.print()
|
self.print()
|
||||||
|
|
||||||
def handle_llm_call_failed(
|
def handle_llm_call_failed(
|
||||||
self, tool_branch: Optional[Tree], error: str, crew_tree: Optional[Tree]
|
self, tool_branch: Tree | None, error: str, crew_tree: Tree | None
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle LLM call failed event."""
|
"""Handle LLM call failed event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
@@ -789,7 +789,7 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_crew_test_started(
|
def handle_crew_test_started(
|
||||||
self, crew_name: str, source_id: str, n_iterations: int
|
self, crew_name: str, source_id: str, n_iterations: int
|
||||||
) -> Optional[Tree]:
|
) -> Tree | None:
|
||||||
"""Handle crew test started event."""
|
"""Handle crew test started event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return None
|
||||||
@@ -823,7 +823,7 @@ class ConsoleFormatter:
|
|||||||
return test_tree
|
return test_tree
|
||||||
|
|
||||||
def handle_crew_test_completed(
|
def handle_crew_test_completed(
|
||||||
self, flow_tree: Optional[Tree], crew_name: str
|
self, flow_tree: Tree | None, crew_name: str
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle crew test completed event."""
|
"""Handle crew test completed event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
@@ -913,7 +913,7 @@ class ConsoleFormatter:
|
|||||||
self.print_panel(failure_content, "Test Failure", "red")
|
self.print_panel(failure_content, "Test Failure", "red")
|
||||||
self.print()
|
self.print()
|
||||||
|
|
||||||
def create_lite_agent_branch(self, lite_agent_role: str) -> Optional[Tree]:
|
def create_lite_agent_branch(self, lite_agent_role: str) -> Tree | None:
|
||||||
"""Create and initialize a lite agent branch."""
|
"""Create and initialize a lite agent branch."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return None
|
||||||
@@ -935,10 +935,10 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def update_lite_agent_status(
|
def update_lite_agent_status(
|
||||||
self,
|
self,
|
||||||
lite_agent_branch: Optional[Tree],
|
lite_agent_branch: Tree | None,
|
||||||
lite_agent_role: str,
|
lite_agent_role: str,
|
||||||
status: str = "completed",
|
status: str = "completed",
|
||||||
**fields: Dict[str, Any],
|
**fields: dict[str, Any],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Update lite agent status in the tree."""
|
"""Update lite agent status in the tree."""
|
||||||
if not self.verbose or lite_agent_branch is None:
|
if not self.verbose or lite_agent_branch is None:
|
||||||
@@ -981,7 +981,7 @@ class ConsoleFormatter:
|
|||||||
lite_agent_role: str,
|
lite_agent_role: str,
|
||||||
status: str = "started",
|
status: str = "started",
|
||||||
error: Any = None,
|
error: Any = None,
|
||||||
**fields: Dict[str, Any],
|
**fields: dict[str, Any],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle lite agent execution events with consistent formatting."""
|
"""Handle lite agent execution events with consistent formatting."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
@@ -1006,9 +1006,9 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_knowledge_retrieval_started(
|
def handle_knowledge_retrieval_started(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> Optional[Tree]:
|
) -> Tree | None:
|
||||||
"""Handle knowledge retrieval started event."""
|
"""Handle knowledge retrieval started event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return None
|
||||||
@@ -1034,13 +1034,13 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_knowledge_retrieval_completed(
|
def handle_knowledge_retrieval_completed(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
retrieved_knowledge: Any,
|
retrieved_knowledge: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle knowledge retrieval completed event."""
|
"""Handle knowledge retrieval completed event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return
|
||||||
|
|
||||||
branch_to_use = self.current_lite_agent_branch or agent_branch
|
branch_to_use = self.current_lite_agent_branch or agent_branch
|
||||||
tree_to_use = branch_to_use or crew_tree
|
tree_to_use = branch_to_use or crew_tree
|
||||||
@@ -1062,7 +1062,7 @@ class ConsoleFormatter:
|
|||||||
)
|
)
|
||||||
self.print(knowledge_panel)
|
self.print(knowledge_panel)
|
||||||
self.print()
|
self.print()
|
||||||
return None
|
return
|
||||||
|
|
||||||
knowledge_branch_found = False
|
knowledge_branch_found = False
|
||||||
for child in branch_to_use.children:
|
for child in branch_to_use.children:
|
||||||
@@ -1111,18 +1111,18 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_knowledge_query_started(
|
def handle_knowledge_query_started(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
task_prompt: str,
|
task_prompt: str,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle knowledge query generated event."""
|
"""Handle knowledge query generated event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return
|
||||||
|
|
||||||
branch_to_use = self.current_lite_agent_branch or agent_branch
|
branch_to_use = self.current_lite_agent_branch or agent_branch
|
||||||
tree_to_use = branch_to_use or crew_tree
|
tree_to_use = branch_to_use or crew_tree
|
||||||
if branch_to_use is None or tree_to_use is None:
|
if branch_to_use is None or tree_to_use is None:
|
||||||
return None
|
return
|
||||||
|
|
||||||
query_branch = branch_to_use.add("")
|
query_branch = branch_to_use.add("")
|
||||||
self.update_tree_label(
|
self.update_tree_label(
|
||||||
@@ -1134,9 +1134,9 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_knowledge_query_failed(
|
def handle_knowledge_query_failed(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
error: str,
|
error: str,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle knowledge query failed event."""
|
"""Handle knowledge query failed event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
@@ -1159,18 +1159,18 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_knowledge_query_completed(
|
def handle_knowledge_query_completed(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle knowledge query completed event."""
|
"""Handle knowledge query completed event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return
|
||||||
|
|
||||||
branch_to_use = self.current_lite_agent_branch or agent_branch
|
branch_to_use = self.current_lite_agent_branch or agent_branch
|
||||||
tree_to_use = branch_to_use or crew_tree
|
tree_to_use = branch_to_use or crew_tree
|
||||||
|
|
||||||
if branch_to_use is None or tree_to_use is None:
|
if branch_to_use is None or tree_to_use is None:
|
||||||
return None
|
return
|
||||||
|
|
||||||
query_branch = branch_to_use.add("")
|
query_branch = branch_to_use.add("")
|
||||||
self.update_tree_label(query_branch, "✅", "Knowledge Query Completed", "green")
|
self.update_tree_label(query_branch, "✅", "Knowledge Query Completed", "green")
|
||||||
@@ -1180,9 +1180,9 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_knowledge_search_query_failed(
|
def handle_knowledge_search_query_failed(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
error: str,
|
error: str,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle knowledge search query failed event."""
|
"""Handle knowledge search query failed event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
@@ -1207,10 +1207,10 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_reasoning_started(
|
def handle_reasoning_started(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
attempt: int,
|
attempt: int,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> Optional[Tree]:
|
) -> Tree | None:
|
||||||
"""Handle agent reasoning started (or refinement) event."""
|
"""Handle agent reasoning started (or refinement) event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return None
|
||||||
@@ -1249,7 +1249,7 @@ class ConsoleFormatter:
|
|||||||
self,
|
self,
|
||||||
plan: str,
|
plan: str,
|
||||||
ready: bool,
|
ready: bool,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle agent reasoning completed event."""
|
"""Handle agent reasoning completed event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
@@ -1292,7 +1292,7 @@ class ConsoleFormatter:
|
|||||||
def handle_reasoning_failed(
|
def handle_reasoning_failed(
|
||||||
self,
|
self,
|
||||||
error: str,
|
error: str,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle agent reasoning failure event."""
|
"""Handle agent reasoning failure event."""
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
@@ -1329,7 +1329,7 @@ class ConsoleFormatter:
|
|||||||
def handle_agent_logs_started(
|
def handle_agent_logs_started(
|
||||||
self,
|
self,
|
||||||
agent_role: str,
|
agent_role: str,
|
||||||
task_description: Optional[str] = None,
|
task_description: str | None = None,
|
||||||
verbose: bool = False,
|
verbose: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle agent logs started event."""
|
"""Handle agent logs started event."""
|
||||||
@@ -1367,10 +1367,11 @@ class ConsoleFormatter:
|
|||||||
if not verbose:
|
if not verbose:
|
||||||
return
|
return
|
||||||
|
|
||||||
from crewai.agents.parser import AgentAction, AgentFinish
|
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from crewai.agents.parser import AgentAction, AgentFinish
|
||||||
|
|
||||||
agent_role = agent_role.partition("\n")[0]
|
agent_role = agent_role.partition("\n")[0]
|
||||||
|
|
||||||
if isinstance(formatted_answer, AgentAction):
|
if isinstance(formatted_answer, AgentAction):
|
||||||
@@ -1473,9 +1474,9 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_memory_retrieval_started(
|
def handle_memory_retrieval_started(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> Optional[Tree]:
|
) -> Tree | None:
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -1497,13 +1498,13 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_memory_retrieval_completed(
|
def handle_memory_retrieval_completed(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
memory_content: str,
|
memory_content: str,
|
||||||
retrieval_time_ms: float,
|
retrieval_time_ms: float,
|
||||||
) -> None:
|
) -> None:
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return
|
||||||
|
|
||||||
branch_to_use = self.current_lite_agent_branch or agent_branch
|
branch_to_use = self.current_lite_agent_branch or agent_branch
|
||||||
tree_to_use = branch_to_use or crew_tree
|
tree_to_use = branch_to_use or crew_tree
|
||||||
@@ -1528,7 +1529,7 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
if branch_to_use is None or tree_to_use is None:
|
if branch_to_use is None or tree_to_use is None:
|
||||||
add_panel()
|
add_panel()
|
||||||
return None
|
return
|
||||||
|
|
||||||
memory_branch_found = False
|
memory_branch_found = False
|
||||||
for child in branch_to_use.children:
|
for child in branch_to_use.children:
|
||||||
@@ -1565,13 +1566,13 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_memory_query_completed(
|
def handle_memory_query_completed(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
source_type: str,
|
source_type: str,
|
||||||
query_time_ms: float,
|
query_time_ms: float,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return
|
||||||
|
|
||||||
branch_to_use = self.current_lite_agent_branch or agent_branch
|
branch_to_use = self.current_lite_agent_branch or agent_branch
|
||||||
tree_to_use = branch_to_use or crew_tree
|
tree_to_use = branch_to_use or crew_tree
|
||||||
@@ -1580,15 +1581,15 @@ class ConsoleFormatter:
|
|||||||
branch_to_use = tree_to_use
|
branch_to_use = tree_to_use
|
||||||
|
|
||||||
if branch_to_use is None:
|
if branch_to_use is None:
|
||||||
return None
|
return
|
||||||
|
|
||||||
memory_type = source_type.replace("_", " ").title()
|
memory_type = source_type.replace("_", " ").title()
|
||||||
|
|
||||||
for child in branch_to_use.children:
|
for child in branch_to_use.children:
|
||||||
if "Memory Retrieval" in str(child.label):
|
if "Memory Retrieval" in str(child.label):
|
||||||
for child in child.children:
|
for inner_child in child.children:
|
||||||
sources_branch = child
|
sources_branch = inner_child
|
||||||
if "Sources Used" in str(child.label):
|
if "Sources Used" in str(inner_child.label):
|
||||||
sources_branch.add(f"✅ {memory_type} ({query_time_ms:.2f}ms)")
|
sources_branch.add(f"✅ {memory_type} ({query_time_ms:.2f}ms)")
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@@ -1598,13 +1599,13 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_memory_query_failed(
|
def handle_memory_query_failed(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
error: str,
|
error: str,
|
||||||
source_type: str,
|
source_type: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return
|
||||||
|
|
||||||
branch_to_use = self.current_lite_agent_branch or agent_branch
|
branch_to_use = self.current_lite_agent_branch or agent_branch
|
||||||
tree_to_use = branch_to_use or crew_tree
|
tree_to_use = branch_to_use or crew_tree
|
||||||
@@ -1613,15 +1614,15 @@ class ConsoleFormatter:
|
|||||||
branch_to_use = tree_to_use
|
branch_to_use = tree_to_use
|
||||||
|
|
||||||
if branch_to_use is None:
|
if branch_to_use is None:
|
||||||
return None
|
return
|
||||||
|
|
||||||
memory_type = source_type.replace("_", " ").title()
|
memory_type = source_type.replace("_", " ").title()
|
||||||
|
|
||||||
for child in branch_to_use.children:
|
for child in branch_to_use.children:
|
||||||
if "Memory Retrieval" in str(child.label):
|
if "Memory Retrieval" in str(child.label):
|
||||||
for child in child.children:
|
for inner_child in child.children:
|
||||||
sources_branch = child
|
sources_branch = inner_child
|
||||||
if "Sources Used" in str(child.label):
|
if "Sources Used" in str(inner_child.label):
|
||||||
sources_branch.add(f"❌ {memory_type} - Error: {error}")
|
sources_branch.add(f"❌ {memory_type} - Error: {error}")
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@@ -1630,16 +1631,16 @@ class ConsoleFormatter:
|
|||||||
break
|
break
|
||||||
|
|
||||||
def handle_memory_save_started(
|
def handle_memory_save_started(
|
||||||
self, agent_branch: Optional[Tree], crew_tree: Optional[Tree]
|
self, agent_branch: Tree | None, crew_tree: Tree | None
|
||||||
) -> None:
|
) -> None:
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return
|
||||||
|
|
||||||
branch_to_use = agent_branch or self.current_lite_agent_branch
|
branch_to_use = agent_branch or self.current_lite_agent_branch
|
||||||
tree_to_use = branch_to_use or crew_tree
|
tree_to_use = branch_to_use or crew_tree
|
||||||
|
|
||||||
if tree_to_use is None:
|
if tree_to_use is None:
|
||||||
return None
|
return
|
||||||
|
|
||||||
for child in tree_to_use.children:
|
for child in tree_to_use.children:
|
||||||
if "Memory Update" in str(child.label):
|
if "Memory Update" in str(child.label):
|
||||||
@@ -1655,19 +1656,19 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_memory_save_completed(
|
def handle_memory_save_completed(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
save_time_ms: float,
|
save_time_ms: float,
|
||||||
source_type: str,
|
source_type: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return
|
||||||
|
|
||||||
branch_to_use = agent_branch or self.current_lite_agent_branch
|
branch_to_use = agent_branch or self.current_lite_agent_branch
|
||||||
tree_to_use = branch_to_use or crew_tree
|
tree_to_use = branch_to_use or crew_tree
|
||||||
|
|
||||||
if tree_to_use is None:
|
if tree_to_use is None:
|
||||||
return None
|
return
|
||||||
|
|
||||||
memory_type = source_type.replace("_", " ").title()
|
memory_type = source_type.replace("_", " ").title()
|
||||||
content = f"✅ {memory_type} Memory Saved ({save_time_ms:.2f}ms)"
|
content = f"✅ {memory_type} Memory Saved ({save_time_ms:.2f}ms)"
|
||||||
@@ -1685,19 +1686,19 @@ class ConsoleFormatter:
|
|||||||
|
|
||||||
def handle_memory_save_failed(
|
def handle_memory_save_failed(
|
||||||
self,
|
self,
|
||||||
agent_branch: Optional[Tree],
|
agent_branch: Tree | None,
|
||||||
error: str,
|
error: str,
|
||||||
source_type: str,
|
source_type: str,
|
||||||
crew_tree: Optional[Tree],
|
crew_tree: Tree | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
if not self.verbose:
|
if not self.verbose:
|
||||||
return None
|
return
|
||||||
|
|
||||||
branch_to_use = agent_branch or self.current_lite_agent_branch
|
branch_to_use = agent_branch or self.current_lite_agent_branch
|
||||||
tree_to_use = branch_to_use or crew_tree
|
tree_to_use = branch_to_use or crew_tree
|
||||||
|
|
||||||
if branch_to_use is None or tree_to_use is None:
|
if branch_to_use is None or tree_to_use is None:
|
||||||
return None
|
return
|
||||||
|
|
||||||
memory_type = source_type.replace("_", " ").title()
|
memory_type = source_type.replace("_", " ").title()
|
||||||
content = f"❌ {memory_type} Memory Save Failed"
|
content = f"❌ {memory_type} Memory Save Failed"
|
||||||
@@ -1738,7 +1739,7 @@ class ConsoleFormatter:
|
|||||||
def handle_guardrail_completed(
|
def handle_guardrail_completed(
|
||||||
self,
|
self,
|
||||||
success: bool,
|
success: bool,
|
||||||
error: Optional[str],
|
error: str | None,
|
||||||
retry_count: int,
|
retry_count: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Display guardrail evaluation result.
|
"""Display guardrail evaluation result.
|
||||||
|
|||||||
Reference in New Issue
Block a user