Skip to main content
Last Updated: May 2026 (Post-Enhancement) The 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

  1. Trigger: Cloudflare® Cron triggers the worker.
  2. State Sync: Fetches active OPEN positions via the d1-worker.
  3. Market Pulse: Pings public exchange APIs for the latest markPrice.
  4. Risk Evaluation: Cross-references current price with KV-stored watermarks and global drawdown limits.
  5. AI Processing: Uses configured AI provider with automatic fallback chain.
  6. Execution: Dispatches actions to trade-worker (closing positions) and telegram-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:
Streaming Response (SSE):

POST /agent/vision (NEW!)

Analyze images with AI vision models. Supports both URL and base64 input.
Or with base64:

POST /agent/reasoning (NEW!)

Extended thinking queries with reasoning models like OpenAI o1.
Response:

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 in CONFIG_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

The agent-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 Coverage: >80% across all modules

Test Structure


Cloudflare® and the Cloudflare logo are trademarks and/or registered trademarks of Cloudflare, Inc. in the United States and other jurisdictions.
Last modified on June 17, 2026