Spaces:
Runtime error
Runtime error
Update workflows/sales_analysis.py
Browse files- workflows/sales_analysis.py +38 -9
workflows/sales_analysis.py
CHANGED
|
@@ -118,16 +118,45 @@ class SalesAnalysisWorkflow:
|
|
| 118 |
# Add error handling
|
| 119 |
workflow.add_node("handle_error", self.handle_error_node)
|
| 120 |
|
| 121 |
-
# Add conditional edges for error handling
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
workflow.add_edge("handle_error", END)
|
| 132 |
|
| 133 |
# Set the entry point
|
|
|
|
| 118 |
# Add error handling
|
| 119 |
workflow.add_node("handle_error", self.handle_error_node)
|
| 120 |
|
| 121 |
+
# Add conditional edges for error handling using LangGraph's newer API
|
| 122 |
+
def route_planning(state):
|
| 123 |
+
if state["status"] == "error":
|
| 124 |
+
return "handle_error"
|
| 125 |
+
return "data_collection"
|
| 126 |
|
| 127 |
+
def route_data_collection(state):
|
| 128 |
+
if state["status"] == "error":
|
| 129 |
+
return "handle_error"
|
| 130 |
+
return "analysis"
|
| 131 |
+
|
| 132 |
+
def route_analysis(state):
|
| 133 |
+
if state["status"] == "error":
|
| 134 |
+
return "handle_error"
|
| 135 |
+
return "validation"
|
| 136 |
+
|
| 137 |
+
def route_validation(state):
|
| 138 |
+
if state["status"] == "error":
|
| 139 |
+
return "handle_error"
|
| 140 |
+
return "insights"
|
| 141 |
+
|
| 142 |
+
def route_insights(state):
|
| 143 |
+
if state["status"] == "error":
|
| 144 |
+
return "handle_error"
|
| 145 |
+
return END
|
| 146 |
+
|
| 147 |
+
# Replace linear edges with conditional ones
|
| 148 |
+
workflow.remove_edge("planning", "data_collection")
|
| 149 |
+
workflow.remove_edge("data_collection", "analysis")
|
| 150 |
+
workflow.remove_edge("analysis", "validation")
|
| 151 |
+
workflow.remove_edge("validation", "insights")
|
| 152 |
+
workflow.remove_edge("insights", END)
|
| 153 |
+
|
| 154 |
+
# Add the conditional routing
|
| 155 |
+
workflow.add_conditional_edges("planning", route_planning)
|
| 156 |
+
workflow.add_conditional_edges("data_collection", route_data_collection)
|
| 157 |
+
workflow.add_conditional_edges("analysis", route_analysis)
|
| 158 |
+
workflow.add_conditional_edges("validation", route_validation)
|
| 159 |
+
workflow.add_conditional_edges("insights", route_insights)
|
| 160 |
workflow.add_edge("handle_error", END)
|
| 161 |
|
| 162 |
# Set the entry point
|