[Python] How to let a tool return a picture when using langgraph/langchain?

Discussão em 'Python' iniciado por Stack, Abril 24, 2025.

  1. Stack

    Stack Membro Participativo

    I am using a LLM model which is capable of processing images.

    When the LLM calls "get_screenshot" tool, I want to provide a screenshot of a website to it.

    For example:

    from langchain_core.tools import tool

    def do_screenshoot_and_save_it_to_local_disk():
    # Pretend that this function will take a screenshot and return the path of the image.
    return "/path/to/pic.png"

    @tool
    def get_screenshot():
    picture_path = do_screenshoot_and_save_it_to_local_disk()
    return ??? # What should I return?


    How to implement it? Or, is it impossible to let a tool return a picture when using langgraph/langchain?

    Or, when a function is decorated with @tool, what types of return values are allowed? Obviously, returning a str is useless.

    Continue reading...

Compartilhe esta Página