Skip to main content

What This Feature Unlocks

Returning images and files from the tools enables real agentic feedback loops on completely new modalities. For example, instead of dumping all the data into an agent, and hoping for the best, you can generate a visualization or analyze PDF reports, and allow the agent to provide insights based on that output. Just like a real data analyst. This saves your context window and unlocks autonomous agentic workflows for a lot of new use cases:

New Use Cases

Software Development

Agents can check websites autonomously and iterate until all elements are properly positioned, enabling them to tackle complex projects without manual screenshot feedback.

Brand Asset Generation

Provide brand guidelines, logos, and messaging, then let agents iterate on image and video generation (including Sora 2) until outputs fully match your expectations.

Screen-Aware Assistance

Build agents that help visually impaired individuals navigate websites or create customer support agents that see the user’s current webpage for better assistance.

Data Analytics

Generate visual graphs and analyze PDF reports, then let agents provide insights based on these outputs without overloading the context window.

Output Formats

Images (PNG, JPG)

To return an image from a tool, you can either:
  1. Use the ToolOutputImage class.
  2. Return a dict with the type set to "image" and either image_url (URL or data URL) or file_id.
  3. Use our convenience tool_output_image_from_path function.

Files (PDF)

Similarly to return a file from a tool:
When you choose file_data, include filename to hint a download name; URL-based outputs rely on the remote server metadata instead.
tool_output_file_from_path only supports PDF files.
Need to load local files without custom logic? Use the built-in LoadFileAttachment tool instead of creating a custom tool. It handles both images and PDFs and uses these same utility functions under the hood.

Combining Multiple Outputs

Return multiple outputs by returning a list from run.

Complete Example (Chart generation tool)

Here’s a complete example using BaseTool:
function_tool decorators and BaseTool classes both support multimodal outputs in the exact same way.

Tips & Best Practices

  • Base64-encoded images can be large. Use file references for large content.
  • Compress screenshots and other visuals before returning them to cut token usage without sacrificing clarity.
  • Include the image names in your textual response whenever you return more than one image so the agent can reference them unambiguously.

Real Examples