Repository navigation
fix(checkpoint): restore hierarchical crews from checkpoints - #8646
subhashpolisetti wants to merge 1 commit into
Conversation
Strix Security ReviewWarning This pull request has 1 commit after the last Strix review ( ✅ No open security findings. PR summary: Fixes checkpoint restore for crews whose agents hold delegation tools (hierarchical managers and `AgentTools(...).tools()`): the `BaseTool` core-schema validator now forwards the pydantic validation context, and `BaseAgentTool.agents` resolves serialized agents via `_resolve_agent`, so the saved agent ids are no longer rejected as user-set during restore. Review summaryThe two changed source files only thread pydantic's validation context through a wrap validator ( Review 1 on this PR · Reviewed by Strix |
A checkpoint of a crew whose agents hold delegation tools could not be restored. The manager of every hierarchical crew holds them, as does any agent given AgentTools(...).tools(). Crew.from_checkpoint failed with "This field is not to be set by the user" on the coworker agents' ids. The BaseTool validator rebuilt serialized tools without the validation context, so the nested agents never saw from_checkpoint. Pass the context through, and resolve BaseAgentTool.agents with _resolve_agent like Task.agent and Crew.manager_agent already do.
b6d639a to
612af90
Compare
Related issue
Fixes #8645
Summary
A checkpoint of a crew whose agents hold delegation tools could not be restored: the manager of every
hierarchical crew, or any agent given
AgentTools(...).tools().Crew.from_checkpointraised aValidationError("This field is not to be set by the user") on the coworker agents' saved
id.The
BaseToolvalidator rebuilt a serialized tool withmodel_validate(data)and dropped the validation context,so the agents inside
BaseAgentTool.agentsnever sawfrom_checkpoint. This passes the context through, andresolves
BaseAgentTool.agentswith_resolve_agent, the same hookTask.agentandCrew.manager_agentuse.Only checkpoint restore passes a context, so validating tools anywhere else is unchanged, and the
idguard stillrejects a user-set id everywhere outside restore. The restored tools are not what a resumed run delegates with:
_update_manager_toolsstill builds fresh ones fromcrew.agentsper task.Verification
TestDelegationToolCheckpointRestorecovers both paths: a hierarchical crew checkpointed afterkickoff()andresumed with
kickoff(from_checkpoint=...)andakickoff(from_checkpoint=...), and an agent withAgentTools(...).tools()round-tripped throughRuntimeState. All three fail onmainwith themay_not_set_fielderror and pass with the fix.test_user_set_coworker_id_still_rejectedis a control: adelegation tool validated without the checkpoint context still rejects a user-set coworker id, on
mainand withthe fix. The issue repro also restores, and a resumed
kickoff()of atwo-task hierarchical crew completes the second task.
lib/crewai/tests/: 6350 passed, 44 skipped (Python 3.13)test_checkpoint.pyandtests/tools/agent_tools/also pass on Python 3.10ruff check,ruff format,mypycleanAdditional context
#8596 and #8625 also edit
_resolve_tool_dict(callback andTool.funcrestore). Neither passes thecontext through, so this is independent of both.