agent-worker serves as the proactive intelligence layer of the Hoox trading ecosystem. Rather than waiting for webhooks, it runs continuously on a cron schedule to monitor portfolio health, enforce risk limits, and optimize position exits.
Core Capabilities
Architecture & Flow
- Trigger: Cloudflare® Cron triggers the worker.
- State Sync: Fetches active
OPENpositions via thed1-worker. - Market Pulse: Pings public exchange APIs for the latest
markPrice. - Risk Evaluation: Cross-references current price with KV-stored watermarks and global drawdown limits.
- AI Processing: Uses configured AI provider with automatic fallback chain.
- Execution: Dispatches actions to
trade-worker(closing positions) andtelegram-worker(alerts) via internal Service Bindings.
Endpoints & Interactions
Note: For the canonical endpoint directory with full request/response examples across all workers, see /docs/devops/api/endpoints.
Management Endpoints
GET /agent/config
Returns current agent configuration including provider settings.
POST /agent/config
Update agent configuration at runtime.
GET /agent/models
Returns all available models from Cloudflare Workers AI and external providers.
POST /agent/test-model
Test a specific AI model.
GET /agent/health
Returns health status of all configured AI providers.
AI Interaction Endpoints
POST /agent/chat
Send a chat request with automatic provider fallback and SSE streaming support.
Request:
POST /agent/vision (NEW!)
Analyze images with AI vision models. Supports both URL and base64 input.
POST /agent/reasoning (NEW!)
Extended thinking queries with reasoning models like OpenAI o1.
GET /agent/usage (NEW!)
Get AI API usage statistics across all providers.
GET /agent/prompts (NEW!)
List available prompt templates.
POST /agent/embedding
Generate text embeddings using Workers AI embedding models.
Legacy Endpoints
POST /agent/risk-override
Manually enforce or release risk locks.
GET /agent/status
Retrieve the real-time health of the agent and active trailing stops.
Configuration
KV Keys
All configuration is stored inCONFIG_KV for real-time adjustments.
Default Agent Config
Supported Models
Workers AI Models
External Providers
AI Gateway Features
The AI Gateway provides:- Fallback Chain: Automatically tries providers in order on failure
- Health Checks: Providers self-report health status every 5 minutes
- Retry Logic: Exponential backoff with configurable max retries
- Timeout Protection: Configurable per-request timeout (default 30s)
- Usage Tracking: Automatic token and request counting per provider
Internal Service Bindings
Theagent-worker requires the following bindings to operate:
D1_SERVICE: To fetch open positions and system logs.TRADE_SERVICE: To execute trailing stops and profit-taking.TELEGRAM_SERVICE: To broadcast AI summaries and emergency alerts.CONFIG_KV: For dynamic configuration and state.AI: Workers AI binding for inference.
Testing
The agent-worker includes comprehensive tests (171 tests across 33 files):Test Structure
Cloudflare® and the Cloudflare logo are trademarks and/or registered trademarks of Cloudflare, Inc. in the United States and other jurisdictions.