Repository navigation
Description
Summary
Generating an image in chat sometimes ends in a failed generate_image step whose result has the status invalid_args (the step reads "Couldn't run as asked"). It was reported on 2026-11-04 as rare, for the image model the report calls "Gemini 3.8 Flash Image Lite". For #5358 the reporter confirmed that this name means gemini-3.1-flash-image on an OpenAI-compatible Bifrost gateway. The report came with a question: do image models differ in the arguments they take, so that the chat model gets confused? No thread, message or error text is available, and the failure was not reproduced.
Several checks answer invalid_args for this tool, and the result's message says which one refused. From the code alone, the likeliest one is the refusal of a picture. Tale reads gemini-3.1-flash-image on a gateway as a model that takes no picture, but the chat tool offers pictures whatever the image model is. A change on train (below) now builds the tool for the turn's image model. The other sources are untouched. One of them, arguments that do not parse, leaves no record of what the model sent.
What the code does today (main 7d7b1ee98)
Where invalid_args can come from for one generate_image call in chat, by the message it carries:
| Source | message (abridged) |
Anchor |
|---|---|---|
| The arguments do not parse as JSON | "The arguments of generate_image were not valid JSON. Send them again as one JSON object." | services/platform/backend/domains/agent_tools/executor.ts:110-115. The raw text is kept as rawInput only when JSON.parse fails (services/platform/backend/core/chat/turn_action.ts:211-222) |
| The reply cap ended the round | "The arguments were cut by the reply cap …", or "The reply cap … ended this round right after these arguments were complete; the call was withheld …". Given to every call of a round that finished with length |
services/platform/lib/chat/turn.ts:1172-1193, applied at :2063-2073 |
| More than 16 calls in one round | "Too many tool calls in one step (at most 16 run) …" | services/platform/lib/chat/tool-batch.ts:42-47 |
| The tool's argument checks | The arguments are not an object (for example a JSON-encoded string). An empty prompt, which is also what arguments that arrive empty get, because they are read as {} (turn_action.ts:208-209). A prompt over 4,000 characters. A size other than square, landscape, portrait, WxH or W:H (for example auto). A count that is not a whole number from 1 to 4. inputImages that are not a list, or more than 4 of them |
services/platform/backend/domains/agent_tools/image.ts:55-103; readImageSize in services/platform/backend/core/lib/providers/image_wire.ts |
| The image model takes no picture | "The image model … cannot start from an image. Describe the picture in the prompt instead." | image.ts:143-148 |
| The image model's catalog limits | "… takes at most N reference images in one call …", or "… edits pictures and needs at least N reference images in every call …" | image.ts:149-150, services/platform/backend/core/lib/providers/image_generation.ts:219-237 |
| The reference files | A file larger than 4 MB, more than 16 MB together, or a file that is not a PNG, JPEG or WebP image | image.ts:163-187 |
What bears on the reported model:
- Take a gateway listing row that describes nothing, for a model that no catalog shipped with Tale knows. Tale reads it as an image generator by its id, with
supportsVisionfalse (services/platform/lib/shared/providers/catalog_normalize.ts:343-363).- No shipped catalog (
configs/platform/system/models/*/models.yml) namesgemini-3.1-flash-image. - So the resolved image model has
acceptsImageInput: false(services/platform/backend/core/lib/providers/resolve_image_model.ts:383), and a call with anyinputImagesgets the "cannot start from an image" refusal.
- No shipped catalog (
- In the 2026-11-04 check, the gateway's Images API answered 404 for this model, and Tale fell back to drawing over chat completions. Whether the model takes a picture there was not checked. OpenRouter's image catalog lists its Gemini image models with up to 3 reference images (checked 2026-10-27).
- The chat tool's schema and description are the same for every image model:
inputImages, at most 4, "to edit or take as reference, as many as the image model takes" (services/platform/lib/agent/work-tools.ts:162-193; the description is at:298-304).- The executor builds the tool without the image model (
executor.ts:102,work-tools.ts:418-431). - So nothing tells the chat model that this image model takes no picture until the refusal does.
- The executor builds the tool without the image model (
- A failed
invalid_argsstep is hidden when a later call of the same tool in the turn succeeded (services/platform/app/features/chat/components/thought-timeline.tsx:227-268). A step that stays visible is one the model did not recover from within the turn, which fits a rare report. - Expanding the step shows the call's input and the whole result as JSON, its
messageincluded (thought-timeline.tsx:321-339). - The transcript keeps a call's parsed
inputonly (services/platform/lib/chat/turn.ts:1971-1977).- For arguments that do not parse, that input is
{}. The raw text is neither stored nor logged on this path, and the work tools' refusal does not quote it. - The assistant's own tools quote its first 200 characters (
services/platform/backend/core/chat/assistant_tools.ts:934-938).
- For arguments that do not parse, that input is
The change on train
cd4a12c (fix(platform): offer an image model only the pictures it takes) goes to main with the next train. It builds generate_image for the turn's image model:
- An image model that takes no picture. The tool offers no
inputImages. Its description says the model draws from the prompt alone and cannot edit a picture, and that a person who wants a picture changed is told it can only draw a new one. - An image model that takes pictures. The tool offers at most the catalog's maximum, capped at Tale's 4.
- A catalog minimum above 0. The schema adds
minItemsand makesinputImagesrequired, and the description says every call needs a picture. - The stated range can always be met: the minimum never exceeds the maximum.
- The tests are in
services/platform/lib/agent/work-tools.test.tsandservices/platform/backend/domains/agent_tools/executor.test.ts.
It closes the picture refusals only as far as the chat model follows its tool's schema. It was not checked against the reported deployment, and the other sources are unchanged.
Not covered
- Task runs in a workspace. The harness bridge's image tool keeps one description for every image model ("when the model accepts images and as many as it takes",
services/platform/backend/core/node_only/sandbox/workspace_image_tool.ts:110-131), and it refuses the same way (:683-692). See Improvement: knowledge search and image generation exist twice, once for chat and shared-engine task runs and once for the harness bridge #4875. - Editing with a gateway image model Tale cannot describe. Such a model takes no picture, even when the vendor's model edits. With the change on
train, chat no longer offers it pictures, so a request to change an image gets a new picture drawn from the prompt. - Arguments that do not parse. What the model sent is lost (see above).
What would settle it
- The
messageof a failed step (expand the step), or the thread, so that its stored tool result can be read. - The chat model that wrote the call, and whether the conversation held an uploaded or a generated image at the time.
- For "not valid JSON": the raw arguments. Today they take a logging proxy between Tale and the gateway, or option 1.
Options (no preference)
- Keep the raw text of arguments that did not parse, bounded, with the tool-call part or in the server log.
- Quote the start of that raw text in the work tools' refusal, as the assistant's own tools do, so that the model sees what it sent.
- Describe gateway image models that Tale cannot read from the listing. Possible sources: a fact an admin sets (takes pictures, how many), shipped catalog entries for known gateway ids such as
gemini-3.1-flash-image, or the vendor's facts looked up by the id. - Write the bridge tool's description for the turn's image model as well.
- Narrow
sizein the schema (anenumof the named sizes, or apattern), if the messages show sizes Tale cannot read. Providers differ in which schema keywords they honour.
Questions
- Should a gateway image model that Tale cannot describe be offered pictures, at the risk that a provider refuses them, or not, at the cost of editing?
Related
- bug(platform): a generated image can show twice in chat, once as a broken placeholder — the model writes the image's s3: ref as Markdown #5358 and bug(platform): a chat image's preview breaks after 15 minutes — the page keeps presigned links past their lifetime #5366: the same image model in chat.
- Improvement: knowledge search and image generation exist twice, once for chat and shared-engine task runs and once for the harness bridge #4875: the two image tools.
- Epic Epic: findings checked on main 2026-11-04 — chat follow-ups, generated images, chat-to-task hand-over, organizations, sandbox errors, agents in chats #5367.
Activity
fix(platform): offer an image model only the pictures it takes
fix(platform): offer an image model only the pictures it takes