From 5b48aee0c96780d0643aaf1aa3b1ef1414e41b64 Mon Sep 17 00:00:00 2001 From: Tommaso Bendinelli <43389342+TommasoBendinelli@users.noreply.github.com> Date: Mon, 23 Jun 2025 18:01:36 +0200 Subject: [PATCH] Fix openhands.core.exceptions.FunctionCallConversionError `fn_call_converter` for GPT-o4-mini when the agent generates images (#9152) Co-authored-by: tommaso --- openhands/llm/fn_call_converter.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/openhands/llm/fn_call_converter.py b/openhands/llm/fn_call_converter.py index 64f67cf086..73eba911c6 100644 --- a/openhands/llm/fn_call_converter.py +++ b/openhands/llm/fn_call_converter.py @@ -794,17 +794,19 @@ def convert_non_fncall_messages_to_fncall_messages( ) if tool_result_match: - if not ( - isinstance(content, str) - or ( - isinstance(content, list) - and len(content) == 1 - and content[0].get('type') == 'text' - ) - ): + if isinstance(content, list): + text_content_items = [ + item for item in content if item.get('type') == 'text' + ] + if not text_content_items: + raise FunctionCallConversionError( + f'Could not find text content in message with tool result. Content: {content}' + ) + elif not isinstance(content, str): raise FunctionCallConversionError( - f'Expected str or list with one text item when tool result is present in the message. Content: {content}' + f'Unexpected content type {type(content)}. Expected str or list. Content: {content}' ) + tool_name = tool_result_match.group(1) tool_result = tool_result_match.group(2).strip()