---
reliability: 4.0 # 5 − image edit .2 ×4 edit stages (test render / style sweep / variation grid / hero = .8) − 1 stage over 5 (.2); before/after + gallery are deterministic ffmpeg/HTML; no proven E2E showcase yet
---

# Sketch to portfolio art — agent playbook

> Paste this whole file (with the BRIEF filled in) into Claude cowork, chat, or Code. The agent walks through it with you and stops for your approval at every step that matters.

## What you'll get

A finished portfolio package built from the line work you already drew — not "AI from scratch with sketch as vague hint." The agent edits your sketch directly with `kontext-edit` / `gpt-image-edit`, which preserve your composition and apply the rendering style on top.

- **Sketch-locked rendering** — `kontext-edit` (or `gpt-image-edit`) runs FROM your sketch as the source image, so every render obeys the lines you actually drew.
- **4-up rendering style sweep** — your sketch rendered four different ways (painterly / cel-shaded / ink-wash / your target). Pick the rendering before you commit.
- **6-8 finished variations** — same composition, same line work, varied palette + lighting + texture. The grid you put on your portfolio's "process" page.
- **1 hero rendering** at `quality_threshold: 0.85` — the piece that goes on the front page.
- **Side-by-side before/after** — your raw sketch next to the hero, the demo reel of your range.
- **Gallery HTML page** — every variation embedded, palette swatches, the sketch credit, an artist bio block. Shareable as a portfolio entry.

**Time**: ~15 minutes wall clock. **Your attention**: about 4 minutes across 6 approvals. **Cost**: $0.80 – $2.00 end to end.

## Tell the agent about the sketch

```yaml
sketch_url:            # the raw drawing — upload to /upload first or paste a URL. JPG / PNG / scan from notebook is fine.
subject_description:   # e.g. "young woman in a flowing cloak, looking over her shoulder, river behind her"
style_target:          # e.g. watercolor · oil painting · digital painting · cel-shaded · photoreal · gouache · ink-and-wash · ghibli watercolor
palette_hex:           # 4 hex colors space-separated, e.g. #1F3A5F #C8A165 #F4E8D8 #6B2E2B  (or leave blank — the agent infers from style_target)
intended_use:          # portfolio · print · web · client commission · personal · gift
variation_count:       # 4 to 8 (default 6)
artist_name:           # for the gallery page credit
piece_slug:            # kebab-case, used in filenames, e.g. river-girl-watercolor
```

## How the agent should run this (interaction contract)

1. **CONFIRM (one message, ≤1 question):** restate in 1 line ("your sketch → <style_target>: 4-style sweep → N variations → 1 hero + gallery page, ~$0.80–2, ~15 min") + real choices: `variation_count` 4 vs 8 · kontext-edit (default) vs gpt-image-edit (if the composition has text/signage). Ask only if `sketch_url` won't load.
2. **PREVIEW CHECKPOINT:** the Step-1 single test render (~$0.01–0.05) IS the gate — show it NEXT TO the raw sketch and confirm the lines carry through BEFORE the 4-up sweep or the variation grid spends anything.
3. **NARRATE:** each wave is 1–3 min — 1-liner with job ids ("style sweep: 4 renders firing, ~2 min"); poll `get_create_media` every 10–15s, ≤4 image jobs in flight, never silent >2 min.
4. **FAIL GRACEFULLY:** kontext-edit losing the line work → `gpt-image-edit` (the other structure-holding edit cap); 422/timeout → retry once → swap edit cap; NEVER fall back to text-to-image — that abandons the sketch lock, which is the whole point. ≤2 retries per render; ship the strongest passing variations over a forced full grid.
5. **DELIVER:** gallery HTML + hero + one honest line ("edit caps hold composition ~95%; very fine hatching/texture detail is the cap ceiling — it softens in rendering") + ONE next step (same `style_target` on the next sketch for portfolio cohesion).

## Quality controls (new — auto-applied)

This playbook leverages the closed quality loop. The agent applies these by default; you don't have to ask:

- **Cost upfront.** Before any multi-step batch fires, the agent calls `submit_plan` with `confirm:false` and shows you the proposed steps + total cost. Nothing runs until you approve.
- **Auto-retry on weak shots.** The server default is `quality_threshold: 0.7`. For the hero rendering the playbook step tells the agent to pass `quality_threshold: 0.85` so a low-confidence first try gets one auto-retry before you see it.
- **Critic verdict on the result.** When a multi-shot step finishes, the agent reads the `critique` field on the response (verdict: ship / iterate, plus issues / missing items) and surfaces it for your review.
- **One-click recovery.** If a step fails, `get_plan` returns a `recovery` hint pointing at `replan({plan_id})` — the agent classifies the failure and proposes a recovery plan you can approve.
- **End-of-project scorecard.** The final wrap-up calls `get_scorecard({project_id})` with succeeded count, mean quality score, critic verdict, total cost, and wall time.

You can override any of these per step: pass `quality_gate: false` on cost-sensitive tries, `quality_threshold: 0.6` for stylized / experimental work, or `submit_plan({plan_id, confirm:true})` to skip the cost-preview pause when you trust the chain.

## How this works

Six gates. The premise: every render runs FROM your sketch as the source image via `kontext-edit` / `gpt-image-edit` — image-edit models that hold source structure — so the drawing you made is preserved, not re-guessed.

## The steps

### Step 0 — Confirm the brief

The agent reads back the BRIEF and previews your sketch_url inline so you can spot upload errors before any inference fires.

**STOP**: "Brief looks right? Sketch loads? (approve / edit [field] [new value])"

### Step 1 — Confirm the sketch is the source (~10s, ~$0.01)

The agent confirms it will render FROM your `sketch_url` as the source image (not from a text description). One cheap test render proves the lines carry through: `create_media({ action: "restyle", model_override: "kontext-edit", source_url: sketch_url, prompt: "<style_target>, faithful to the line composition" })`.

> **For the agent**: `kontext-edit` and `gpt-image-edit` are the only image-edit caps that hold source structure on production BYOC. Pass `source_url` = the raw sketch on EVERY render in this playbook — that is what locks the composition. Show the test render next to the original so the user confirms the lines carried through.

**STOP**: "Lines carry through cleanly? (approve / refine [direction])"

### Step 2 — 4-up rendering style sweep (~3 min, ~$0.40)

Now the rendering decision. The agent calls `create_media` four times in parallel: each with `action: "restyle"`, `source_url: sketch_url`, your `subject_description`, and a different rendering style. Default sweep:

1. Painterly digital — visible brushwork
2. Cel-shaded — hard line work, flat color
3. Ink-wash with selective color
4. Your `style_target` from the brief

Each output preserves your composition but feels totally different. This is where you commit to a look before spending on a full variation grid.

> **For the agent**: pass `quality_threshold: 0.85`. Use `model_override: "kontext-edit"` (or `gpt-image-edit` if the composition has text/signage) — both respect source structure. The raw sketch stays the `source_url` on every call.

**STOP**: "Which rendering becomes canonical? (1 / 2 / 3 / 4) — this locks the style for the variation grid."

### Step 3 — Variation grid (~5 min, ~$0.60)

Your locked composition + locked rendering style, now varied across `variation_count` outputs. The agent calls `create_variations` with `mode: mixed` — half seed-variations (same prompt, different RNG; gives you compositional luck), half palette-variations (your palette_hex shifted across hero / accent / dominant slots). Result: 6-8 outputs that all look like your drawing, all look like the same artistic hand, all carry the right color story.

> **For the agent**: pass the raw sketch as `source_url` on every variation so the line work stays locked. Pass `quality_threshold: 0.75` (relaxed from hero standard — these are exploration shots). Surface the critic verdict on the batch.

**STOP**: "Open the variation grid. Approve the keepers, or redo specific? (approve / redo [#] [direction])"

### Step 4 — Hero rendering (~2 min, ~$0.30)

Pick your favorite variation from Step 3. The agent re-renders that exact composition at premium quality — `quality_threshold: 0.85`, `max_quality_retries: 1`, larger output dimensions, the rendering style fully committed. This is the portfolio piece.

> **For the agent**: use `gpt-image-edit` if the composition has any text / signage (best typography), `kontext-edit` otherwise. Keep `source_url` = the raw sketch and pass the chosen Step 3 variation as `quality_anchor_url` so the hero matches the variation the user picked.

**STOP**: "Hero shown. Approve, or one refine pass? (approve / refine [direction])"

### Step 5 — Before/after side-by-side (~30s, ~$0.05)

The agent uses `ffmpeg-overlay` to compose your raw sketch on the left and the hero rendering on the right, with a thin divider and your `artist_name` watermark in the corner. This is the "from this to this" piece that does the heaviest lifting on social — it shows the human craft and the finishing work together.

> **For the agent**: 1:1 composition, sketch left-half, hero right-half, divider color from the palette. No AI inference — pure ffmpeg composition.

**STOP**: "Before/after approved? (approve / redo with [different framing])"

### Step 6 — Gallery HTML page (~1 min, ~$0.001)

The agent writes a single-page HTML — `public/galleries/{piece_slug}.html` — with the hero rendering full-bleed at top, palette swatches, the variation grid below, before/after, sketch credit, an artist bio block (LLM-written from `artist_name` + `style_target`). Self-contained — open in any browser, send as portfolio link.

### Final step — scorecard wrap-up

Call `get_scorecard({project_id: ...})` — paste output to your channel.

```
Scorecard for cjob_xxx
N/N renderings shipped — critic: SHIP
Title: {piece_slug}
Steps: N/N succeeded (100%)
Quality: mean X.XX · M/N passed · K retries
Cost: $X.XX actual (est $Y.YY) · Ts wall time
Viewer: <gallery URL>
```

## When you're done

```
✅ Gallery page: public/galleries/{piece_slug}.html
✅ Hero rendering: <URL>
✅ Variation grid: <URL × N>
✅ Before/after: <URL>
✅ Source sketch: <URL>

Total spent: $X.XX
Total wall-clock: MM:SS
```

## What to do next

Your sketches are now finishable in 15 minutes apiece — that's the whole point. A pencil drawing in your notebook, scanned at lunch, becomes a portfolio piece by dinner.

Run the playbook a second time with the same `style_target` on a different sketch — your portfolio gains visual cohesion across pieces because the rendering style is now your style. Eventually you'll have ten sketches finished in the same hand: that's a series.

If you're a comic creator, the line-lock step is the unlock. Pencil the page, scan, run this playbook with `style_target: cel-shaded`, and you've got finished art that obeys your panel composition exactly. Repeat across an issue. For commission work, the variation grid + hero combo is what clients actually want to see — "here are the four directions, here's the one I'd ship."
