Basic usage

from kapso.builder.flows.edges import Edge

# Simple connection
flow.add_edge("start_1234", "send_text_5678")

# With custom label
flow.add_edge("decide_9012", "support_3456", label="needs_support")

# Or create Edge directly
edge = Edge(source="node_a", target="node_b", label="next")

Edge class

Edge(
    source: str,           # Source node ID
    target: str,           # Target node ID  
    label: str = "next",   # Edge label
    flow_condition_id: str = None  # Set by DecideNode
)

Labels vs conditions

Flows use labels (not conditions like agents):
# Flow edges - labels identify the path
flow.add_edge("decide_1234", "urgent_5678", label="urgent") 
flow.add_edge("decide_1234", "normal_9012", label="general")

# Agent edges - conditions describe when to take path  
agent.add_edge("triage", "urgent", condition="customer sounds frustrated")

DecideNode routing

DecideNode creates edges automatically based on conditions:
from kapso.builder.flows.nodes import DecideNode
from kapso.builder.flows.nodes.decide import Condition

decide = DecideNode(
    id="decide_1234",
    provider_model_name="claude-sonnet-4-20250514",
    conditions=[
        Condition(label="urgent", description="Customer issue is urgent"),
        Condition(label="billing", description="Billing question")
    ]
)

# These edges are available for routing:
flow.add_edge("decide_1234", "urgent_handler", label="urgent")
flow.add_edge("decide_1234", "billing_handler", label="billing")

Flow patterns

Linear flow

flow.add_edge("start_1234", "greeting_5678")
flow.add_edge("greeting_5678", "collect_info_9012") 
flow.add_edge("collect_info_9012", "process_3456")

Branching from decide

# DecideNode evaluates and routes based on AI
flow.add_edge("triage_1234", "support_5678", label="technical_issue")
flow.add_edge("triage_1234", "billing_9012", label="billing_question")
flow.add_edge("triage_1234", "general_3456", label="general_inquiry")

Converging paths

# Multiple paths to same destination
flow.add_edge("option_a", "confirmation_1234")
flow.add_edge("option_b", "confirmation_1234")
flow.add_edge("option_c", "confirmation_1234")

Interactive routing

# Interactive button responses create edges automatically
interactive = SendInteractiveNode(
    id="menu_1234",
    action_config={
        "buttons": [
            {"id": "support", "title": "Get Support"},
            {"id": "billing", "title": "Billing"}
        ]
    }
)

# Route based on button selection  
flow.add_edge("menu_1234", "support_flow", label="support")
flow.add_edge("menu_1234", "billing_flow", label="billing")

Edge validation

Flow validation checks:
  • All source/target node IDs exist
  • StartNode has outgoing edges
  • All nodes reachable from StartNode
  • No circular dependencies
flow.validate()  # Raises error if invalid