Edge Runtime
AgentDeploy edge agents run on Cloudflare Workers with Durable Objects — a serverless execution environment deployed to 300+ cities worldwide.
How SDK-based agents are deployed
When a buyer deploys an SDK-based agent, the platform:
- Receives the bundled ESM module from
ad deploy(already bundled by esbuild) - Analyzes the script with
analyzeRenderedScript()to detect:- Durable Object classes (extends
Agent,AIChatAgent) - Agents SDK imports (
agents,@cloudflare/ai-chat,@agentdeploy/edge-sdk) - Workers AI binding usage (
env.AI) - Agent routing patterns (
routeAgentRequest)
- Durable Object classes (extends
- Generates deployment metadata including:
- DO namespace bindings for each detected class
new_sqlite_classesmigration tag for SQLite-backed DOsnodejs_compatcompatibility flag- Workers AI binding (if
env.AIdetected)
- Wraps with AD_ constants* — Injects
AD_DEPLOYMENT_ID,AD_MODEL,AD_GATEWAY_BASE_URL, etc. as ambient globals - Deploys to Cloudflare via the Workers API with full metadata
- Binds buyer secrets via the Cloudflare Secrets API
- Returns a global URL that routes to the worker
The rendered worker
// AgentDeploy Edge Worker — v2.0.0-edge
// Generated from template 42 version 1.0.0
// Platform-injected constants
const AD_DEPLOYMENT_ID = "uuid-here";
const AD_USER_ID = "buyer-uuid";
const AD_TEMPLATE_ID = 42;
const AD_MODEL = "openai/gpt-4o-mini";
const AD_REGION = "auto";
const AD_GATEWAY_BASE_URL = "https://gateway.agentdeploy.io";
// ─── Seller's bundled code (single ESM module) ───
// This is the output of: ad deploy (esbuild)
// Contains: @agentdeploy/edge-sdk + agents + @cloudflare/ai-chat + seller code
export class MyAgent extends AgentDeployChatAgent { ... }
export default createHandler(MyAgent);
Durable Object auto-detection
The platform's analyzeRenderedScript() uses regex patterns to detect DO classes:
// Detection patterns:
/export\s+class\s+(\w+)\s+extends\s+(?:Agent|AIChatAgent|AgentDeployAgent|AgentDeployChatAgent)\b/g
/export\s+(?:const|let)\s+(\w+)\s*=\s*(?:createAgent|createChatAgent)\s*\(/g
Each detected class results in:
- A
durable_object_namespacebinding in the Worker metadata - A
new_sqlite_classesentry in the migration tag (for SQLite-backed DOs)
No manual configuration needed — the platform infers everything from the bundled code.
Worker naming convention
edge-{template_id}-{user_id_8chars}-{timestamp}
Example: edge-42-abc12345-1721640000000
Lowercase, sanitized, max 52 characters (Cloudflare limit).
Execution limits
| Resource | Limit |
|---|---|
| CPU time | 50ms default (configurable up to 30,000ms) |
| Memory | 128 MB |
| Script size (raw) | 256 KB |
| Script size (SDK-bundled) | 3 MB |
| Request body | 100 MB |
| Subrequests | 50 per request (1,000 with nodejs_compat) |
| Concurrent connections | No limit |
Compatibility flags
SDK-based agents automatically get nodejs_compat injected when Agents SDK imports are detected. For raw workers, specify manually:
{
"compatibility_date": "2025-01-01",
"compatibility_flags": ["nodejs_compat"]
}
Bindings
The platform auto-generates these binding types based on script analysis:
| Binding type | Trigger | Use case |
|---|---|---|
durable_object_namespace | DO class detected | Stateful agent storage |
ai | env.AI reference detected | Workers AI models |
secret_text | Buyer-configured secrets | API keys, tokens |
plain_text | AD_* constants | Platform metadata |
For KV namespaces, R2 buckets, D1 databases, and queues — declare them in your wrangler.jsonc for local dev, and the platform passes them through if included in the edge version metadata.
Gateway integration
All LLM calls route through the AgentDeploy gateway:
Agent code → useGateway() → AD_GATEWAY_BASE_URL/v1/chat/completions → Gateway
│
┌────────────────────┤
│ │
Token metering Provider routing
│ │
Billing system OpenAI / Anthropic
/ Google / Groq
The gateway:
- Uses the
X-AD-Deploymentheader for authentication (no API key needed in agent code) - Tracks token usage per deployment
- Enforces buyer plan limits (overage protection)
- Writes revshare ledger entries for token markup
Local development
ad dev
This wraps wrangler dev with your project's wrangler.jsonc. The wrangler config includes:
- DO bindings for local testing
- SQLite migrations
nodejs_compatflag- Local
AD_*variable stubs
The local gateway stubs route to the platform's gateway URL, so billing and metering still work in dev mode.