Tutorial

Workflow DSL Explained: Task, Assert, If, Loop, Parallel

Michael Rodriguez||7 min
+Z

You want agents that do more than click buttons, they need to make decisions, handle errors, and run independent jobs in parallel. The Coasty Workflow DSL gives you a versioned JSON structure to orchestrate runs, with built‑in branching, retries, and budget limits.

How it works

A workflow is POSTed to /v1/workflows. Each step is an object with a type: task, assert, if, loop, parallel, human_approval, retry, succeed, fail. Variables use double‑brace syntax like {{inputs.x}} or stepId.field. You can set hard gates: budget_cents, max_iterations, deadline_seconds. When you POST /v1/workflows/{id}/runs, Coasty instantiates one or more agent runs that obey that DSL, billing $0.05 per task step.

curl
curl -X POST https://coasty.ai/v1/workflows \ 
  -H "X-API-Key: $COASTY_API_KEY" \ 
  -H "Content-Type: application/json" \ 
  -d '{
    "name": "my_workflow",
    "version": "1.0",
    "steps": [
      {
        "id": "login",
        "type": "task",
        "task": "Log in to https://myapp.com using email {{inputs.email}} and password {{inputs.password}}",
        "system_prompt": "You are a helpful assistant that logs in to the web app."
      },
      {
        "id": "check_balance",
        "type": "assert",
        "assert": {
          "field": "balance",
          "operator": ">",
          "value": 0
        },
        "next_on_fail": "retry_check_balance"
      },
      {
        "id": "retry_check_balance",
        "type": "retry",
        "max_attempts": 3,
        "retry_on": ["fail", "timed_out"],
        "next_on_success": "deposit",
        "next_on_fail": "fail"
      },
      {
        "id": "deposit",
        "type": "task",
        "task": "Deposit $50 using the deposit button."
      },
      {
        "id": "withdraw",
        "type": "if",
        "condition": "{{deposit.success}}",
        "then": [
          {
            "type": "task",
            "task": "Withdraw $20 using the withdraw button."
          }
        ],
        "else": [
          {
            "type": "fail",
            "message": "Deposit failed, cannot withdraw."
          }
        ]
      },
      {
        "id": "parallel_payments",
        "type": "parallel",
        "steps": [
          {
            "type": "task",
            "task": "Pay vendor A: $100.",
            "next_on_success": "parallel_success"
          },
          {
            "type": "task",
            "task": "Pay vendor B: $150.",
            "next_on_success": "parallel_success"
          }
        ],
        "next_on_success": "final_task"
      },
      {
        "id": "final_task",
        "type": "task",
        "task": "Confirm that payments succeeded."
      },
      {
        "id": "succeed",
        "type": "succeed"
      }
    ],
    "hard_guards": {
      "budget_cents": 500,
      "deadline_seconds": 600
    }
  }'

Step types you need to know

  • task: runs an agent on a real desktop, browser, or terminal. Billed $0.05 per step.
  • assert: checks a field from the last task result (e.g., balance > 0). next_on_fail branches to retry or fail.
  • if: conditionally executes then steps or else steps based on stepId.field values like {{deposit.success}}.
  • loop: repeats a block of steps up to max_iterations or until a success condition, useful for paginated tasks.
  • parallel: runs all steps concurrently; next_on_success runs when all parallel steps succeed.
  • retry: retries a step up to max_attempts on specific failure codes or next_on_fail targets.
  • human_approval: pauses the workflow until your webhook receives approval, then continues or fails.
  • succeed / fail: explicit terminal steps that end the workflow with a success or error state.
  • Variables: refer to inputs via {{inputs.x}} or step results via stepId.field.

POST /v1/workflows/{id}/runs to instantiate runs that follow your DSL, billing $0.05 per task step.

Where this beats brittle automation

API‑only tools rely on fixed selectors and fragile endpoints. The Coasty workflow DSL lets you describe intent and let the computer use agent locate buttons, fill forms, and adapt to UI changes. You can branch on assertions, retry on transient errors, and run parallel payments without managing separate scripts. Because the DSL is versioned JSON, you can roll back or iterate, and hard guards keep costs predictable.

Take your agents from one‑shot actions to full workflows with the Coasty Workflow DSL. Build stateful, branching, and parallel automation that controls real desktops. Get your API key at https://coasty.ai/developers and start orchestrating runs today.

Want to see this in action?

View Case Studies
Try Coasty Free