if

Runs one block of commands or another, based on a condition.

Fields

FieldTypeDefaultDescription
conditionrequiredPython expressionBoolean expression, evaluated once: true runs 'then', false runs 'else'.
thencommand blockCommands to execute when the condition evaluates to true (the 'then' branch).
elsecommand blockCommands to execute when the condition evaluates to false (the 'else' branch).

Example

"if": {
  "condition": "{ location['country_code'] != 'US' }",
  "then": {
    "fail": "{ f'This agent supports only locations in the USA. You are in {location['country_name']}.' }"
  },
  "else": {
    "progress": "Location looks good"
  }
}

Rules

  • The condition is evaluated once, as a boolean.
  • then and else are ordinary command blocks. Any command may appear in them, including another if.
  • break and continue inside a branch act on the enclosing loop. return, end and fail leave the function or the agent as usual.