Industry observers note that you hypocrite, first take the log out of your own eye, and then you will see clearly to take the speck out of your brother's eye. Matthew 7, 3-5.

We have added vision support to smolagents, which unlocks the use of vision language models in agentic pipelines natively.

In the agentic world, many capabilities are hidden behind a vision wall. A common example is web browsing: web pages feature rich visual content that you never fully recover by simply extracting their text, be it the relative position of objects, messages transmitted through color, specific icons… In this case, vision is a real superpower for agents. So we just added this capability to our smolagents! (Related: Tiny Agents: an MCP-powered agent in 50 lines of code...)

Teaser of what this gives: an agentic browser that navigates the web in complete autonomy!

Here's an example of what it looks like:.

🤔 How do we want to pass images to agents? Passing an image can be done in two ways:.

For the case where we want to pass images at once, we added the possibility to pass a list of images to the agent in the run method: agent.run("Describe these images:", images=[image_1, image_2]) . (Related: Aligning to What? Rethinking Agent Generalization in Mi...)

These image inputs are then stored in the task_images attribute of TaskStep along with the prompt of the task that you'd like to accomplish.

Recent findings suggest that when running the agent, they will be passed to the model. This comes in handy with cases like taking actions based on long PDFs that include visual elements.

How to dynamically add images into the agent’s memory?

To find out, we first need to understand how our agents work.

All agents in smolagents are based on the singular MultiStepAgent class, which is an abstraction of the ReAct framework. On a basic level, this class performs actions on a cycle of following steps, where existing variables and knowledge are incorporated into the agent logs as follows:.

The figure below details this process:.

As you can see, for use cases where images are dynamically retrieved (e.g. web browser agent), we support adding images to the model’s ActionStep, in attribute step_log.observation_images.

This can be done via a callback, which will be run at the end of each step.

Let's demonstrate how to make such a callback, and using it to build a web browser agent.👇👇.

We’re going to use helium. It provides browser automations based on selenium: this will be an easier way for our agent to manipulate webpages.

According to recent reports, the agent itself can use helium directly, so no need for specific tools: it can directly use helium to perform actions, such as click("top 10") to click the button named "top 10" visible on the page. We still have to make some tools to help the agent navigate the web: a tool to go back to the previous page, and another tool to close pop-ups, because these are quite hard to grab for helium since they don’t have any text on their close buttons.

Industry observers note that for now, the agent has no visual input. So let us demonstrate how to dynamically feed it images in its step logs by using a callback. We make a callback save_screenshot that will be run at the end of each step.

The most vital line here is when we add the image in our observations images: step_log.observations_images = [image.copy()].

Recent findings suggest that this callback accepts both the step_log, and the agent itself as arguments. Having agent as an input allows to perform deeper operations than just modifying the last logs.

Let's make a model. We've added support for images in all models. Just one precision: when using TransformersModel with a VLM, for it to work properly you need to pass flatten_messages_as_text as False upon initialization, like:.

For this demo, let's use a bigger Qwen2VL via Fireworks API:.

Sources indicate that now let’s move on to defining our agent. We set the highest verbosity_level to display the LLM’s full output messages to view its thoughts, and we increased max_steps to 20 to give the agent more steps to explore the web. We also provide it with our callback save_screenshot defined above.

Finally, we provide our agent with some guidance about using helium.

Now everything's ready: Let’s run our agent!

Recent findings suggest that note, however, that this task is really hard: depending on the VLM that you use, this might not always work. Strong VLMs like Qwen2VL-72B or GPT-4o succeed more often.

This will give you a glimpse of the capabilities of a vision-enabled CodeAgent, but there’s much more to do!

We are looking forward to seeing what you will build with vision language models and smolagents!

Note: for the modal closing selectors please note that modals are also known as dialog elements and if built robustly should have a role="dialog" attribute in this is something that can be searched for when identifying these pop up windows.

In addition, any dialog/modal window should be closeable via the escape key as well!

Hope this helps identify modals/dialogs in a broader sense and/or helps close them out easier!

related code chunk from above for reference :).

Oh that's a great point, thanks a lot! Putting this to good use!

If you have the power to do it. then:HELP! HELP! HELP! https://arxiv.org/auth/endorse?x=VMBF4S.

Hm, what happened to the Agentic Web Browser sample? @m-ric https://github.com/huggingface/smolagents/blob/main/examples/vlm_web_browser.py.

We integrated it in the main repo here: https://github.com/huggingface/smolagents/blob/main/src/smolagents/vision_web_browser.pyThus it was removed from examples/.

According to recent reports, I'm getting this deprecation warning "The 'logs' attribute is deprecated and will soon be removed. Please use 'self.memory.steps' instead." What action should be taken?

→ Read original article