πŸ”€ Branching Action

Overview

This action helps you determine a path based on user input. You can branch by number, string/category, or date. Category branching also supports fuzzy (partial) matches. This is useful in cases where the agent struggle to follow the right path based on a numeric or categorical comparison.

Endpoint

https://branching-function-1739.twil.io/branching

Request Parameters

ParameterTypeRequiredDescription
typestringYes"numeric", "category", or "date"
inputValuestring/numberYesThe value to check. For "numeric", a number; for "date", MM-DD-YYYY string
conditionsarrayYesList of branching rules (see examples)
fuzzyMatchbooleanNoSet to true for fuzzy category matching. Default: false

Examples

Numeric Branching Example

Request:

{
  "type": "numeric",
  "inputValue": "7",
  "conditions": [
    { "operator": "greater_than", "threshold": 10, "path": "high" },
    { "operator": "between", "threshold": [5, 10], "path": "medium" },
    { "operator": "less_than", "threshold": 5, "path": "low" }
  ]
}

Response:

{ "path": "medium" }

Category Branching Example (Exact Match)

Request:

{
  "type": "category",
  "inputValue": "VIP",
  "conditions": [
    { "categories": ["VIP", "premium"], "path": "priority_support" },
    { "categories": ["basic"], "path": "standard_support" }
  ]
}

Response:

{ "path": "priority_support" }

Category Branching Example (Fuzzy Match)

Request:

{
  "type": "category",
  "inputValue": "premium user",
  "fuzzyMatch": true,
  "conditions": [
    { "categories": ["VIP", "premium"], "path": "priority_support" },
    { "categories": ["basic"], "path": "standard_support" }
  ]
}

Response:

{ "path": "priority_support" }

Date Branching Example

Request:

{
  "type": "date",
  "inputValue": "07-01-2022",
  "conditions": [
    { "operator": "before", "threshold": "01-01-2023", "path": "old_policy" },
    { "operator": "after", "threshold": "12-31-2023", "path": "future_policy" },
    { "operator": "between", "threshold": ["01-01-2023", "12-31-2023"], "path": "current_policy" }
  ]
}

Response (for "07-01-2022"):

{ "path": "old_policy" }

Behavior Details

  • The function evaluates each condition in the order they are listed
  • For numeric branching, supported operators are:
    • greater_than
    • less_than
    • equal_to
    • not_equal_to
    • between (inclusive, pass as array [min, max])
  • For category branching, checks if the input matches any in the categories array
    • If fuzzyMatch is true, it checks if the input contains the category (case-insensitive)
  • Returns the path of the first matching condition
  • If nothing matches, returns:
    { "path": "default" }
    

Notes

  • Replace {{variables.value}} with your actual variable when implementing
  • Date format must be MM-DD-YYYY
  • Fuzzy matching is case-insensitive and checks for substring matches

Prompt Example


## ROLE
You are an AI voice agent that determines if a caller qualifies for medicare

## STRUCTURE
- Ask the caller "How old are you?"
- call function branching and jump to the appropriate path based on its return value

### Over 65 Flow
Respond with: "It looks like you qualify for medicare!"

### Under 65 flow
Ask: "Unfortunately, you don't qualify for medicare at this time."