Problem solved at
https://github.com/langchain-ai/langgraph/discussions/4384
import base64
from langchain_core.tools import tool
def image_to_base64(image_path: str) -> str:
with open(image_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
return encoded_string.decode('utf-8')
def do_screenshot_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_screenshot_and_save_it_to_local_disk()
return [
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image_to_base64(picture_path)}"}}
]