Python Agents SDK 0.4.0 - compatibility with openai 2.x and new output types

A new release of Agents SDK was released, which, among other things, addresses 2 major issues:

  • It is now compatible with python openai package 2.x, allowing the usage of newer features like chatkit and sora (previously it was enforcing 1.109.x) . source
  • Agent tool calls are now compatible with the new output types, like images and files. source

In the PR there is an example on how to return an image to an agent:

FILEPATH = os.path.join(os.path.dirname(__file__), "media/image_bison.jpg")

def image_to_base64(image_path):
    with open(image_path, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
    return encoded_string

@function_tool
def fetch_random_image() -> ToolOutputImage | ToolOutputImageDict:
    """Fetch a random image."""

    print("Image tool called")
    b64_image = image_to_base64(FILEPATH)
    return {
        "type": "image",
        "image_url": f"data:image/jpeg;base64,{b64_image}",
        "detail": "auto",
    }
1 Like