Basic usage

# 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

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

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

# Multiple paths to same node
agent.add_edge("option_a", "confirmation")
agent.add_edge("option_b", "confirmation") 
agent.add_edge("option_c", "confirmation")

Loops

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
# ✅ 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
# ✅ 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
handoff = HandoffNode(
    name="human",
    global_=True, 
    global_condition="user requests human"
)
# No edges needed - available from any state

Condition tips

Write natural language conditions:
# ✅ 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.