mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
* initial setup * feat: enhance CrewKickoffCompletedEvent to include total token usage - Added total_tokens attribute to CrewKickoffCompletedEvent for better tracking of token usage during crew execution. - Updated Crew class to emit total token usage upon kickoff completion. - Removed obsolete context handler and execution context tracker files to streamline event handling. * cleanup * remove print statements for loggers * feat: add CrewAI base URL and improve logging in tracing - Introduced `CREWAI_BASE_URL` constant for easy access to the CrewAI application URL. - Replaced print statements with logging in the `TraceSender` class for better error tracking. - Enhanced the `TraceBatchManager` to provide default values for flow names and removed unnecessary comments. - Implemented singleton pattern in `TraceCollectionListener` to ensure a single instance is used. - Added a new test case to verify that the trace listener correctly collects events during crew execution. * clear * fix: update datetime serialization in tracing interfaces - Removed the 'Z' suffix from datetime serialization in TraceSender and TraceEvent to ensure consistent ISO format. - Added new test cases to validate the functionality of the TraceBatchManager and event collection during crew execution. - Introduced fixtures to clear event bus listeners before each test to maintain isolation. * test: enhance tracing tests with mock authentication token - Added a mock authentication token to the tracing tests to ensure proper setup and event collection. - Updated test methods to include the mock token, improving isolation and reliability of tests related to the TraceListener and BatchManager. - Ensured that the tests validate the correct behavior of event collection during crew execution. * test: refactor tracing tests to improve mock usage - Moved the mock authentication token patching inside the test class to enhance readability and maintainability. - Updated test methods to remove unnecessary mock parameters, streamlining the test signatures. - Ensured that the tests continue to validate the correct behavior of event collection during crew execution while improving isolation. * test: refactor tracing tests for improved mock usage and consistency - Moved mock authentication token patching into individual test methods for better clarity and maintainability. - Corrected the backstory string in the `Agent` instantiation to fix a typo. - Ensured that all tests validate the correct behavior of event collection during crew execution while enhancing isolation and readability. * test: add new tracing test for disabled trace listener - Introduced a new test case to verify that the trace listener does not make HTTP calls when tracing is disabled via environment variables. - Enhanced existing tests by mocking PlusAPI HTTP calls to avoid authentication and network requests, improving test isolation and reliability. - Updated the test setup to ensure proper initialization of the trace listener and its components during crew execution. * refactor: update LLM class to utilize new completion function and improve cost calculation - Replaced direct calls to `litellm.completion` with a new import for better clarity and maintainability. - Introduced a new optional attribute `completion_cost` in the LLM class to track the cost of completions. - Updated the handling of completion responses to ensure accurate cost calculations and improved error handling. - Removed outdated test cassettes for gemini models to streamline test suite and avoid redundancy. - Enhanced existing tests to reflect changes in the LLM class and ensure proper functionality. * test: enhance tracing tests with additional request and response scenarios - Added new test cases to validate the behavior of the trace listener and batch manager when handling 404 responses from the tracing API. - Updated existing test cassettes to include detailed request and response structures, ensuring comprehensive coverage of edge cases. - Improved mock setup to avoid unnecessary network calls and enhance test reliability. - Ensured that the tests validate the correct behavior of event collection during crew execution, particularly in scenarios where the tracing service is unavailable. * feat: enable conditional tracing based on environment variable - Added support for enabling or disabling the trace listener based on the `CREWAI_TRACING_ENABLED` environment variable. - Updated the `Crew` class to conditionally set up the trace listener only when tracing is enabled, improving performance and resource management. - Refactored test cases to ensure proper cleanup of event bus listeners before and after each test, enhancing test reliability and isolation. - Improved mock setup in tracing tests to validate the behavior of the trace listener when tracing is disabled. * fix: downgrade litellm version from 1.74.9 to 1.74.3 - Updated the `pyproject.toml` and `uv.lock` files to reflect the change in the `litellm` dependency version. - This downgrade addresses compatibility issues and ensures stability in the project environment. * refactor: improve tracing test setup by moving mock authentication token patching - Removed the module-level patch for the authentication token and implemented a fixture to mock the token for all tests in the class, enhancing test isolation and readability. - Updated the event bus clearing logic to ensure original handlers are restored after tests, improving reliability of the test environment. - This refactor streamlines the test setup and ensures consistent behavior across tracing tests. * test: enhance tracing test setup with comprehensive mock authentication - Expanded the mock authentication token patching to cover all instances where `get_auth_token` is used across different modules, ensuring consistent behavior in tests. - Introduced a new fixture to reset tracing singleton instances between tests, improving test isolation and reliability. - This update enhances the overall robustness of the tracing tests by ensuring that all necessary components are properly mocked and reset, leading to more reliable test outcomes. * just drop the test for now * refactor: comment out completion-related code in LLM and LLM event classes - Commented out the `completion` and `completion_cost` imports and their usage in the `LLM` class to prevent potential issues during execution. - Updated the `LLMCallCompletedEvent` class to comment out the `response_cost` attribute, ensuring consistency with the changes in the LLM class. - This refactor aims to streamline the code and prepare for future updates without affecting current functionality. * refactor: update LLM response handling in LiteAgent - Commented out the `response_cost` attribute in the LLM response handling to align with recent refactoring in the LLM class. - This change aims to maintain consistency in the codebase and prepare for future updates without affecting current functionality. * refactor: remove commented-out response cost attributes in LLM and LiteAgent - Commented out the `response_cost` attribute in both the `LiteAgent` and `LLM` classes to maintain consistency with recent refactoring efforts. - This change aligns with previous updates aimed at streamlining the codebase and preparing for future enhancements without impacting current functionality. * bring back litellm upgrade version
113 lines
2.9 KiB
Python
113 lines
2.9 KiB
Python
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
|
|
|
|
from crewai.utilities.events.base_events import BaseEvent
|
|
|
|
if TYPE_CHECKING:
|
|
from crewai.crew import Crew
|
|
else:
|
|
Crew = Any
|
|
|
|
|
|
class CrewBaseEvent(BaseEvent):
|
|
"""Base class for crew events with fingerprint handling"""
|
|
|
|
crew_name: Optional[str]
|
|
crew: Optional[Crew] = None
|
|
|
|
def __init__(self, **data):
|
|
super().__init__(**data)
|
|
self.set_crew_fingerprint()
|
|
|
|
def set_crew_fingerprint(self) -> None:
|
|
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
|
|
|
|
def to_json(self, exclude: set[str] | None = None):
|
|
if exclude is None:
|
|
exclude = set()
|
|
exclude.add("crew")
|
|
return super().to_json(exclude=exclude)
|
|
|
|
|
|
class CrewKickoffStartedEvent(CrewBaseEvent):
|
|
"""Event emitted when a crew starts execution"""
|
|
|
|
inputs: Optional[Dict[str, Any]]
|
|
type: str = "crew_kickoff_started"
|
|
|
|
|
|
class CrewKickoffCompletedEvent(CrewBaseEvent):
|
|
"""Event emitted when a crew completes execution"""
|
|
|
|
output: Any
|
|
type: str = "crew_kickoff_completed"
|
|
total_tokens: int = 0
|
|
|
|
|
|
class CrewKickoffFailedEvent(CrewBaseEvent):
|
|
"""Event emitted when a crew fails to complete execution"""
|
|
|
|
error: str
|
|
type: str = "crew_kickoff_failed"
|
|
|
|
|
|
class CrewTrainStartedEvent(CrewBaseEvent):
|
|
"""Event emitted when a crew starts training"""
|
|
|
|
n_iterations: int
|
|
filename: str
|
|
inputs: Optional[Dict[str, Any]]
|
|
type: str = "crew_train_started"
|
|
|
|
|
|
class CrewTrainCompletedEvent(CrewBaseEvent):
|
|
"""Event emitted when a crew completes training"""
|
|
|
|
n_iterations: int
|
|
filename: str
|
|
type: str = "crew_train_completed"
|
|
|
|
|
|
class CrewTrainFailedEvent(CrewBaseEvent):
|
|
"""Event emitted when a crew fails to complete training"""
|
|
|
|
error: str
|
|
type: str = "crew_train_failed"
|
|
|
|
|
|
class CrewTestStartedEvent(CrewBaseEvent):
|
|
"""Event emitted when a crew starts testing"""
|
|
|
|
n_iterations: int
|
|
eval_llm: Optional[Union[str, Any]]
|
|
inputs: Optional[Dict[str, Any]]
|
|
type: str = "crew_test_started"
|
|
|
|
|
|
class CrewTestCompletedEvent(CrewBaseEvent):
|
|
"""Event emitted when a crew completes testing"""
|
|
|
|
type: str = "crew_test_completed"
|
|
|
|
|
|
class CrewTestFailedEvent(CrewBaseEvent):
|
|
"""Event emitted when a crew fails to complete testing"""
|
|
|
|
error: str
|
|
type: str = "crew_test_failed"
|
|
|
|
|
|
class CrewTestResultEvent(CrewBaseEvent):
|
|
"""Event emitted when a crew test result is available"""
|
|
|
|
quality: float
|
|
execution_duration: float
|
|
model: str
|
|
type: str = "crew_test_result"
|