|
|
|
@ -373,139 +373,6 @@ async function executeAutonomousAlerts(env, intelligenceReport, marketIntelligen
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Healthcare Cron Agent Example
|
|
|
|
|
|
|
|
|
|
Healthcare monitoring cron agent with Swarms AI:
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
export default {
|
|
|
|
|
async fetch(request, env, ctx) {
|
|
|
|
|
if (request.url.includes('/health')) {
|
|
|
|
|
return new Response(JSON.stringify({
|
|
|
|
|
status: 'Healthcare cron agent active',
|
|
|
|
|
next_check: 'Every 30 minutes'
|
|
|
|
|
}), {
|
|
|
|
|
headers: { 'Content-Type': 'application/json' }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return new Response('Healthcare Cron Agent');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Healthcare monitoring - every 30 minutes
|
|
|
|
|
async scheduled(event, env, ctx) {
|
|
|
|
|
console.log('🏥 Healthcare cron agent triggered');
|
|
|
|
|
ctx.waitUntil(executeHealthAnalysis(event, env));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async function executeHealthAnalysis(event, env) {
|
|
|
|
|
try {
|
|
|
|
|
// Collect patient data (from EMR, IoT devices, etc.)
|
|
|
|
|
const patientData = await getPatientData();
|
|
|
|
|
|
|
|
|
|
// Configure Swarms healthcare agents
|
|
|
|
|
const healthConfig = {
|
|
|
|
|
name: "Healthcare Monitoring Swarm",
|
|
|
|
|
agents: [
|
|
|
|
|
{
|
|
|
|
|
agent_name: "Vital Signs Monitor",
|
|
|
|
|
system_prompt: "Monitor patient vital signs and detect anomalies. Alert on critical values.",
|
|
|
|
|
model_name: "gpt-4o-mini",
|
|
|
|
|
max_tokens: 1000
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
swarm_type: "ConcurrentWorkflow",
|
|
|
|
|
task: `Analyze patient data: ${JSON.stringify(patientData, null, 2)}`,
|
|
|
|
|
max_loops: 1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Call Swarms API
|
|
|
|
|
const response = await fetch('https://api.swarms.world/v1/swarm/completions', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'x-api-key': env.SWARMS_API_KEY,
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(healthConfig)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await response.json();
|
|
|
|
|
|
|
|
|
|
// Send alerts if critical conditions detected
|
|
|
|
|
if (result.output.includes('CRITICAL')) {
|
|
|
|
|
await sendHealthAlert(env, result.output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { success: true, analysis: result.output };
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Healthcare analysis failed:', error);
|
|
|
|
|
return { success: false, error: error.message };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getPatientData() {
|
|
|
|
|
// Mock patient data - replace with real EMR/IoT integration
|
|
|
|
|
return {
|
|
|
|
|
patient_001: {
|
|
|
|
|
heart_rate: 115, // Elevated
|
|
|
|
|
oxygen_saturation: 89 // Low - critical
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function sendHealthAlert(env, analysis) {
|
|
|
|
|
// Send emergency alerts via email/SMS
|
|
|
|
|
console.log('🚨 Critical health alert sent');
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Deployment & Configuration
|
|
|
|
|
|
|
|
|
|
### Environment Variables
|
|
|
|
|
|
|
|
|
|
Configure your Cloudflare Workers deployment with Swarms API:
|
|
|
|
|
|
|
|
|
|
```jsonc
|
|
|
|
|
{
|
|
|
|
|
"vars": {
|
|
|
|
|
"SWARMS_API_KEY": "your-swarms-api-key",
|
|
|
|
|
"AUTONOMOUS_ALERTS_EMAIL": "intelligence@yourcompany.com",
|
|
|
|
|
"HEALTHCARE_EMERGENCY_EMAIL": "emergency@hospital.com",
|
|
|
|
|
"MAILGUN_API_KEY": "your-mailgun-key",
|
|
|
|
|
"MAILGUN_DOMAIN": "intelligence.yourcompany.com"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Cloudflare Workers Cron Scheduling Patterns
|
|
|
|
|
|
|
|
|
|
```jsonc
|
|
|
|
|
{
|
|
|
|
|
"triggers": {
|
|
|
|
|
"crons": [
|
|
|
|
|
"0 */3 * * *", // Financial Swarms agents every 3 hours
|
|
|
|
|
"*/30 * * * *", // Healthcare Swarms monitoring every 30 minutes
|
|
|
|
|
"0 9,15,21 * * *", // Daily Swarms intelligence briefings
|
|
|
|
|
"*/5 * * * *" // Critical Swarms systems every 5 minutes
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Cloudflare Workers Deployment Commands
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# Deploy Swarms AI agents to Cloudflare Workers
|
|
|
|
|
wrangler deploy
|
|
|
|
|
|
|
|
|
|
# Monitor Cloudflare Workers execution logs
|
|
|
|
|
wrangler tail
|
|
|
|
|
|
|
|
|
|
# Test Cloudflare Workers cron triggers manually
|
|
|
|
|
wrangler triggers cron "0 */3 * * *"
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Production Best Practices
|
|
|
|
|
|
|
|
|
|
### 1. **Cloudflare Workers + Swarms API Integration**
|
|
|
|
|