Repository navigation
How should an agent save an image attached in a HumanMessage to the backend?
#7935
|
Hi! I'm trying to understand the expected way to let an agent save a user-attached image to the filesystem. I'm using My code takes the user's image, base64-encodes it, and sends it in a HumanMessage using the standard multimodal content blocks: HumanMessage(content=[
{"type": "text", "text": "Save this image to /images/photo.png"},
{"type": "image", "base64": b64_data, "mime_type": "image/png"},
])What happens: the agent can't find the image content anywhere in the filesystem, so it starts calling Is there an intended way for an agent to persist an image that arrived in a Can you help me understand please? (DA is the best!) |
Replies: 1 comment 1 reply
|
The image block gives the model image input; it does not, by itself, create For this use case, I would save the attachment in application code before invoking the agent. Decode A custom tool is useful if the agent should decide when to save it. Have the tool accept an The distinction with Current |

The image block gives the model image input; it does not, by itself, create
/images/photo.pnginyour backend. The filesystem tools therefore have no file at that path to find.
For this use case, I would save the attachment in application code before invoking the agent. Decode
your existing
b64_datato bytes, pass[("/images/photo.png", image_bytes)]to the same backendinstance's
upload_files, and check each returned response'serrorbefore telling the agent thefile is available. You can still include the image block if you want the model to see it directly.
With
FilesystemBackend(virtual_mode=True), that path is relative to its configured virtual root.A custom tool is useful if the ag…