π OpenHands: AI-Driven Development
bug: fix cache_control missing during convertion (#8692)
CoreJa0c2924453f04
diff --git a/openhands/llm/fn_call_converter.py b/openhands/llm/fn_call_converter.pyindex 14166814f3..35ae68b23e 100644--- a/openhands/llm/fn_call_converter.py+++ b/openhands/llm/fn_call_converter.py@@ -544,6 +544,8 @@ def convert_fncall_messages_to_non_fncall_messages(raise FunctionCallConversionError(f'Unexpected content type {type(content)}. Expected str or list. Content: {content}')+ if 'cache_control' in message:+ content[-1]['cache_control'] = {'type': 'ephemeral'}converted_messages.append({'role': 'user', 'content': content})else:raise FunctionCallConversionError(diff --git a/tests/unit/test_llm_fncall_converter.py b/tests/unit/test_llm_fncall_converter.pyindex 29cfd80840..a8a5d816fb 100644--- a/tests/unit/test_llm_fncall_converter.py+++ b/tests/unit/test_llm_fncall_converter.py@@ -944,3 +944,53 @@ def test_convert_from_multiple_tool_calls_no_tool_calls():input_messages)assert result == input_messages+++def test_convert_fncall_messages_with_cache_control():+ """Test that cache_control is properly handled in tool messages."""+ # Prepare test data+ messages = [+ {+ 'role': 'tool',+ 'name': 'test_tool',+ 'content': [{'type': 'text', 'text': 'test content'}],+ 'cache_control': {'type': 'ephemeral'},+ }+ ]++ # Call the function+ result = convert_fncall_messages_to_non_fncall_messages(messages, [])++ # Verify the result+ assert len(result) == 1+ assert result[0]['role'] == 'user'+ assert 'cache_control' in result[0]['content'][-1]+ assert result[0]['content'][-1]['cache_control'] == {'type': 'ephemeral'}+ assert (+ result[0]['content'][0]['text']+ == 'EXECUTION RESULT of [test_tool]:\ntest content'+ )+++def test_convert_fncall_messages_without_cache_control():+ """Test that tool messages without cache_control work as expected."""+ # Prepare test data+ messages = [+ {+ 'role': 'tool',+ 'name': 'test_tool',+ 'content': [{'type': 'text', 'text': 'test content'}],+ }+ ]++ # Call the function+ result = convert_fncall_messages_to_non_fncall_messages(messages, [])++ # Verify the result+ assert len(result) == 1+ assert result[0]['role'] == 'user'+ assert 'cache_control' not in result[0]['content'][-1]+ assert (+ result[0]['content'][0]['text']+ == 'EXECUTION RESULT of [test_tool]:\ntest content'+ )