> ## 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.

# Agent edges

> Connect nodes and control conversation flow

## Basic usage

```python theme={null}
# Simple connection
agent.add_edge(START_NODE, "greeting")
agent.add_edge("greeting", END_NODE)

# With condition
agent.add_edge("triage", "orders", condition="user asks about orders")
agent.add_edge("triage", "support", condition="user has technical issues")
```

## Syntax

```python theme={null}
agent.add_edge(source, target, condition=None)
```

* **source**: Node name or START\_NODE
* **target**: Node name or END\_NODE
* **condition**: Natural language condition (optional)

## Flow patterns

### Branching

```python theme={null}
agent.add_edge("menu", "orders", condition="user selects orders")
agent.add_edge("menu", "support", condition="user selects support")
agent.add_edge("menu", "info", condition="user wants information")

# Default fallback (no condition)
agent.add_edge("menu", "help")
```

### Converging

```python theme={null}
# Multiple paths to same node
agent.add_edge("option_a", "confirmation")
agent.add_edge("option_b", "confirmation") 
agent.add_edge("option_c", "confirmation")
```

### Loops

```python theme={null}
agent.add_edge("ask_input", "validate")
agent.add_edge("validate", "ask_input", condition="invalid input")
agent.add_edge("validate", "success", condition="valid input")
```

## Rules

### START\_NODE

* Exactly one outgoing edge
* No conditions allowed
* No incoming edges

```python theme={null}
# ✅ Correct
agent.add_edge(START_NODE, "first_node")

# ❌ Wrong - multiple edges
agent.add_edge(START_NODE, "node1")
agent.add_edge(START_NODE, "node2")
```

### END\_NODE

* Multiple incoming edges allowed
* No outgoing edges

```python theme={null}
# ✅ Multiple paths to end
agent.add_edge("success", END_NODE)
agent.add_edge("error", END_NODE)
agent.add_edge("cancelled", END_NODE)
```

### Global nodes

* Don't need explicit edges
* Triggered by conditions from anywhere

```python theme={null}
handoff = HandoffNode(
    name="human",
    global_=True, 
    global_condition="user requests human"
)
# No edges needed - available from any state
```

## Condition tips

Write natural language conditions:

```python theme={null}
# ✅ Good
condition="user asks about their order or shipment status"

# ✅ Good  
condition="user is frustrated or upset"

# ❌ Avoid code-like syntax
condition="input == 'order' || sentiment < 0"
```

Always provide fallback paths without conditions.
