Step 3: Add a Request Form to your Workflow#

At this point, you should have a workflow in workflow/hello_workflow.py that uses the @workflow decorator to specify the workflow’s name ('Hello Workflow'), id ('hello_workflow'), and lab ('lab_b4bdcb5b-578e-4240-8805-de66eaba8b19').

Now that we have a workflow, it would be nice to be able to specify parameters when running the workflow in LabOps. For example, a user might want to run a workflow on different numbers of plates, or with shortened incubation timings for testing. You might also want to set up this workflow to run in response to parameterized requests generated in your LIMS system.

This tutorial will walk you through how to do just that.

Add a Parameter to your Workflow#

To add a parameter to the workflow, we’ll use the @parameter decorator. Replace the code in your workflow with the following snippet (again replacing lab_id with the id of the lab you created in your Artificial instance)

from artificial.workflows.decorators import workflow, parameter
from artificial.workflows.runtime import show_info

@workflow('Hello Workflow',
          'hello_workflow',
          'lab_id')
@parameter('hello_message', {'required': True, 'uiTitle': 'Hello Message'})
async def hello_workflow(hello_message: str = "Hello World") -> None:
    await show_info(hello_message)

Let’s walk through the changes we’ve made:

@parameter('hello_message', {'required': True, 'uiTitle': 'Hello Message'})

@parameter is a decorator that marks the hello_workflow function as taking a parameter. This decorator specifies the parameter name ('hello_message'), whether the parameter is required, and the label that will be used for the text field in the Request form ('Hello Message').

async def hello_workflow(hello_message: str = "Hello World") -> None:

We have added our parameter as an argument to the hello_workflow function and marked it as being a string with a default value of “Hello World”. The name of the argument should match the name of the parameter. When a user runs this workflow in LabOps, the value they enter for the parameter into the Request form will be passed as the value of this argument.

await show_info(hello_message)

We use the hello_message argument in our call to the show_info action instead of the hard-coded string we used previously.

Now publish the workflow and run it in LabOps to see the generated Request form. Notice that the value you enter for the parameter in the Request form appears in the info message.

For more information about adding Request Parameters to your workflow see Workflow Parameters.