Skip to main content
Branching logic allows workflows to take different actions based on runtime conditions. Instead of following a single linear path, complex workflows may need to:
  • take different actions based on page content
  • handle success and failure cases differently
  • take additional steps or skip steps when certain conditions are met.

Building branches

The productionize agent infers and builds branches in the production file from your conversation history. For example, a state dropdown on a healthcare form may have additional questions depending on the state selected. State dropdown Given the following test data:
data/variables.json
{
  "Medical License": "7676789",
  "Status": "Pending Registration"
}
With the following prompt:
Fill out the new questions since California requires additional
information. Keep going with the form after.
The agent generates the following branch in the production file:
workspace/flow.py
import asyncio
import json
from servers.browser_tools import click, type, select_option, send_keys, scroll

async def main():
    with open("/home/chrome_user/agent/data/variables.json", "r") as f:
        variables = json.load(f)

    # Service state selection
    await select_option(selector="select#serviceState", label=variables["state"])
    await send_keys(keys=["Escape"])

    # Additional State fields if California
    if variables.get("state") == "California":
        await click(selector="input#caLicense")
        await type(text=variables["Medical License"])
        await select_option(selector="select#curesStatus", label=variables["Status"])

    # Scroll to continue button
    await scroll(pixels=500)

asyncio.run(main())

Using configs

Use variables to build configurations that modify workflow behavior. This lets you maintain a single workflow while changing end states or actions based on config flags.
data/variables.json
{
  "save_output_as_pdf": true,
  "submit": false
}
The production flow can then branch based on these configs:
workspace/flow.py
import asyncio
import json
from servers.browser_tools import click

async def main():
    with open("/home/chrome_user/agent/data/variables.json", "r") as f:
        variables = json.load(f)

    if variables.get("save_output_as_pdf"):
        await click(selector="button#export")
        await click(selector="option[value='pdf']")

asyncio.run(main())