Uses AI to analyze conversation history and route the flow based on user intent.

Configuration

  • id: Unique node identifier
  • provider_model_name: AI model to use for decision making
  • conditions: List of possible paths with labels and descriptions
  • decision_type: Always “ai” (default)
  • llm_temperature: Model creativity, 0.0-1.0 (default: 0.0)
  • llm_max_tokens: Maximum tokens for response (default: 10000)

Examples

Support routing
from kapso.builder.flows.nodes import DecideNode
from kapso.builder.flows.nodes.decide import Condition

node = DecideNode(
    id="route_support",
    provider_model_name="claude-3-5-sonnet-20241022",
    conditions=[
        Condition("billing", "User needs billing help"),
        Condition("technical", "User has technical issues"),
        Condition("general", "General inquiry or other topics")
    ]
)
Yes/no decision
conditions = [
    Condition("yes", "User confirmed or agreed"),
    Condition("no", "User declined or disagreed")
]

node = DecideNode(
    id="confirm_order",
    provider_model_name="gpt-4o",
    conditions=conditions,
    llm_temperature=0.1
)
Customer satisfaction
node = DecideNode(
    id="satisfaction_route",
    provider_model_name="claude-3-5-sonnet-20241022",
    conditions=[
        Condition("happy", "Customer is satisfied with service"),
        Condition("neutral", "Customer is neutral about service"),
        Condition("unhappy", "Customer is dissatisfied with service")
    ]
)

How it works

  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 flow: Uses the label to follow the matching outgoing edge
  5. Fallback: Uses first condition if AI evaluation fails
Important: Condition labels must exactly match your outgoing edge labels for proper routing.
# Create decide node with conditions
decide = DecideNode(
    id="route_support",
    provider_model_name="claude-3-5-sonnet-20241022",
    conditions=[
        Condition("billing", "User needs billing help"),
        Condition("technical", "User has technical issues")
    ]
)

# Create target nodes
billing_help = SendTextNode(id="billing", whatsapp_config_id="config", message="Billing support")
tech_help = SendTextNode(id="tech", whatsapp_config_id="config", message="Technical support")

# Connect with matching edge labels
flow.add_edge("route_support", "billing", "billing")      # Label matches condition
flow.add_edge("route_support", "tech", "technical")       # Label matches condition

Usage patterns

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