Tutorial

The Workflow DSL Explained: task, assert, if, loop, and parallel

Sarah Chen||9 min
Ctrl+F

Robust automation needs more than a single task. You need to verify results, handle branches, repeat actions, and coordinate concurrent steps. The Coasty workflow DSL is a versioned JSON DSL that lets you define these multi-step workflows with task, assert, if, loop, parallel, human_approval, retry, succeed, and fail. You POST your workflow to /v1/workflows then execute instances with POST /v1/workflows/{id}/runs. Each task step is billed at $0.05. This approach gives you structured, versionable automation that matches how humans work on computers.

Workflow DSL basics

A workflow is a JSON object with a version field and a steps array. Each step has a step_id, type, and required fields depending on the type. The DSL supports these step types. Task steps drive an agent to complete a task, costing $0.05 per execution. Assert steps validate a condition, such as checking a UI element or API response. If steps execute branches based on conditions. Loop steps repeat a block while a condition holds. Parallel steps run multiple steps concurrently. Human_approval, retry, succeed, and fail provide control flow and error handling.

bash
curl -X POST https://coasty.ai/v1/workflows \
  -H "X-API-Key: $COASTY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "version": 1,
    "steps": [
      {
        "step_id": "setup",
        "type": "task",
        "task": "Open Chrome and navigate to https://coasty.ai"
      },
      {
        "step_id": "check_homepage",
        "type": "assert",
        "condition": {
          "type": "text_present",
          "selector": { "tag": "h1", "text": "AI Computer Use" }
        }
      },
      {
        "step_id": "branch",
        "type": "if",
        "condition": {
          "type": "text_present",
          "selector": { "tag": "button", "text": "Get Started" }
        },
        "then": [
          {
            "step_id": "click_start",
            "type": "task",
            "task": "Click the Get Started button"
          }
        ],
        "else": [
          {
            "step_id": "search",
            "type": "task",
            "task": "Search for Coasty documentation"
          }
        ]
      },
      {
        "step_id": "verify_confirm",
        "type": "assert",
        "condition": {
          "type": "text_present",
          "selector": { "tag": "h2", "text": "Computer Use API" }
        }
      },
      {
        "step_id": "success",
        "type": "succeed",
        "message": "Workflow completed successfully"
      }
    ]
  }'

Task steps

Task steps are the core actions that drive an agent. You provide a task string like 'Open Chrome and navigate to https://example.com'. The agent uses its computer use model to interpret the task, capture the screen, and perform actions. Task steps are billed at $0.05 each. You can append instructions to the base prompt via the instructions field in the workflow or task steps. Use step_id to reference steps later, such as in if and loop conditions.

Task steps drive the agent at $0.05 per execution.

Assert steps

Assert steps validate conditions after a task. The condition object supports types like text_present, element_visible, and custom checks. You define selectors with tag, text, or other attributes. If a condition fails, the workflow stops and reports failure. Assert steps do not incur additional billing beyond the task steps they follow. You can combine assert with if to handle different outcomes.

If steps

If steps let you branch execution based on conditions. The condition uses the same assert-style objects. If the condition is true, the then array executes; otherwise, the else array runs. You can nest if steps for complex logic. Each branch contains a list of steps, including task, assert, if, loop, parallel, and other step types. This gives you control flow that mirrors human decision-making.

Loop steps

Loop steps repeat a block of steps while a condition holds. You define a condition that evaluates to true or false, similar to if. The loop body can include task, assert, and other steps. You can set a maximum number of iterations via the max_iterations guard to prevent infinite loops. Loop steps are useful for retrying a task until success or repeating a process until a condition is met.

Parallel steps

Parallel steps run multiple steps concurrently. Each parallel branch is an array of steps. The DSL does not guarantee order, but you can use step_id and assert conditions to coordinate results. Parallel steps are useful for launching multiple agents or performing independent actions in parallel. They do not add billing beyond the task steps they contain.

Where this beats brittle automation

Traditional automation often relies on brittle selectors and fixed API calls. When UI changes, those selectors break. Coasty’s computer use agent uses vision to see the screen and interpret tasks naturally, adapting to changes. The workflow DSL adds structure and control flow, letting you define multi-step flows with verification, branching, and concurrency. You get versioned, testable workflows that drive real desktops and browsers instead of fragile scripts.

Next steps

Now you know how to define workflows with task, assert, if, loop, and parallel steps. Try building a workflow that opens an application, performs a multi-step task, asserts results, and handles different outcomes. Get a key at https://coasty.ai/developers to start building your own computer use agents.

Want to see this in action?

View Case Studies
Try Coasty Free