Skip to content

AaronKuebler/n8n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

PCE n8n Workflow Suite

Three n8n workflows that turn the Predictive Creative Engine (PCE) — a proprietary neural network for eCommerce ad-creative performance forecasting — into a self-sustaining operational system.

EyesHandsMemory: research input, execution output, self-learning loop.


TL;DR

This repository contains three production-shaped n8n workflows that surround a neural network (the PCE) with the operational layer an agency actually needs — automated consumer-insights ingestion, score-to-task routing across Claude / ClickUp / Slack, and a nightly calibration pipeline that decides on its own whether to retrain the model.

The PCE itself is kept private. The workflows here show how I orchestrate a trained neural network into a business, not how I trained it.

Workflow Role Model File
1 — Audience Persona Extractor Turn scraped consumer voice into a structured persona profile Claude Opus (Tool-Use) workflows/wf1-audience-persona.json
2 — Score-to-Action Router Translate PCE predictions into editor briefs, Slack alerts and ClickUp tasks Claude Sonnet workflows/wf2-score-to-action.json
3 — Calibration & Retrain Trigger Nightly drift analysis + autonomous retrain decision Claude Opus workflows/wf3-calibration-retrain.json

About the Predictive Creative Engine (context, not internals)

The PCE is a trained neural network, not an LLM wrapper. It forecasts ad-creative performance across ten business-critical KPIs before any media budget is spent, per target audience, and surfaces counterfactual "levers" — concrete attribute changes that would raise the creative's expected winner-score.

It is multi-tenant: each agency client has isolated data, can run on their own model artefact, and can override the scoring logic per audience.

What makes it different from "yet another AI scorer":

  • It is a trained neural network, not a prompt chain over GPT
  • It outputs calibrated numeric predictions, not fuzzy text
  • Behavioural-economics and direct-response frameworks are encoded into the training pipeline (Cialdini, Schwartz, PAS, Georgi and others) — the model doesn't rediscover psychology from scratch, it starts from priors and refines them against real campaign outcomes
  • It has a real feedback loop: post-launch KPIs flow back into a quality-gated retrain pipeline, so it learns from every campaign it sees

The API surface these workflows interact with:

POST /api/v1/rank/attributes              rank pre-tagged creatives
POST /api/v1/rank/upload                  upload + extract + rank in one call
POST /api/v1/feedback                     submit ground-truth after launch
POST /api/v1/tenants/{id}/audience-persona    enrich an audience profile
POST /api/v1/retrain/trigger              kick a quality-gated retrain

Every call is authenticated with an X-API-Key header scoped to a tenant.


Workflow 1 — Audience Persona Extractor (Eyes)

What it does

Takes a raw corpus of consumer voice (Reddit threads, Trustpilot reviews, niche forum posts) for a specific target audience and distils it into a structured Persona Profile that is POSTed into the PCE's audience-persona endpoint. That profile is then used by the neural network as additional audience-side context during scoring.

flowchart LR
    A[Webhook<br/>corpus + tenant + audience] --> B[Validate]
    B --> C[Build Prompt]
    C --> D[Claude Opus<br/>Tool-Use schema]
    D --> E[Extract Persona]
    E --> F[POST to PCE API]
    F --> G[Respond]
Loading

Why I built it

A neural network is only as good as its understanding of the audience it scores against. Without this workflow, the audience context has to be hand-crafted by a senior strategist. With it, the research step becomes automated, repeatable, and tenant-scoped.

Interesting design decisions

  • Tool-Use instead of JSON-prompting. Claude's tools API with an explicit input_schema guarantees schema conformance at the API level. No parser gymnastics, no regex, no "please return JSON" in the prompt.
  • Evidence-bound output. Every claim in the persona must be traceable to at least one quote from the corpus — enforced in the system prompt and audited by the downstream PCE endpoint.
  • Confidence score per run. Low-quality corpora produce a low-confidence persona, which the PCE then down-weights. No silent garbage-in / garbage-out.

Workflow 2 — Score-to-Action Router (Hands)

What it does

Consumes a single PCE prediction (one creative × one audience, with winner score, psych drivers, psych blockers, and counterfactual recommendations) and routes it into the agency's execution layer based on the score band:

  • score < 50 — Claude Sonnet drafts an editor-ready revision brief in German, with each instruction tagged with the underlying sales-psychology lever. A ClickUp task is opened automatically.
  • 50 ≤ score < 75 — Slack notification to #creative-review with a concise iteration hint.
  • score ≥ 75 — Slack launch alert to #media-buying. @channel above 90.

Thresholds are configurable per tenant.

flowchart LR
    A[Webhook<br/>PCE prediction] --> B[Validate + Normalise]
    B --> C{Score Router}
    C -->|< 50| D[Sonnet → Revision Brief]
    C -->|50–75| E[Slack Iteration Hint]
    C -->|≥ 75| F[Slack Launch Alert]
    D --> G[ClickUp Task]
    G --> H[Respond]
    E --> H
    F --> H
Loading

Why I built it

Without this, the PCE is a tool that produces numbers. With it, the PCE becomes an operational nervous system — every prediction ends up as a concrete task on someone's plate, without a human interpreter in between.

Interesting design decisions

  • Framework-named revision briefs. Each instruction carries its psychology tag ([Authority / Cialdini], [Big Promise / Georgi]) — juniors learn the framework by doing, seniors can defend the brief to the client.
  • Three distinct downstream tools, not one. Ticket for work that needs doing, Slack thread for decisions, Slack alert for scaling. The right channel per use-case, not "everything to Slack".
  • Per-tenant thresholds. A DTC fashion brand and a premium B2B SaaS will have very different "winner" definitions — the workflow reads thresholds from the caller payload.

Workflow 3 — Calibration & Retrain Trigger (Memory)

What it does

Runs nightly at 03:00, pulls the last 21 days of PCE predictions from Supabase, joins them against actualised campaign performance (from campaign_actuals), and runs a Claude Opus analysis to classify systematic errors into three buckets:

  • CREATIVE_FATIGUE — delta grows with creative age
  • MARKET_SHIFT — uniform delta across >30 % of rows in a period
  • MODEL_BIAS — delta correlates with specific attribute combos

If model bias is detected, the workflow autonomously calls the PCE's /retrain/trigger endpoint with a warm-start payload. A digest goes to #model-health either way.

flowchart LR
    A[Cron<br/>03:00 daily] --> B[Fetch Predictions<br/>21d window]
    B --> C[Fetch Actuals]
    C --> D[Join + Compute Deltas]
    D --> E{≥100 rows?}
    E -->|yes| F[Claude Opus<br/>Classify Errors]
    F --> G{Retrain<br/>recommended?}
    G -->|yes| H[POST /retrain/trigger]
    G -->|no| I[Slack Report]
    H --> I
    E -->|no| I
Loading

Why I built it

A neural network that never retrains goes stale within months. A neural network that retrains on every new datapoint goes unstable within days. This workflow is the deliberate middle path — it decides, based on evidence, whether a retrain is warranted, and lets the PCE's own quality-floor gate make the final accept/reject call.

Interesting design decisions

  • Hybrid statistics + LLM judgement. Deterministic delta calculation for the numbers, Claude for the semantic "what caused this" classification. Right tool for each sub-task.
  • Evidence threshold. No retrain decision below 100 joined (creative × audience) rows. The production path extends this with effect-size gating — a retrain should only fire when the bootstrap 95 % CI of the predicted-vs-actual delta excludes zero, so tiny samples with large p-values can't move the model.
  • Autonomous, not automatic. The workflow can only recommend and trigger; the PCE's own quality-floor gate in the training pipeline decides whether the new artefact actually ships. Two independent safety layers, not one.

Setup

Prerequisites

  • n8n instance (self-hosted or Cloud). Tested on n8n 1.60+.
  • Anthropic API key with access to claude-opus-4-7, claude-sonnet-4-6, and claude-haiku-4-5.
  • PCE instance with a tenant and API key already provisioned.
  • Supabase project (for Workflow 3 — optional if you run the calibration analysis against another store).
  • ClickUp + Slack webhooks (for Workflow 2).

Environment variables (configure in n8n → Settings → Variables)

Variable Used in Description
ANTHROPIC_API_KEY WF1, WF2, WF3 Anthropic Messages API key
PCE_API_BASE WF1, WF3 e.g. https://api.your-domain.com
PCE_API_KEY WF1, WF3 Tenant-scoped key
CLICKUP_TOKEN WF2 pk_...
CLICKUP_LIST_ID WF2 Numeric list ID
SLACK_WEBHOOK_REVIEW WF2 #creative-review incoming webhook
SLACK_WEBHOOK_MEDIA WF2 #media-buying incoming webhook
SLACK_WEBHOOK_MODEL_HEALTH WF3 #model-health incoming webhook
SUPABASE_URL WF3 https://<project>.supabase.co
SUPABASE_SERVICE_KEY WF3 Service-role key (needs read access)

Import

For each workflow:

  1. n8n → WorkflowsImport from File → select the JSON
  2. Verify all HTTP nodes pick up the environment variables
  3. Activate the workflow
  4. For Workflows 1 & 2, copy the webhook URL and configure the caller (PCE, an upstream scraper, or your CI) to POST to it
  5. For Workflow 3, the schedule trigger activates automatically

Test payloads

See examples/ for minimal reference payloads that trigger each workflow end-to-end.


Tech stack at a glance

  • Orchestration: n8n (webhooks, schedule triggers, HTTP, Code, Switch, IF)
  • LLM layer: Anthropic Messages API with Tool-Use for schema enforcement
  • Models: Claude Opus 4.7 (analysis-heavy), Sonnet 4.6 (structured generation), Haiku 4.5 (fast classification) — chosen per task
  • Neural network: Proprietary multi-tenant PyTorch model — its API surface is documented above, its weights are not in this repo
  • Storage / observability: Supabase (Postgres) for audit trails and actuals
  • Downstream integrations: ClickUp, Slack

Design principles

The four principles that drove every decision in this repo:

  1. Deterministic where possible, LLM where necessary. Math is done in code, semantic reasoning in Claude. Never the other way round.
  2. Schema-first. Every AI output is enforced against a JSON schema at the API level (Tool-Use), not hoped for in the prompt.
  3. Autonomous with guard-rails. Workflows can make decisions (route tasks, trigger retrains) but only within explicit thresholds and sample-size minimums.
  4. Per-tenant from day one. There is no "global config" — every workflow is parameterised by tenant, so multi-client scaling is free.

About

These workflows were designed and implemented as part of an application for the AI Systems & Automations Architect role at ECOM HOUSE GmbH.

They demonstrate:

  • End-to-end AI architecture — deciding what should be solved by a trained model, what by an LLM, and what by deterministic code
  • Translating expert knowledge into reproducible systems (Wissenstransfer)
  • Cross-functional integration — strategy, creative, media buying, ML ops — under one orchestration layer
  • Monitoring and autonomous iteration loops

The neural network itself (the PCE) is kept as a private artefact. What is shown here is the operational wrapping that turns a model into a product.


License & contact

This repository serves as a technical proof-of-concept. Commercial rights and full PCE integration details are available upon request.

Aaron Kuebler

About

hree n8n workflows orchestrating a proprietary neural network for ad-creative performance forecasting (Eyes / Hands / Memory)

Topics

Resources

Stars

Watchers

Forks

Contributors