What this pattern is good for
- ⚡ Scheduled execution — agents trigger automatically on cron schedules.
- 📊 Real-time data fetch — pull from Yahoo Finance, news feeds, custom APIs.
- 🤖 Multi-agent analysis — call the Swarms API with several specialized agents.
- 📧 Automated actions — email reports, webhook posts, push notifications.
- 🌍 Global edge — Cloudflare’s network is closer to your users and data sources than a single VM.
Reference implementation
A complete, production-ready stock analysis agent is published at: 🔗 github.com/The-Swarm-Corporation/Swarms-CloudFlare-Deployment The repository ships two implementations:| Folder | Runtime | Status |
|---|---|---|
stock-agent/ — JavaScript / TypeScript | V8 | Production-ready |
python-stock-agent/ — Python (Pyodide) | Cloudflare Python Workers | Beta |
Architecture
Step 1: Clone and install
Option A — JavaScript
Option B — Python
Step 2: Configure environment
Create a.dev.vars file:
wrangler secret put.
Step 3: Set the cron schedule
Cron triggers are configured inwrangler.jsonc:
| Cron | Schedule |
|---|---|
0 9 * * 1-5 | 9 AM weekdays |
0 */6 * * * | Every 6 hours |
0 0 * * * | Daily at midnight |
Step 4: Run locally
Step 5: Deploy
Customization
Stock symbols
In JavaScript:Custom Swarms agents
Cost notes
- Cloudflare Workers — free tier covers 100,000 requests/day.
- Swarms API — monitor usage in the dashboard; switch to
gpt-4o-minifor cost-sensitive runs. - External APIs — most of the providers listed above (Yahoo Finance, FMP free tier, Mailgun free tier) are free at low volume.
Security checklist
- Store API keys as Wrangler secrets, never in source.
- Validate incoming requests + apply per-IP rate limits.
- Audit AI decisions and persist compliance logs.
- Use HTTPS for every outbound call.
Troubleshooting
| Symptom | Likely cause |
|---|---|
| API key errors | .dev.vars missing or wrangler secret put not run for production |
| Cron not firing | Check wrangler.jsonc syntax and Workers cron limits |
| Email not sending | Mailgun domain not verified, or API key wrong region |
| Data fetch failures | External API quota hit or rate-limited |
Useful links
See also
- Deployment Solutions Overview — comparison table for picking the right deploy target.
- Google Cloud Run — managed-container alternative for synchronous APIs.
- FastAPI Agent API — local FastAPI deployment.