Skip to main content
Complex web forms often have hundreds of questions with conditional logic — different fields appear based on previous answers, selected states, insurance types, or provider specialties. Branching logic allows workflows to handle all of these paths.

Building branches

As you build in the editor, Simplex infers and builds branches in the production flow.py file from your conversation. 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())

Runtime branch detection

When a production workflow encounters a form path it hasn’t seen before, Simplex can detect new questions and branches at runtime. You can configure workflows to pause when this happens, allowing you to update the workflow in the editor to handle the new branch, or use the AskUserQuestion tool to get input from a human operator.