-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: V2 Workflows and Steps #5
Conversation
|
Nice! I think this makes a lot of sense and I am very happy with the cleanup for registration and types! I want to discuss briefly implications of #7 as I think we might want to consider moving in the direction of "all things are functions" where dags are functions that orchestrate functions... lets discuss there for a bit. Wrt naming convention, I'm not sure what is most pythonic but i don't like Impl and perhaps we should have |
Great, thanks for the feedback! Re: naming - I don't think adding |
|
BaseWorkflow makes sense to me. |
This is a lot, but please read it - I need some feedback in a couple of spots :)
This PR implements the V2 SDK's definitions of workflows and steps (standalone functions soon to come). There's a lot going on here, sorry about that 😄
First, some things less related to workflows:
Stepclass that's has a generic param (the return type), which implementscallandacallmethods and has all the same parameters as the old steps, just as a class as opposed to as a function. This helps type checking a lot - we can know the return type of the step (at least in generic terms) in the other places in the code, can access attributes correctly, and so on.Stepis passed around everywhere now, so there's much less of a notion of an "action function". Instead, we just pass the step and figure out how to call it depending on if it'sis_async_functionisTrueorFalse. This is also a dramatic improvement for type checking, e.g. here or hereisinstance(..., Step))For the workflows themselves:
WorkflowConfig, which is configuration for a workflow (name, etc.), we have aWorkflowDeclaration, which is generic with the type of the input to the workflow, and has methods forrun, etc. (justrunandworkflow_inputright now but will extend), and we haveBaseWorkflowImpl, which is a base class intended to be inherited from in a Pydantic-y fashion, and have config passed as a class variable (similar to how Pydantic handlesmodel_configby allowing you to pass aConfigDict).Hatchetclass now has an instance methoddeclare_workflow, which takes workflow config keyword arguments and returns a typedDeclarativeWorkflowobject, which you can pass to your workflow class that inherits fromBaseWorkflowImpl. Importantly, this behavior is opt-in. If you don't pass any config, we fall back to the old workflow behavior where you used@workflow()with no paramsCheck out the simple and v2 examples for more of a sense of how this is intended to work. In the v2 example, the type checker is happy all the way through - it knows the type of the workflow input when it reads it from the context in the step, it knows the type of the input when we go to trigger the workflow, it infers the name of the workflow to trigger, and so on.
Important feedback I'd love:
Declaration/Impl/ abuse ofWorkflow?Miscellaneous notes:
if TYPE_CHECKINGand such - don't worry about that for now. I'll do my best to fix it later.