Bug Fix: KeyError when agent reaches max steps with image input by robin-ede · Pull Request #1525 · huggingface/smolagents (original) (raw)

Problem

When an agent reaches max steps with image input, a KeyError occurs because the error handling in provide_final_answer returns a plain string instead of the expected list
format. This causes models.py to fail when trying to pop("image") from the message content.

Solution

Changed the error message format in agents.py:826 from a plain string to a properly structured list with type annotation, matching the expected ChatMessage content format.

Testing

Fixes #1524