Python: Add checkpoint save and restore hooks to executor#2097
Merged
TaoChenOSU merged 11 commits intomicrosoft:mainfrom Nov 17, 2025
Merged
Conversation
TaoChenOSU
commented
Nov 11, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new checkpoint state management contract for executors by adding on_checkpoint_save() and on_checkpoint_restore() hooks to the Executor base class. This replaces the pattern of using ctx.get_executor_state() and ctx.set_executor_state() for managing executor state during checkpointing.
Key Changes:
- New checkpoint hooks (
on_checkpoint_saveandon_checkpoint_restore) on the Executor base class - Deprecation of
set_executor_stateandget_executor_statemethods in WorkflowContext - New workflow events (
SuperStepStartedEventandSuperStepCompletedEvent) for tracking superstep boundaries - Backward compatibility maintained by supporting both old (
snapshot_state/restore_state) and new checkpoint methods
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
_executor.py |
Added on_checkpoint_save() and on_checkpoint_restore() hooks to Executor base class with documentation |
_runner.py |
Updated checkpoint save/restore logic to call new hooks while maintaining backward compatibility; added superstep event emission |
_workflow_context.py |
Deprecated set_executor_state() and get_executor_state() methods with migration guidance |
_events.py |
Added SuperStepEvent, SuperStepStartedEvent, and SuperStepCompletedEvent classes; simplified ExecutorInvokedEvent and ExecutorCompletedEvent |
_workflow_executor.py |
Refactored WorkflowExecutor to use new checkpoint hooks instead of manual state loading; removed _state_loaded flag |
_agent_executor.py |
Updated AgentExecutor to use on_checkpoint_save() and on_checkpoint_restore() |
_magentic.py |
Converted all magentic executors from snapshot_state/restore_state to new checkpoint hooks |
_handoff.py |
Updated HandoffCoordinator to use base class checkpoint methods via pattern metadata hooks |
_base_group_chat_orchestrator.py |
Updated base orchestrator to use new checkpoint hooks |
__init__.py / __init__.pyi |
Exported new SuperStep event types |
| Sample files | Updated all checkpoint samples to demonstrate new executor state management pattern |
| Test files | Updated tests to use new checkpoint hook names; converted sync test to async |
python/samples/getting_started/workflows/checkpoint/sub_workflow_checkpoint.py
Show resolved
Hide resolved
python/samples/getting_started/workflows/checkpoint/checkpoint_with_resume.py
Show resolved
Hide resolved
python/packages/core/agent_framework/_workflows/_base_group_chat_orchestrator.py
Outdated
Show resolved
Hide resolved
Member
moonbox3
reviewed
Nov 12, 2025
python/packages/core/agent_framework/_workflows/_workflow_context.py
Outdated
Show resolved
Hide resolved
python/packages/core/agent_framework/_workflows/_workflow_context.py
Outdated
Show resolved
Hide resolved
python/packages/core/agent_framework/_workflows/_workflow_executor.py
Outdated
Show resolved
Hide resolved
moonbox3
approved these changes
Nov 14, 2025
eavanvalkenburg
approved these changes
Nov 17, 2025
arisng
pushed a commit
to arisng/agent-framework
that referenced
this pull request
Feb 2, 2026
…2097) * Add checkpoint hooks * Deprecate get_executor_state and set_executor_state * Fix tests and samples * Add doc strings * Add sample * Fix import * Address comments and fix tests * Address comments * conditional import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Closes #1816
Description
This PR adds the following:
on_checkpoint_saveandon_checkpoint_restorecontracts on the executor base class that will get invoked when creating a checkpoint and restoring from a checkpoint. This will allow users to have a clear contract to save executor states for checkpointing.SuperStepStartedEventandSuperStepCompletedEventContribution Checklist