-
Notifications
You must be signed in to change notification settings - Fork 20
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
[PoC]: Declarative Workflows in V2 SDK #292
base: main
Are you sure you want to change the base?
Conversation
workflow_input = greet_workflow.workflow_input(ctx) | ||
greeting = workflow_input.greeting |
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.
these type check correctly, so no need to cast
or parse from a dict to an ExampleInput
input=language_counter_workflow.construct_spawn_workflow_input( | ||
input=workflow_input | ||
), |
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.
types are enforced here, so you know the shape of input
in your IDE + at type checking time
@greet_workflow.declare() | ||
async def greet(ctx: Context) -> dict[Literal["message"], str]: |
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.
single decorator to register a function in Hatchet
workflow_input = greet_workflow.workflow_input(ctx) | ||
greeting = workflow_input.greeting | ||
|
||
await language_counter_workflow.spawn( |
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.
refer to the workflow as an object instead of passing a string with the name
greeting = language_counter_workflow.workflow_input(ctx).greeting | ||
|
||
match greeting: |
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.
type checking here for greeting
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.
not super experienced in Python so probably don't understand the nuances here, but looks good
@grutt Think we should merge this or wait for a couple weeks till we have the real V2 hopefully done? |
This is an initial PoC for declarative workflows in the V2 SDK. We're seeking to accomplish a couple of things here:
I added Pydantic support to the V2 SDK here, and then added a
DeclarativeWorkflow
(we can rename this to step, function, etc. if we want) generic-typed class that lets the user declaratively define their workflows and share the definitions across the codebase. The example provided should hopefully give a sense of what's possible with this approach.The TL;DR is that with just a few lines of code in the
workflow.py
in the example, we get type checking for workflow inputs, both when accessing them with<< workflow >>.workflow_input()
and when spawning them with<< workflow >>.spawn()
or<< workflow >>.run()
. We also get "name-inference", meaning we don't need to pass a string value for the name of the workflow (or step or function) when we spawn it, which is another possible cause of errors in the current SDK.Here are a few results from running the example here:
First
greet
run:First child (counter) run
Second greet run:
Second child run:
Pydantic support: