Skip to content

Free, open-source AI video generator for Mac. Run LTX-2.5 and MiniMax H3 (Hailuo) locally on Apple Silicon: text-to-video and image-to-video with sound, lip-sync, character LoRA training, songs from lyrics (YuE2) and image editing (Qwen-Image-Edit). One-click install via Pinokio. Offline: no cloud, no API key, no NVIDIA GPU.

feat(agent): multiple takes per shot (generate_shot_images append:true)

mrbizarro7bdc177c981f
diff --git a/agent/prompts.py b/agent/prompts.py
index 573382b..eb17ffd 100644
--- a/agent/prompts.py
+++ b/agent/prompts.py
@@ -322,6 +322,13 @@ extensions. Use only when explicitly asked.
# Writing prompts FOR ANCHOR STILLS (Phase B)
+When the user asks for **more variations of an already-generated shot**
+("give me 4 more S3", "different takes of the doctor reveal"), call
+`generate_shot_images` again with the same `shot_label` AND
+`append: true`. The previous candidates stay clickable; the new take
+stacks below in the chat as "Take 2 / 2". The user can pick from any
+take.
+
A still prompt is NOT a video prompt. Differences:
- **No dialogue.** Audio comes with the video render in Phase C, not
diff --git a/agent/tools.py b/agent/tools.py
index 00808fc..952b08f 100644
--- a/agent/tools.py
+++ b/agent/tools.py
@@ -683,14 +683,23 @@ def _generate_shot_images(args: dict, ops: PanelOps, session: dict) -> dict:
aspect: "16:9" | "9:16" | "1:1" | "4:3" | "21:9" | "3:4" = "16:9"
seed_base: int = -1 — when >= 0, candidates use seed_base + i so the
run is reproducible. Use -1 for random seeds.
+ append: bool = false — when true AND the same shot_label has
+ existing candidates, ADD a new "take" instead
+ of overwriting. New PNGs land under
+ `take_NN/cand_*.png`. Use this when the user
+ says "give me 4 more variations of S3" — the
+ previous candidates stay clickable and the new
+ take stacks below.
Returns: {shot_label, prompt, candidates: [{png_path, seed, ...}, ...],
- elapsed_seconds, engine}.
+ takes: [{candidates, generated_at, prompt}, ...],
+ elapsed_seconds, engine, take_index}.
The UI renders the candidates as a clickable thumbnail grid in the
tool-result card. When the user clicks one, that selection is recorded
in `session.tool_state["selected_anchors"][shot_label]`. The agent
- can read the selections later via `get_selected_anchors`.
+ can read the selections later via `get_selected_anchors`. With multiple
+ takes, the user can pick from ANY take.
"""
from agent import image_engine as _image_engine
@@ -701,6 +710,7 @@ def _generate_shot_images(args: dict, ops: PanelOps, session: dict) -> dict:
n = max(1, min(8, int(args.get("n", 4))))
aspect = args.get("aspect", "16:9")
seed_base = int(args.get("seed_base", -1))
+ append = bool(args.get("append", False))
# Image engine config travels in PanelOps.capabilities so tools.py
# stays free of panel imports.
@@ -709,7 +719,30 @@ def _generate_shot_images(args: dict, ops: PanelOps, session: dict) -> dict:
safe_label = re.sub(r"[^a-z0-9_-]", "_", label.lower())[:40] or "untitled"
sid = session.get("session_id") or "session"
- out_dir = ops.uploads_dir / "agentflow" / sid / safe_label
+ base_dir = ops.uploads_dir / "agentflow" / sid / safe_label
+
+ # Resolve existing takes so we can compute the next subdir.
+ session.setdefault("anchor_candidates", {})
+ existing = session["anchor_candidates"].get(label) or {}
+ prior_takes = list(existing.get("takes") or [])
+ # Migration path: an older session may have a flat "candidates" list
+ # under the label without a "takes" array. Preserve as take_00.
+ if not prior_takes and existing.get("candidates"):
+ prior_takes = [{
+ "candidates": existing["candidates"],
+ "prompt": existing.get("prompt", prompt),
+ "generated_at": existing.get("generated_at", time.time()),
+ }]
+
+ if append and prior_takes:
+ take_index = len(prior_takes)
+ out_dir = base_dir / f"take_{take_index:02d}"
+ else:
+ # Fresh run (or no append flag) — overwrite. Keep the old behavior
+ # for the no-append branch so the agent's existing prompts work.
+ prior_takes = []
+ take_index = 0
+ out_dir = base_dir
t0 = time.time()
candidates = _image_engine.generate(
@@ -720,11 +753,17 @@ def _generate_shot_images(args: dict, ops: PanelOps, session: dict) -> dict:
)
elapsed = round(time.time() - t0, 2)
- # Track in session state.
- session.setdefault("anchor_candidates", {})
+ new_take = {
+ "candidates": candidates,
+ "prompt": prompt,
+ "generated_at": time.time(),
+ "take_index": take_index,
+ }
+ all_takes = prior_takes + [new_take]
session["anchor_candidates"][label] = {
"prompt": prompt,
- "candidates": candidates,
+ "candidates": candidates, # latest take, surfaced to legacy UI
+ "takes": all_takes,
"generated_at": time.time(),
}
@@ -732,6 +771,8 @@ def _generate_shot_images(args: dict, ops: PanelOps, session: dict) -> dict:
"shot_label": label,
"prompt": prompt,
"candidates": candidates,
+ "takes": all_takes,
+ "take_index": take_index,
"engine": cfg.kind,
"elapsed_seconds": elapsed,
}
diff --git a/mlx_ltx_panel.py b/mlx_ltx_panel.py
index af481e5..916aa69 100644
--- a/mlx_ltx_panel.py
+++ b/mlx_ltx_panel.py
@@ -8031,6 +8031,14 @@ HTML = r"""<!doctype html>
font-weight: 600; font-size: 10px;
letter-spacing: 0.4px; text-transform: uppercase;
}
+ .anchor-grid-meta .take-pill {
+ padding: 2px 8px; border-radius: 999px;
+ background: rgba(255,255,255,0.06);
+ color: var(--text);
+ font-weight: 500; font-size: 10px;
+ border: 1px solid var(--border);
+ letter-spacing: 0.2px;
+ }
/* Pick-state badge — right-aligned, neutral when nothing picked,
success-tinted when there's a pick. Updated in-place by
agentPickAnchor without re-rendering the grid. */
@@ -14794,10 +14802,28 @@ function renderToolResultCard(result) {
// Phase B of the director workflow: when the result carries
// `candidates`, render an interactive thumbnail grid below the head.
// The card stays expanded by default so the user can immediately pick.
- if (ok && inner && Array.isArray(inner.candidates) && inner.candidates.length > 0) {
- card.classList.add('open'); // open by default
- const grid = renderAnchorGrid(inner);
- card.appendChild(grid);
+ // Multi-take support: if `takes` is present, render every take stacked
+ // (take 1 / take 2 / take N) so the user can choose from any prior batch.
+ if (ok && inner) {
+ const takes = Array.isArray(inner.takes) && inner.takes.length > 1
+ ? inner.takes
+ : (Array.isArray(inner.candidates) && inner.candidates.length > 0
+ ? [{candidates: inner.candidates, prompt: inner.prompt, take_index: 0}]
+ : []);
+ if (takes.length > 0) {
+ card.classList.add('open'); // open by default
+ for (const take of takes) {
+ const grid = renderAnchorGrid({
+ shot_label: inner.shot_label,
+ prompt: take.prompt || inner.prompt,
+ engine: inner.engine,
+ candidates: take.candidates || [],
+ take_index: take.take_index,
+ take_count: takes.length,
+ });
+ card.appendChild(grid);
+ }
+ }
}
return card;
}
@@ -14811,11 +14837,19 @@ function renderAnchorGrid(payload) {
const selected = window.AGENT.selectedAnchors || {};
const isPicked = !!((selected[label] || {}).png_path);
+ // Multi-take label: when the same shot has multiple takes generated,
+ // tag each grid as "Take 1 of 3" so the user knows where the candidates
+ // came from and can compare across takes.
+ const takeChip = (typeof payload.take_index === 'number'
+ && (payload.take_count || 1) > 1)
+ ? `<span class="take-pill">Take ${payload.take_index + 1} / ${payload.take_count}</span>`
+ : '';
const meta = document.createElement('div');
meta.className = 'anchor-grid-meta';
meta.dataset.shot = label;
meta.innerHTML = `
<span class="label-pill">${escapeHtml(label)}</span>
+ ${takeChip}
<span>${payload.candidates.length} candidates · ${escapeHtml(engine)}</span>
<span style="flex:1"></span>
<span class="pick-state${isPicked ? ' is-picked' : ''}">${isPicked ? '✓ picked' : 'click to pick'}</span>