-
Notifications
You must be signed in to change notification settings - Fork 2
Add a typed-context API #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 15797215531Details
💛 - Coveralls |
def state(self) -> InMemoryStateManager[MODEL_T]: | ||
# Default to DictState if no state manager is initialized | ||
if self._state_manager is None: | ||
self._state_manager = InMemoryStateManager(DictState()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't we use the init method here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the init method is async, and we can't have an async @property
👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
special case since we don't need to check the existing class (there is none)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a comment about an indirection level it would be nice to remove if possible
self._state_manager = InMemoryStateManager(state_class) | ||
|
||
@property | ||
def state(self) -> InMemoryStateManager[MODEL_T]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect that state
returns the state I specified to be MyState
but I get a manager instead. A yellow flag this might be a problem is the get_all
and set_all
methods, where it's not clear what all
is.
I haven't tried but I think we have two options to align semantic here:
- We make the existence of the manager explicit: this proporty becomes
state_manager
and setter/getter become a writable propertyctx.state_manager.state
. - We remove the concept of the manager, moving its code to a base
State
class thatMyState
must inherit from. This way this property could return the actualMODEL_T
state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for 1. ctx.state_manager.state
can't work unless we make it async. get_state()
?
oh interesting idea on 2 🤔 But It also removes the general idea of async. The reason I've made it async is I can imagine a future where the state for a workflow may live in some db (and the state could be so large that you might avoid loading the entire thing and use the get/set methods instead)
If that doesn't sound valuable I can just remove all async and go the 2 route
This PR adds an opt-in typed-context state. This effectively replaces the old get/set API
By default, the state is effectively an untyped dict (taking advantage of the base
Event
class features). This means users will see no breaking change in core usage, and the existing serdes flow continues to work.However, users can also opt-in to a typed state experience.
Design:
Limitations:
ctx.clear
might need to be deprecated because its not asyncDeprecations/Breaking Changes
ctx.data
,ctx._serialize_globals
, andctx._globals
ctx.get()
andctx.set()
in favor ofctx.state.get()
andctx.state.set()