Ultron Workers

Marketing pipeline

The marketing worker is one Cloudflare Worker that takes a brief and produces a rendered carousel. It runs a seven-stage pipeline end to end inside the worker: retrieve exemplars, plan a deck, validate, render to PNGs in-worker, score every slide with vision, promote good runs to the exemplar index, return the result. No hop to the containerized cloud runtime on the hot path.

Updated today

Overview

At a glance
Worker
ultron-marketing-swarm
Entry
POST /carousel
Region
Cloudflare edge, globally distributed
Renderer
In-worker Satori + Resvg WASM
Planner model
@cf/google/gemma-4-26b-a4b-it via Workers AI
Vision model
@cf/llava-1.5-7b via Workers AI
Embedding model
@cf/baai/bge-base-en-v1.5 (768 dim)
Promote threshold
Average slide score >= 0.85, or user starred

The marketing worker is one of the Ultron Workers that runs entirely on Cloudflare. It does not call back to the main containerized cloud runtime at any point during a render; everything from the brief to the PNG happens at the edge. That keeps latency predictable, keeps cost low, and lets the worker scale linearly with traffic.

Entry point

One handler, one route, one job: turn a brief into a carousel.

cf-workers/marketing-swarm/src/index.tsts
1// POST /carousel
2// body: { brief: string, vibe?: string, canvasSize?: "1080x1080" | "1080x1350" }
3// returns: { id: string, score: number, slides: { url: string }[] }
4router.post("/carousel", async (req, env) => {
5 const body = await req.json<CarouselRequest>()
6 return runCarousel(body, env)
7})
8
9// GET /health → readiness probe
10router.get("/health", () => new Response("ok"))
11
12// POST /carousel/:id/star → user-promotes a run to the exemplar index
13router.post("/carousel/:id/star", async (_, env, params) => starRun(params.id, env))

The seven-stage pipeline

Each stage is one file under src/carousel/. Stages run in sequence; failure short-circuits to a structured error.

  1. 01
    Retrieve
    Embed the brief via bge-base-en-v1.5, query the carousel-briefs Vectorize index, pull the top exemplars (PNG + spec JSON) from the carousel-engine-exemplars R2 bucket.
  2. 02
    Plan
    Send the brief, the exemplars, and the component index summary to Gemma. The model returns a CarouselSpec: a list of freeform slides with positioned elements.
  3. 03
    Validate
    Walk the spec. Reject any slide that is not freeform, anything over the per-slide character budget, anything missing a required backdrop or icon.
  4. 04
    Render
    Compile the spec to JSX with the SlideRenderer dispatcher, run Satori to produce SVG per slide, rasterise to PNG with resvg-wasm. All in the worker.
  5. 05
    QA
    Send each slide PNG to LLaVA with a structured rubric, parse a per-slide score and a short critique.
  6. 06
    Promote
    If the average score is at or above the threshold, upsert the run into D1, push the brief embedding into Vectorize, and copy the PNGs into the exemplars bucket.
  7. 07
    Respond
    Return the run id, the score, and the signed URLs for every slide.

Models in the loop

Three Workers AI models do the heavy lifting.

StageModelBinding
Retrievebge-base-en-v1.5 (text embedding)env.AI.run("@cf/baai/bge-base-en-v1.5", ...)
Plan@cf/google/gemma-4-26b-a4b-itenv.AI.run("@cf/google/gemma-4-26b-a4b-it", ...)
QA@cf/llava-1.5-7benv.AI.run("@cf/llava-1.5-7b", { image, prompt })
Note
Gemma was picked over Kimi K2.6 for the planner because Gemma's structured-output adherence is materially better on the carousel DSL. Kimi works for prose-heavy planning but loses the position grids the renderer needs.

Worker bindings

The wrangler.toml declares every binding the pipeline reads or writes.

cf-workers/marketing-swarm/wrangler.tomltoml
1name = "ultron-marketing-swarm"
2main = "src/index.ts"
3compatibility_date = "2026-04-01"
4compatibility_flags = ["nodejs_compat"]
5
6[ai]
7binding = "AI"
8
9[[r2_buckets]]
10binding = "INDEX"
11bucket_name = "carousel-engine-index"
12
13[[r2_buckets]]
14binding = "EXEMPLARS"
15bucket_name = "carousel-engine-exemplars"
16
17[[d1_databases]]
18binding = "DB"
19database_name = "carousel-engine"
20
21[[vectorize]]
22binding = "BRIEFS"
23index_name = "carousel-briefs"

Run tracing

Every run leaves a row in D1 with timings and outcomes.

The worker writes a render_runs row with the brief, the spec, the per-stage timing, and the final score on every run. Promoted runs also land in carousels with the slide URLs and the QA notes. Reading either table is the fastest way to understand why a particular run did what it did. See Storage for the full schema.

File map

cf-workers/marketing-swarm
wrangler.tomlbindings (AI, R2 x2, D1, Vectorize)
src
index.tsrouter + entry
carousel
index.tsorchestrator
retrieve.tsVectorize search + exemplar hydration
plan.tsGemma planner prompt
validate.tsper-slide budgets, freeform-only rule
render-v2/index.tsSatori + Resvg WASM
qa.tsLLaVA vision scoring
promote.tsD1 + Vectorize + R2 promote

Glossary

Brief
The plain-language input to the pipeline. One sentence to a short paragraph describing what the carousel should communicate.
Spec
The structured CarouselSpec produced by the planner and consumed by the renderer.
Exemplar
A past run that scored above the promote threshold. Stored in R2 and indexed in Vectorize for retrieval.
Promote
The act of writing a successful run into the canonical D1 row and pushing its brief embedding into Vectorize so future briefs can retrieve it.
Star
User-driven promotion. Forces a run to be added to the exemplar index even if its score was below the auto-promote threshold.
Renderer
The in-worker Satori plus Resvg WASM pipeline that turns the spec into PNGs without leaving the edge.