Skip to main content
Routes the workflow to different paths based on AI analysis or your own routing logic.

Decision modes

Choose between two decision types:
  • AI-Powered: AI interprets user intent from conversation
  • Function (Custom Code): Run your own routing logic - business rules, data checks, API calls, etc.

Configuration

Common parameters

  • id: Unique node identifier
  • conditions: List of possible paths with labels and descriptions

AI-powered mode

  • decision_type: Set to "ai" (default)
  • provider_model_name: AI model to use for decision making
  • llm_temperature: Model creativity, 0.0-1.0 (default: 0.0)
  • llm_max_tokens: Maximum tokens for response (default: 10000)

Function mode

  • decision_type: Set to "function"
  • function_id: ID of the deployed Kapso Function to execute

Workflow library example

AI decision:
Function decision:

How it works

AI-powered mode

  1. Analyzes conversation: Reviews recent WhatsApp message history
  2. Evaluates conditions: Uses AI to match user intent against condition descriptions
  3. Returns label: Chooses the best matching condition label for routing
  4. Routes workflow: Uses the label to follow the matching outgoing edge
  5. Fallback: Uses first condition if AI evaluation fails

Function mode

  1. Executes function: Calls your deployed Kapso Function with current workflow state
  2. Your logic runs: Function executes your custom logic - check data, call APIs, apply rules, etc.
  3. Returns decision: Function returns JSON with next_edge set to a condition label
  4. Routes workflow: Uses the returned label to follow the matching outgoing edge
  5. Updates variables: Optionally updates workflow variables if function returns vars
Important: Condition labels must exactly match your outgoing edge labels for proper routing in both modes.

Function decision contract

When using function mode, your function receives the standard execution payload plus an available_edges array containing all possible edge labels from your conditions.

Request payload

Response format

Your function must return JSON with next_edge set to one of the labels from available_edges:

Example function

Accessing WhatsApp data

When your flow is triggered by a WhatsApp message, use whatsapp_context to access conversation data:

Routing by button ID

Common pattern: route based on which button the user clicked.
Tip: Set your button id values to match your condition labels for direct routing.

Usage patterns

Question → Wait → Decide → Route Interactive → Wait → Decide