Drive Google Flow from Claude, Codex or a local control panel, on Mac or Windows — using your Google AI subscription credits instead of the pay-per-use video API. No browser extension.
Agent image batches carry reference images, like Flow's + button
GTAI-184b548f3aa72
diff --git a/README.md b/README.mdindex e345508..1ecf800 100644--- a/README.md+++ b/README.md@@ -195,7 +195,7 @@ agree on what is running. That API listens on 127.0.0.1 only and needs a per-run| `flow_assets` | List images and videos already in the Flow project (usable as `asset:<title>`) || `flow_download` | Download existing project media without regenerating. Free, including the 1080p / 2K upscale. A scene comes down as one stitched film || `flow_trash` | Move an image, video or scene in the Flow project to Flow's Trash, where it can be restored. Exact title only; refuses if two items share it; never deletes permanently |-| `flow_agent_images` | Fast image batch: hands up to 50 scenes to Flow's own Agent mode, rendered in parallel (20 images in ~204 s), 0 credits. Each image is matched back to its scene by its stored prompt, so file numbers are right in any finish order. Scenes the agent drops are re-asked of it (up to 2 rounds), then re-run one by one |+| `flow_agent_images` | Fast image batch: hands up to 50 scenes to Flow's own Agent mode, rendered in parallel (20 images in ~204 s), 0 credits. Each image is matched back to its scene by its stored prompt, so file numbers are right in any finish order. Scenes the agent drops are re-asked of it (up to 2 rounds), then re-run one by one. `references` attaches characters, places and objects once in the agent's composer (like its + button), and `scene_references` says which scenes use which, so a whole story stays on-model; scenes made one by one keep their references || `flow_edit` | Video-to-video edit of a clip already in the project (relight, weather, remove objects). Flow shows no quote first; about 20 credits for a 4 s clip || `flow_continue` | Start a clip from the last frame of an existing one **with a character or your avatar still attached**. The composer allows a start frame or attached characters, never both, so this drives Flow's agent mode, which does both. No quote beforehand || `flow_character` | Create a reusable character from a description (Flow draws the portrait) or an image, with a personality and a stock voice; use it as `asset:<name>` |diff --git a/src/core.ts b/src/core.tsindex 2ea80e2..95d6993 100644--- a/src/core.ts+++ b/src/core.ts@@ -156,6 +156,22 @@ export const shapes = {scenes: z.array(z.string().min(1)).min(1).max(50).describe("One image description per scene, in order."),aspect_ratio: z.enum(["16:9", "9:16", "1:1", "4:3", "3:4"]).default("16:9"),download_quality: z.enum(["original", "upscaled"]).optional(),+ references: z+ .array(+ z.object({+ image: z.string().min(1).describe("Absolute image path, or 'asset:<title>' for an image or character already in the Flow project."),+ name: z.string().min(1).max(40).describe("Short name the scenes use for it, e.g. 'Ines' or 'the station'."),+ }),+ )+ .max(10)+ .optional()+ .describe(+ "Reference images for the whole batch (characters, places, objects), attached once in the agent's composer like the + button does, so every scene stays on-model. Pair with scene_references to say which scenes use which.",+ ),+ scene_references: z+ .array(z.array(z.string()))+ .optional()+ .describe("One list per scene, in scene order: the reference names that scene uses (empty list for none). Without it the agent decides which references fit each scene."),},voices: {},narrate: {@@ -423,6 +439,7 @@ export class LocalCore implements Core {prompt: `Agent batch: ${pick.length} failed image(s) again`,agent_scenes: pick.map((i) => p.agent_scenes![i]),agent_numbers: pick.map((i) => numbers[i]),+ agent_scene_refs: p.agent_scene_refs ? pick.map((i) => p.agent_scene_refs![i]) : undefined,file_stem: `scene-${String(numbers[pick[0]]).padStart(2, "0")}`,}),);@@ -521,9 +538,20 @@ export class LocalCore implements Core {return `${prefix}-${String(Math.max(0, ...onDisk, ...queued) + 1).padStart(2, "0")}`;}- async agent({ project, scenes, aspect_ratio, download_quality }: Args<"agent">) {+ async agent({ project, scenes, aspect_ratio, download_quality, references, scene_references }: Args<"agent">) {const output_dir = projectDir(project);+ if (scene_references && scene_references.length !== scenes.length) {+ throw new Error(`scene_references has ${scene_references.length} entries for ${scenes.length} scenes; give one list per scene (empty for none).`);+ }+ const known = new Set((references ?? []).map((r) => r.name.toLowerCase()));+ const unknown = [...new Set((scene_references ?? []).flat().filter((n) => !known.has(n.toLowerCase())))];+ if (unknown.length) throw new Error(`scene_references names ${unknown.map((n) => `"${n}"`).join(", ")}, which is not in references.`);+ for (const r of references ?? []) {+ if (!r.image.startsWith("asset:") && !existsSync(r.image)) throw new Error(`Reference image not found: ${r.image}`);+ }const job = this.queue.add({+ agent_refs: references?.length ? references : undefined,+ agent_scene_refs: references?.length ? scene_references : undefined,prompt: `Agent batch: ${scenes.length} images`,type: "image",max_credits: 0,diff --git a/src/flow.ts b/src/flow.tsindex 8684b73..1a8d4ac 100644--- a/src/flow.ts+++ b/src/flow.ts@@ -1440,11 +1440,36 @@ async function agentRound(const clear = page.getByRole("button", { name: "Clear prompt" });if (await clear.isVisible().catch(() => false)) await clear.click();- const script = indexes.map((i) => `Scene ${numberOf(i)}: ${scenes[i].replace(/\s*\n+\s*/g, " ").trim()}`).join(" ");+ // Reference images ride along as ingredient chips, attached the way the + button does, once per round (the composer+ // is cleared between rounds). The script then names them, and each scene says which ones it uses.+ const refs = s.agent_refs ?? [];+ const assets = s.agent_ref_assets ?? [];+ if (refs.length) {+ for (const [k, name] of assets.entries()) {+ step(job, `attaching reference ${k + 1} of ${assets.length}`);+ await attachAsset(page, page.getByRole("button", { name: "Add ingredients to the prompt box" }), name);+ await pause(page, 700);+ }+ const attached = await page.getByRole("button", { name: "Ingredient" }).count();+ if (attached < assets.length) throw new Error(`Only ${attached} of ${assets.length} reference image(s) attached in the agent composer.`);+ }+ const usesOf = (i: number) => s.agent_scene_refs?.[i];+ const script = indexes+ .map((i) => {+ const uses = usesOf(i);+ const tag = !refs.length || !uses ? "" : uses.length ? ` (use references: ${uses.join(", ")})` : " (no reference)";+ return `Scene ${numberOf(i)}${tag}: ${scenes[i].replace(/\s*\n+\s*/g, " ").trim()}`;+ })+ .join(" ");+ const legend = refs.length+ ? ` The ${refs.length} attached image(s) are references: ${refs.map((r, k) => `${assets[k] ?? `image ${k + 1}`} is ${r.name}`).join("; ")}. ` ++ `Whenever a scene shows one of them, keep it exactly as it looks in its reference (face, hair, clothing, shape, colours), ` ++ `but stage each scene as its own description says; the references are for likeness only, never copy their pose or background.`+ : "";const lead = retry? `${indexes.length} image(s) from the last batch failed to generate. Generate them again now, one image per scene`: `Generate exactly ${indexes.length} separate images, one image per scene, in scene order`;- const ask = `${lead}. Images only, never video. ${aspect} aspect ratio. Do not ask questions, generate them now. ${script}`;+ const ask = `${lead}. Images only, never video. ${aspect} aspect ratio. Do not ask questions, generate them now.${legend} ${script}`;await page.locator(".ProseMirror").first().click();await page.keyboard.insertText(ask);await pause(page, 800);@@ -1657,6 +1682,17 @@ export async function runAgentBatch(job: Job): Promise<string[]> {let agentRetries = 0;let agentProblem = "";try {+ // References are uploaded once with readable names (the agent sees them), before Agent mode hides the upload menu.+ if (s.agent_refs?.length && !s.agent_ref_assets?.length) {+ await setAgentMode(page, false);+ const assets: string[] = [];+ for (const [k, r] of s.agent_refs.entries()) {+ step(job, `uploading reference ${k + 1} of ${s.agent_refs.length} (${r.name})`);+ const label = r.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 24) || `ref${k + 1}`;+ assets.push(await uploadAsset(page, job, r.image, label));+ }+ s.agent_ref_assets = assets;+ }step(job, "switching Agent mode on");await setAgentMode(page, true);step(job, "setting the agent to generate without asking");@@ -1693,6 +1729,17 @@ export async function runAgentBatch(job: Job): Promise<string[]> {const base = Number(s.file_stem.match(/\d+/)?.[0] ?? 1);const numberOf = (i: number) => s.agent_numbers?.[i] ?? base + i;const stillFails = Number(process.env.FLOW_MCP_SIMULATE_FAILED ?? 0); // test hook: pretend this scene failed for good+ // A scene made one by one keeps its references: the uploaded copies when there are some, else the original files.+ const refsFor = (i: number): string[] | undefined => {+ const refs = s.agent_refs ?? [];+ if (!refs.length) return undefined;+ const uses = s.agent_scene_refs?.[i];+ const picked = refs+ .map((r, k) => ({ r, k }))+ .filter(({ r }) => !uses || uses.some((u) => u.toLowerCase() === r.name.toLowerCase()))+ .slice(0, 3);+ return picked.length ? picked.map(({ r, k }) => (s.agent_ref_assets?.[k] ? `${ASSET_PREFIX}${s.agent_ref_assets[k]}` : r.image)) : undefined;+ };for (const [n, i] of missing.entries()) {job.progress = `re-running scene ${numberOf(i)} one by one (${n + 1}/${missing.length})`;if (numberOf(i) === stillFails && !job.params.agent_numbers) {@@ -1706,6 +1753,7 @@ export async function runAgentBatch(job: Job): Promise<string[]> {prompt: scenes[i],type: "image",max_credits: 0,+ reference_images: refsFor(i),aspect_ratio: s.aspect_ratio,download_quality: s.download_quality,output_dir: s.output_dir,@@ -1735,6 +1783,7 @@ export async function runAgentBatch(job: Job): Promise<string[]> {agentProblem ? `agent mode failed (${agentProblem}), so the images were made one by one` : "",agentTimedOut ? "the agent stalled and was stopped" : "",`${done.size} of ${scenes.length} scenes came from the agent`,+ s.agent_refs?.length ? `${s.agent_refs.length} reference image(s) attached` : "",agentRetries ? `${agentRetries} asked again` : "",failedTiles ? `${failedTiles} tile(s) failed in Flow` : "",missing.length > failed.length ? `${missing.length - failed.length} re-run one by one` : "",diff --git a/src/index.ts b/src/index.tsindex e90c426..3a149cb 100644--- a/src/index.ts+++ b/src/index.ts@@ -170,7 +170,7 @@ server.registerTool({title: "Fast image batch via Flow's agent",description:- "Hand up to 50 image scenes to Flow's own Agent mode, which renders them all in parallel (about a minute for a whole batch) and enriches each prompt itself. Images only, 0 credits. Less exact than flow_generate: the agent picks the wording, no techniques/reference images, and file order is best-effort. Use flow_generate when every scene needs exact settings. Returns a job id; use flow_wait.",+ "Hand up to 50 image scenes to Flow's own Agent mode, which renders them all in parallel (minutes for a whole batch instead of one paced job per scene) and enriches each prompt itself. Images only, 0 credits. Pass `references` (characters, places, objects, each with a short name) to attach them once in the agent's composer, the way its + button does, and `scene_references` to say which scenes use which, so a whole story stays on-model. Scenes the agent drops are asked for again, then made one by one with their references. Less exact than flow_generate: the agent picks the wording, no techniques, and each image is matched back to its scene by its stored prompt. Returns a job id; use flow_wait.",inputSchema: shapes.agent,annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },},diff --git a/src/queue.ts b/src/queue.tsindex ae8f00f..ef48c90 100644--- a/src/queue.ts+++ b/src/queue.ts@@ -21,6 +21,12 @@ export interface SceneParams {// The scene number each agent scene is saved as. A retry of scenes 7 and 12 keeps scene-07 and scene-12; without it// the numbers run on from file_stem.agent_numbers?: number[];+ // Reference images for an agent batch: attached once as ingredients in the agent composer (absolute paths, uploaded+ // once, or "asset:<title>"), with a short name each, plus which of them every scene uses (names, per scene).+ agent_refs?: { image: string; name: string }[];+ agent_scene_refs?: string[][];+ // Flow asset names of agent_refs after upload, so a retry round re-attaches without uploading again.+ agent_ref_assets?: string[];continue_from?: string;attach?: string[];continue_mode?: "exact" | "likeness";