mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-04-15 23:42:37 +00:00
fix: eliminate PydanticSerializationUnexpectedValue warnings
Switch RuntimeState serializer from mode="wrap" to mode="plain" with dict return type so pydantic doesn't re-serialize entities through the Entity union pipeline. Also switch to string-based field discriminator for Entity union.
This commit is contained in:
@@ -192,15 +192,13 @@ try:
|
||||
|
||||
from typing import Annotated
|
||||
|
||||
from pydantic import Discriminator, Tag
|
||||
from pydantic import Field
|
||||
|
||||
from crewai.state.runtime import RuntimeState, _entity_discriminator
|
||||
from crewai.state.runtime import RuntimeState
|
||||
|
||||
Entity = Annotated[
|
||||
Annotated[Flow, Tag("flow")] # type: ignore[type-arg]
|
||||
| Annotated[Crew, Tag("crew")]
|
||||
| Annotated[Agent, Tag("agent")],
|
||||
Discriminator(_entity_discriminator),
|
||||
Flow | Crew | Agent, # type: ignore[type-arg]
|
||||
Field(discriminator="entity_type"),
|
||||
]
|
||||
|
||||
RuntimeState.model_rebuild(
|
||||
|
||||
@@ -15,7 +15,6 @@ from pydantic import (
|
||||
ModelWrapValidatorHandler,
|
||||
PrivateAttr,
|
||||
RootModel,
|
||||
SerializerFunctionWrapHandler,
|
||||
model_serializer,
|
||||
model_validator,
|
||||
)
|
||||
@@ -84,10 +83,10 @@ class RuntimeState(RootModel): # type: ignore[type-arg]
|
||||
"""The execution event record."""
|
||||
return self._event_record
|
||||
|
||||
@model_serializer(mode="wrap")
|
||||
def _serialize(self, handler: SerializerFunctionWrapHandler) -> CheckpointPayload:
|
||||
@model_serializer(mode="plain")
|
||||
def _serialize(self) -> dict[str, Any]:
|
||||
return {
|
||||
"entities": handler(self),
|
||||
"entities": [e.model_dump() for e in self.root],
|
||||
"event_record": self._event_record.model_dump(),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user