Overview
Production AI agents cannot tolerate search downtime. This workflow runs a health check every 5 minutes against the primary search provider. If the primary fails or returns degraded results, it automatically routes agent search requests to the fallback provider. Logs all fallback events for post-incident review.
Trigger
Health check every 5 minutes. Fallback routing triggered on primary failure.
Schedule
Every 5 minutes (health check)
Workflow Steps
Run Primary Provider Health Check
Send a canary query to the primary search provider. Check response time, status code, and result quality (minimum 3 organic results).
Update Provider Status Registry
Write the health check result to a status registry. Track consecutive failures to avoid flapping between providers.
Route Agent Requests Based on Status
Agent search requests check the status registry. If primary is healthy, route there. If degraded or down, route to fallback.
Log Fallback Events
Record every fallback event with timestamp, reason, and query. Generate a daily digest of fallback incidents for the ops team.
Python Implementation
import requests, os, json, time
from datetime import datetime
API_KEY = os.environ["SCAVIO_API_KEY"]
STATUS_FILE = "provider_status.json"
def health_check() -> dict:
try:
start = time.time()
resp = requests.post(
"https://api.scavio.dev/api/v1/search",
headers={"x-api-key": API_KEY, "Content-Type": "application/json"},
json={"query": "test query", "country_code": "us"},
timeout=10,
)
latency = time.time() - start
data = resp.json()
healthy = resp.status_code == 200 and len(data.get("organic_results", [])) >= 3
return {"healthy": healthy, "latency": round(latency, 2), "timestamp": datetime.now().isoformat()}
except Exception as e:
return {"healthy": False, "error": str(e), "timestamp": datetime.now().isoformat()}
status = health_check()
print(f"Provider healthy: {status['healthy']}, latency: {status.get('latency', 'N/A')}s")JavaScript Implementation
const H = {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'};
async function healthCheck() {
try {
const start = Date.now();
const r = await fetch('https://api.scavio.dev/api/v1/search', {method:'POST', headers:H, body:JSON.stringify({query:'test query', country_code:'us'})});
const d = await r.json();
return {healthy: r.ok && (d.organic_results||[]).length >= 3, latency: Date.now()-start, timestamp: new Date().toISOString()};
} catch (e) { return {healthy:false, error:e.message, timestamp:new Date().toISOString()}; }
}
const s = await healthCheck();
console.log('Healthy: '+s.healthy+', Latency: '+s.latency+'ms');Platforms Used
Web search with knowledge graph, PAA, and AI overviews
YouTube
Video search with transcripts and metadata
Community, posts & threaded comments from any subreddit