> ## Documentation Index
> Fetch the complete documentation index at: https://kapso-1adbad2d.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Flow edges

> Connect nodes in WhatsApp workflows

## Basic usage

```python theme={null}
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

```python theme={null}
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):

```python theme={null}
# 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:

```python theme={null}
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

```python theme={null}
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

```python theme={null}
# 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

```python theme={null}
# 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

```python theme={null}
# Interactive button responses create edges automatically
interactive = SendInteractiveNode(
    id="menu_1234",
    interactive_type="button",
    body_text="Choose an option",
    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 and target node IDs reference existing nodes
* Start node exists, is unique, and has at least one outgoing edge
* Node identifiers are unique
* Nodes should be reachable from the start node (warnings are emitted if not)

```python theme={null}
flow.validate()  # Raises error if invalid
```
