Skip to content

How to handle cases when function tool returns an image #2256

@Anurag-gg

Description

@Anurag-gg

Please read this first

  • Have you read the docs?Agents SDK docs - Yes
  • Have you searched for related issues? Others may have had similar requests - Yes

Question

def foo(a):
    '''Test function foo'''
    return {ToolOutputImage(image_url="https://tinyurl.com/3ut4a4fn")}

the docs talks about Returning images or files from function tools using ToolOutputImage. When I do this, the LLM(gemini) is unable to read the image.
This is my workflow

client = AsyncOpenAI(
    base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
    api_key=GEMINI_API_KEY
)

set_default_openai_client(client)
set_tracing_disabled(True)

# Define the Model
model = OpenAIChatCompletionsModel(
    model="gemini-2.5-flash",
    openai_client=client
)

# Create the Agent with Tools
stock_analysis_agent = Agent(
    name="TestAgent",
    instructions="You are a helpful agent",
    tools=[function_tool(foo), function_tool(foo2), function_tool(foo3)],
    model=model
)


async def main(prompt):
    result = await Runner.run(stock_analysis_agent, prompt)
    return result.final_output

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion about using the SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions