Skip to content

Commit 8cda1f8

Browse files
Steve McMillianclaude
andcommitted
fix: Agent 2 error handling - allow waterfall fallback on API errors
Problem: When Agent 2 gets API errors (529 Overloaded, 500 Internal Error), it throws exception and exits before reaching waterfall check. Impact: ALL courses with Agent 2 errors fail immediately, waterfall never triggers. - Bald Head Island Club: API 529 - Birchwood CC: API 529 - Beaver Creek: API 529 - Birdieworkz: API 529 - Brookwood: API 500 Solution: Catch Agent 2 exceptions gracefully - Set staff = [] on error - Create minimal course_data - Continue to waterfall check - Let Agents 2.1 and 2.2 attempt recovery Expected Recovery: 60-100% of failed courses (based on Docker tests) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent c70b6c4 commit 8cda1f8

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

production/golf-enrichment/orchestrator.py

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,49 @@ async def enrich_course(
246246
print("📄 [2/8] Agent 2: Extracting course data...")
247247
agent2_start = time.time()
248248

249-
course_data = await extract_contact_data(url_result["url"])
250-
251-
agent2_duration = time.time() - agent2_start
252-
253-
if not course_data or not course_data.get("data"):
254-
raise Exception("Agent 2 failed: Could not extract course data")
255-
256-
staff = course_data["data"].get("staff", [])
257-
print(f" ✅ Course: {course_data['data'].get('course_name')}")
258-
print(f" 📞 Phone: {course_data['data'].get('phone', 'Not found')}")
259-
print(f" 👥 Staff: {len(staff)} contacts found")
260-
print(f" 💰 Cost: ${course_data.get('cost', 0):.4f} | ⏱️ {agent2_duration:.1f}s\n")
249+
# NEW: Wrap Agent 2 in try/except to allow waterfall fallback on errors
250+
try:
251+
course_data = await extract_contact_data(url_result["url"])
252+
agent2_duration = time.time() - agent2_start
253+
254+
if not course_data or not course_data.get("data"):
255+
print(f" ⚠️ Agent 2: No data returned, triggering fallbacks...")
256+
# Create minimal course_data to allow waterfall
257+
course_data = {
258+
"data": {
259+
"course_name": course_name,
260+
"staff": [],
261+
"phone": None,
262+
"source": "pga_directory_error"
263+
},
264+
"cost": 0.0
265+
}
266+
staff = []
267+
else:
268+
staff = course_data["data"].get("staff", [])
269+
print(f" ✅ Course: {course_data['data'].get('course_name')}")
270+
print(f" 📞 Phone: {course_data['data'].get('phone', 'Not found')}")
271+
print(f" 👥 Staff: {len(staff)} contacts found")
272+
print(f" 💰 Cost: ${course_data.get('cost', 0):.4f} | ⏱️ {agent2_duration:.1f}s\n")
273+
274+
except Exception as agent2_error:
275+
# Agent 2 threw error (API 529/500, parse error, etc.)
276+
# Create minimal course_data to allow waterfall fallback
277+
print(f" ⚠️ Agent 2 error: {agent2_error}")
278+
print(f" 🔁 Continuing to fallback agents...\n")
279+
agent2_duration = time.time() - agent2_start
280+
281+
course_data = {
282+
"data": {
283+
"course_name": course_name,
284+
"staff": [],
285+
"phone": None,
286+
"source": "pga_directory_error"
287+
},
288+
"cost": 0.0,
289+
"error": str(agent2_error)
290+
}
291+
staff = []
261292

262293
result["agent_results"]["agent2"] = course_data
263294

0 commit comments

Comments
 (0)