ensemble: company-inteldescription: Analyze a company from its domainagents: # Fetch company data - name: fetch operation: http config: url: https://api.company-data.com/lookup?domain=${input.domain} method: GET cache_ttl: 3600 # Cache for 1 hour # Analyze with AI - name: analyze operation: think config: model: claude-3-5-sonnet-20241022 prompt: | Analyze this company data and provide: - Industry classification - Key products/services - Market position (1-5 scale) - Growth indicators Company data: ${fetch.output} Respond in JSON format. response_format: type: json_object # Return resultsoutput: company: ${input.domain} analysis: ${analyze.output} cached: ${fetch.cached}
name = "my-ai-workflow"main = "src/index.ts"compatibility_date = "2024-11-01"# KV for caching (optional but recommended)[[kv_namespaces]]binding = "CACHE"id = "your_kv_namespace_id"# AI Gateway for observability (optional)[ai]binding = "AI_GATEWAY"
Create KV namespace:
Copy
wrangler kv:namespace create "CACHE"# Copy the ID to wrangler.toml
# Start local dev serverconductor dev# In another terminal, test itcurl http://localhost:8787/ensembles/company-intel \ -H "Content-Type: application/json" \ -d '{"domain": "stripe.com"}'
# Install Edgitnpm install -g @ensemble-edge/edgitedgit init# Version your promptedgit tag create company-analysis-prompt v1.0.0# Deploy to productionedgit deploy set company-analysis-prompt v1.0.0 --to prod
Add your API key to .dev.vars for local development:
Copy
echo 'ANTHROPIC_API_KEY=sk-ant-...' >> .dev.vars
For production, add it in Cloudflare dashboard under Workers > Settings > Variables.
Error: KV namespace not found
Create a KV namespace first:
Copy
wrangler kv:namespace create "CACHE"
Copy the ID to your wrangler.toml file.
Cold starts taking longer than 50ms
First request always takes longer (~100-200ms). Subsequent requests should be <50ms cold start + execution time.Enable caching to get <10ms for repeated requests:
Copy
config: cache_ttl: 3600 # Cache for 1 hour
AI Gateway not working
Make sure you’ve configured AI Gateway in Cloudflare dashboard:
That’s it. You’ve got a production AI workflow running on the edge with caching, versioning, and infinite scale.No Docker, no Kubernetes, no server management. Just Git, YAML, and Cloudflare Workers.