Skip to content

[BREAKING] Python: Refactor SharedState to State with sync methods and superstep caching - #3667

Merged
Tao Chen (TaoChenOSU) merged 9 commits into
microsoft:mainfrom
moonbox3:workflows-state-update
Feb 5, 2026
Merged

[BREAKING] Python: Refactor SharedState to State with sync methods and superstep caching#3667
Tao Chen (TaoChenOSU) merged 9 commits into
microsoft:mainfrom
moonbox3:workflows-state-update

Conversation

@moonbox3

Copy link
Copy Markdown
Contributor

Motivation and Context

Refactors the workflow state management system with breaking changes:

  • Rename SharedState -> State class and _shared_state.py -> _state.py
  • Convert all async methods to sync (Python dicts are thread-safe; async was unnecessary overhead)
  • Implement superstep caching: writes go to pending cache, committed at superstep boundary via commit(), which is now consistent with the .NET behavior.
  • Add get(key, default=None) API that returns default instead of raising KeyError
  • Add has(key) method for existence checks
  • Rename WorkflowCheckpoint.shared_stateWorkflowCheckpoint.state
  • Remove State from public exports (internal implementation detail)

Breaking Changes

Before After
SharedState State
ctx.shared_state ctx.state
await ctx.get_shared_state(key) ctx.get_state(key, default=None)
await ctx.set_shared_state(key, value) ctx.set_state(key, value)
checkpoint.shared_state checkpoint.state

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings February 4, 2026 06:33
@moonbox3 Evan Mattson (moonbox3) added python Usage: [Issues, PRs], Target: Python workflows Usage: [Issues, PRs], Target: Workflows breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible labels Feb 4, 2026
@github-actions github-actions Bot changed the title [BREAKING] Python: Refactor SharedState to State with sync methods and superstep caching Python: [BREAKING] Python: Refactor SharedState to State with sync methods and superstep caching Feb 4, 2026
@markwallace-microsoft Mark Wallace (markwallace-microsoft) added the documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs label Feb 4, 2026
@markwallace-microsoft

Mark Wallace (markwallace-microsoft) commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework/_workflows
   _agent_executor.py1602286%98, 146, 164–165, 216–217, 219–220, 252–254, 262–264, 274–276, 278, 282, 286, 290–291
   _checkpoint.py121298%184–185
   _checkpoint_summary.py27485%36–39
   _const.py60100% 
   _edge_runner.py1621391%53, 58, 71, 138–139, 143, 150, 206, 211, 355–356, 360, 401
   _executor.py1731094%212, 334, 336, 345, 365, 368, 475, 480, 490, 649
   _runner.py2183285%132–133, 176–179, 183, 224–226, 251–252, 254, 289–291, 315–319, 323, 358, 362, 364, 370, 378–381, 394, 430
   _runner_context.py168696%84, 87, 383, 403, 491, 495
   _state.py430100% 
   _workflow.py2681992%89, 267–269, 271–272, 290, 294, 322, 424, 705, 747, 752, 755, 774–776, 789, 857
   _workflow_context.py157994%62–63, 71, 75, 89, 165, 190, 308, 427
   _workflow_executor.py1734375%96, 445, 456, 468–471, 474–476, 479–480, 482, 485–487, 490–494, 498–499, 508, 513, 547, 573–578, 581, 584, 592, 597, 608, 618, 622, 628, 632, 642, 646
TOTAL16362191388% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3989 221 💤 0 ❌ 0 🔥 1m 5s ⏱️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a breaking refactoring of workflow state management, renaming SharedState to State, converting all async methods to sync, and implementing superstep caching semantics to align with .NET behavior.

Changes:

  • Renamed SharedState class to State and file _shared_state.py to _state.py
  • Converted all state methods from async to sync (removing asyncio.Lock)
  • Implemented superstep caching: writes go to pending buffer, committed at boundaries via commit()
  • Added get(key, default=None) API and has(key) method
  • Renamed WorkflowCheckpoint.shared_stateWorkflowCheckpoint.state
  • Updated all references across codebase (workflow context, runner, executors, tests, samples)

Reviewed changes

Copilot reviewed 47 out of 47 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
_state.py New State class with sync methods and superstep caching implementation
_workflow.py Updated to use State with commit() call after kwargs initialization
_runner.py Integrated commit() at superstep boundaries
_workflow_context.py Changed to sync get_state/set_state methods
_checkpoint.py Renamed shared_state field to state
__init__.py Updated exports (but State still exported - should be removed)
Test files Updated all test mocks and assertions to use State
Sample files Updated comments and documentation references
Frontend Updated TypeScript interfaces and references

Comment thread python/packages/core/agent_framework/_workflows/_state.py Outdated
Comment thread python/packages/core/agent_framework/_workflows/_state.py Outdated
Comment thread python/packages/core/agent_framework/_workflows/_state.py Outdated
Comment thread python/packages/core/agent_framework/_workflows/__init__.py Outdated
@moonbox3 Evan Mattson (moonbox3) changed the title Python: [BREAKING] Python: Refactor SharedState to State with sync methods and superstep caching [BREAKING] Python: Refactor SharedState to State with sync methods and superstep caching Feb 4, 2026
Comment thread python/packages/core/agent_framework/_workflows/_checkpoint.py Outdated
Comment thread python/packages/core/agent_framework/_workflows/_state.py
Comment thread python/packages/core/agent_framework/_workflows/_agent_executor.py Outdated
Comment thread python/packages/core/agent_framework/_workflows/_workflow_context.py Outdated
@TaoChenOSU
Tao Chen (TaoChenOSU) added this pull request to the merge queue Feb 5, 2026
Merged via the queue into microsoft:main with commit 10afb86 Feb 5, 2026
36 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in Agent Framework Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python workflows Usage: [Issues, PRs], Target: Workflows

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Python: Clean up public API surface and kwargs propagation Python: Refactor State class - rename, simplify, and implement superstep caching

6 participants