Connect flow nodes to define execution paths
# Add edge with default "next" label flow.add_edge("send_greeting", "wait_response") # Add edge with custom label flow.add_edge("decide_routing", "support_agent", "support")
flow.add_edge("send_text", "next_step", "next")
# Default progression flow.add_edge("wait_input", "process_response", "next") # After user response flow.add_edge("wait_input", "process_response", "response")
# Edge labels must match condition labels exactly decide = DecideNode( id="route_customer", conditions=[ Condition(label="billing", description="Billing questions"), Condition(label="support", description="Technical support") ] ) flow.add_edge("route_customer", "billing_agent", "billing") flow.add_edge("route_customer", "support_agent", "support")
flow = (Flow(name="Simple Flow") .add_node(StartNode(id="start")) .add_node(SendTextNode(id="greeting", text="Hello!")) .add_node(SendTextNode(id="goodbye", text="Goodbye!")) .add_edge("start", "greeting") .add_edge("greeting", "goodbye") )
# Decision routing decision = DecideNode( id="check_type", conditions=[ Condition(label="question", description="User has a question"), Condition(label="complaint", description="User has a complaint") ] ) # Responses faq = SendTextNode(id="faq_response", text="Here are our FAQs...") escalate = HandoffNode(id="escalate") # Connect flow.add_edge("check_type", "faq_response", "question") flow.add_edge("check_type", "escalate", "complaint")
# Multi-step with conditions flow = (Flow(name="Customer Service") .add_node(StartNode(id="start")) .add_node(SendTextNode(id="welcome", text="How can I help?")) .add_node(WaitForResponseNode(id="get_request")) .add_node(DecideNode( id="classify_request", conditions=[ Condition(label="simple", description="Simple question"), Condition(label="complex", description="Complex issue") ] )) .add_node(SendTextNode(id="quick_help", text="Here's the answer...")) .add_node(AgentNode(id="detailed_help", system_prompt="Help with complex issues")) # Linear progression .add_edge("start", "welcome") .add_edge("welcome", "get_request") .add_edge("get_request", "classify_request", "response") # Conditional routing .add_edge("classify_request", "quick_help", "simple") .add_edge("classify_request", "detailed_help", "complex") )
Was this page helpful?