sunheycho commited on
Commit
c6d454e
·
1 Parent(s): a640033

Add robust error handling to prevent session failure from individual agent errors

Browse files

- Wrap each agent process call in try-catch blocks
- Convert agent failures to warnings instead of session errors
- Ensure final results are always generated even if some agents fail
- Prevents confidence parsing or other agent errors from failing entire workflow

Files changed (1) hide show
  1. product_comparison.py +21 -9
product_comparison.py CHANGED
@@ -981,23 +981,35 @@ class ProductComparisonCoordinator:
981
 
982
  # Step 2: Extract features with Feature Extraction Agent
983
  session_manager.add_message(session_id, "Step 2: Extracting product specifications...")
984
- feature_results = await self.feature_extractor.process(session_id, image_results)
 
 
 
 
985
 
986
  # Step 3: Compare products with Comparison Agent if we have multiple products
987
  comparison_results = {}
988
  if len(product_info) >= 2:
989
  session_manager.add_message(session_id, "Step 3: Comparing products...")
990
- comparison_results = await self.comparison_agent.process(
991
- session_id,
992
- {**feature_results, "specifications": feature_results.get("specifications", {})}
993
- )
 
 
 
 
994
 
995
  # Step 4: Generate recommendation with Recommendation Agent
996
  session_manager.add_message(session_id, "Step 4: Generating purchase recommendation...")
997
- recommendation_results = await self.recommendation_agent.process(
998
- session_id,
999
- {**comparison_results, "specifications": feature_results.get("specifications", {})}
1000
- )
 
 
 
 
1001
  else:
1002
  session_manager.add_message(session_id, "Skipping comparison: Only one product detected")
1003
  comparison_results = {"comparison": {"error": "Need at least two products to compare"}}
 
981
 
982
  # Step 2: Extract features with Feature Extraction Agent
983
  session_manager.add_message(session_id, "Step 2: Extracting product specifications...")
984
+ try:
985
+ feature_results = await self.feature_extractor.process(session_id, image_results)
986
+ except Exception as e:
987
+ session_manager.add_message(session_id, f"Warning: Feature extraction failed: {str(e)}")
988
+ feature_results = {"specifications": {"error": f"Feature extraction failed: {str(e)}"}}
989
 
990
  # Step 3: Compare products with Comparison Agent if we have multiple products
991
  comparison_results = {}
992
  if len(product_info) >= 2:
993
  session_manager.add_message(session_id, "Step 3: Comparing products...")
994
+ try:
995
+ comparison_results = await self.comparison_agent.process(
996
+ session_id,
997
+ {**feature_results, "specifications": feature_results.get("specifications", {})}
998
+ )
999
+ except Exception as e:
1000
+ session_manager.add_message(session_id, f"Warning: Comparison failed: {str(e)}")
1001
+ comparison_results = {"comparison": {"error": f"Comparison failed: {str(e)}"}}
1002
 
1003
  # Step 4: Generate recommendation with Recommendation Agent
1004
  session_manager.add_message(session_id, "Step 4: Generating purchase recommendation...")
1005
+ try:
1006
+ recommendation_results = await self.recommendation_agent.process(
1007
+ session_id,
1008
+ {**comparison_results, "specifications": feature_results.get("specifications", {})}
1009
+ )
1010
+ except Exception as e:
1011
+ session_manager.add_message(session_id, f"Warning: Recommendation failed: {str(e)}")
1012
+ recommendation_results = {"recommendation": {"error": f"Recommendation failed: {str(e)}"}}
1013
  else:
1014
  session_manager.add_message(session_id, "Skipping comparison: Only one product detected")
1015
  comparison_results = {"comparison": {"error": "Need at least two products to compare"}}