mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-01 07:13:00 +00:00
fix: restore Flow subclass on checkpoint resume
Flow.from_checkpoint deserializes as base Flow (entity_type discriminator), losing subclass methods and state type. When called on a subclass like MyFlow.from_checkpoint(), create a cls instance and transfer the checkpoint fields so @start methods, listeners, and structured state are available.
This commit is contained in:
@@ -938,12 +938,21 @@ class Flow(BaseModel, Generic[T], metaclass=FlowMeta):
|
|||||||
)
|
)
|
||||||
crewai_event_bus.set_runtime_state(state)
|
crewai_event_bus.set_runtime_state(state)
|
||||||
for entity in state.root:
|
for entity in state.root:
|
||||||
|
if not isinstance(entity, Flow):
|
||||||
|
continue
|
||||||
|
if entity.execution_context is not None:
|
||||||
|
apply_execution_context(entity.execution_context)
|
||||||
if isinstance(entity, cls):
|
if isinstance(entity, cls):
|
||||||
if entity.execution_context is not None:
|
|
||||||
apply_execution_context(entity.execution_context)
|
|
||||||
entity._restore_from_checkpoint()
|
entity._restore_from_checkpoint()
|
||||||
return entity
|
return entity
|
||||||
raise ValueError(f"No {cls.__name__} found in checkpoint: {path}")
|
instance = cls()
|
||||||
|
instance.checkpoint_completed_methods = entity.checkpoint_completed_methods
|
||||||
|
instance.checkpoint_method_outputs = entity.checkpoint_method_outputs
|
||||||
|
instance.checkpoint_method_counts = entity.checkpoint_method_counts
|
||||||
|
instance.checkpoint_state = entity.checkpoint_state
|
||||||
|
instance._restore_from_checkpoint()
|
||||||
|
return instance
|
||||||
|
raise ValueError(f"No Flow found in checkpoint: {path}")
|
||||||
|
|
||||||
checkpoint_completed_methods: set[str] | None = Field(default=None)
|
checkpoint_completed_methods: set[str] | None = Field(default=None)
|
||||||
checkpoint_method_outputs: list[Any] | None = Field(default=None)
|
checkpoint_method_outputs: list[Any] | None = Field(default=None)
|
||||||
|
|||||||
Reference in New Issue
Block a user