.. _create_first_workflow: ================================== Step 2: Create your first Workflow ================================== At this point, you should have a Codespace that is configured to securely connect to your Artificial Cloud. This tutorial will walk you through writing your first workflow. .. note:: Please note that this tutorial presumes that you have already created your first `Lab `_ and first `Assistant `_ in your Artificial instance. What is a workflow? =================== Wouldn't it be nice to be able to connect and automate the instruments, software and even people in your lab? A Workflow is a script written in :doc:`orchestration_python` that runs in the Artificial Runtime in the cloud and can call Actions to run protocols on instruments, upload data to your LIMS, display Assistants for manual work, and much more. Create a workflow ========================== .. video:: _static/create_hello_workflow.mp4 :autoplay: :muted: :loop: #. Create a new file :file:`workflow/hello_workflow.py`. #. Copy and paste the following Orchestration Python (OP) snippet into this file, replacing ``lab_id`` with the id of the lab you created in your Artificial instance. See :doc:`finding_ids` for help with locating IDs for Labs and Assistants in Artificial. .. code-block:: python from artificial.workflows.decorators import workflow from artificial.workflows.runtime import show_info @workflow('Hello Workflow', 'hello_workflow', 'lab_id') async def hello_workflow() -> None: await show_info("Hello World") Let's walk through what this code does. .. code-block:: python @workflow('Hello Workflow', 'hello_workflow', 'lab_id') :deco:`~artificial.workflows.decorators.workflow` is called a "decorator" and marks the ``hello_workflow`` function as a workflow. It tells Artificial the workflow name (``'Hello Workflow'``), the workflow's unique id (``'hello_workflow'``), and which lab the workflow is built for (``'lab_id'``--don't forget to replace this with the id of the lab you created in your Artificial instance). The Artificial SDK provides lots of :doc:`decorators `; we'll explore several more in the next few tutorials. .. code-block:: python async def hello_workflow() -> None: This declares the workflow function; when a user runs the workflow in LabOps, this is the function that will run. To keep things manageable, the name of the function should match the unique id of the workflow. We also mark workflow functions as ``async`` because sometimes they can take a long time to run--up to months or even years for some complicated cell culture workflows. .. code-block:: python await show_info("Hello World") :doc:`show_info ` is an action that displays the given message in the LabOps console. It's useful for sending messages to the person running the workflow and also for debugging. We prefix action calls with ``await`` because some actions can take a long time to run (e.g. a multi-hour incubation or instrument protocol). Publish your workflow ===================== .. video:: _static/publish_hello_workflow.mp4 :autoplay: :muted: :loop: #. Click the Artificial Logo in the left pane. #. Open the :guilabel:`Workflow Publishing` folder. #. Find the workflow you just created and click the "Publish Workflow" icon to the right of the workflow name. As you continue to edit your workflow, you can also use the "Publish Workflow" quick link that appears just above the :deco:`workflow` decorator in your editor window: .. image:: _static/publish_workflow_shortcut.png Run your workflow ================= Then, use LabOps to run this workflow and see the message. .. video:: _static/run_hello_workflow.mp4 :autoplay: :muted: :loop: