-
Notifications
You must be signed in to change notification settings - Fork 9
Description
When using the Conversations API with the image_generation built-in tool, the API response includes tool_file entries in the message.output content array containing the generated image's file_id. However, Response::updateFromArray() only handles text and tool_reference content types — tool_file entries are silently dropped.
This makes it impossible to retrieve the file ID of generated images through the high-level conversation client.
Expected API response structure
When the image_generation tool executes, the conversation response contains an output like:
{
"type": "message.output",
"content": [
{"type": "text", "text": "Here is the generated image."},
{"type": "tool_file", "file_id": "xxx", "file_type": "png", "file_name": "image.png"}
]
}
The text part is captured, but the tool_file part is lost.
Suggested fix
Add tool_file handling alongside the existing tool_reference case:
if($content['type'] === 'tool_file'){
$message->addReference($content);
}
This stores tool_file entries in the message's references array (same as tool_reference), making the file_id accessible via $response->getReferences(). The file can then be downloaded with MistralClient::downloadFile($fileId).
Context
This is needed for integrating Mistral image generation into the Drupal AI Provider: Mistral module. Ref: https://docs.mistral.ai/agents/tools/built-in/image_generation