mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-24 15:48:23 +00:00
Implement CrewAIBaseModel and Update to ConfigDict (#29)
New CrewAIBaseModel: Base for Agent, Crew, Task. Includes generated, frozen UUID. Adds hashing capability Migrate to ConfigDict: Replaces class Config with model_config, see this deprecation note . Benefits: Adds auditing capability with frozen UUIDs.
This commit is contained in:
24
crewai/base/model.py
Normal file
24
crewai/base/model.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import uuid
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import UUID4, BaseModel, Field, field_validator
|
||||
from pydantic_core import PydanticCustomError
|
||||
|
||||
|
||||
class CrewAIBaseModel(BaseModel):
|
||||
"""Base model with unique identifier."""
|
||||
|
||||
__hash__ = object.__hash__
|
||||
id: UUID4 = Field(
|
||||
default_factory=uuid.uuid4,
|
||||
frozen=True,
|
||||
description="Unique identifier for the object, not set by user.",
|
||||
)
|
||||
|
||||
@field_validator("id", mode="before")
|
||||
@classmethod
|
||||
def _deny_user_set_id(cls, v: Optional[UUID4]) -> None:
|
||||
if v:
|
||||
raise PydanticCustomError(
|
||||
"may_not_set_field", "This field is not to be set by the user.", {}
|
||||
)
|
||||
Reference in New Issue
Block a user