Skip to content

πŸ™Œ OpenHands: AI-Driven Development

feat: make add_in_context_learning_example configurable in fn call converter (#5018)

Xingyao Wang5b3db1bd3321
diff --git a/openhands/llm/fn_call_converter.py b/openhands/llm/fn_call_converter.py
index da595ec4f3..5ddbcb3050 100644
--- a/openhands/llm/fn_call_converter.py
+++ b/openhands/llm/fn_call_converter.py
@@ -307,6 +307,7 @@ def convert_tools_to_description(tools: list[dict]) -> str:
def convert_fncall_messages_to_non_fncall_messages(
messages: list[dict],
tools: list[ChatCompletionToolParam],
+ add_in_context_learning_example: bool = True,
) -> list[dict]:
"""Convert function calling messages to non-function calling messages."""
messages = copy.deepcopy(messages)
@@ -341,7 +342,7 @@ def convert_fncall_messages_to_non_fncall_messages(
# 2. USER MESSAGES (no change)
elif role == 'user':
# Add in-context learning example for the first user message
- if not first_user_message_encountered:
+ if not first_user_message_encountered and add_in_context_learning_example:
first_user_message_encountered = True
# Check tools
if not (
@@ -751,6 +752,7 @@ def convert_non_fncall_messages_to_fncall_messages(
def convert_from_multiple_tool_calls_to_single_tool_call_messages(
messages: list[dict],
+ ignore_final_tool_result: bool = False,
) -> list[dict]:
"""Break one message with multiple tool calls into multiple messages."""
converted_messages = []
@@ -787,7 +789,7 @@ def convert_from_multiple_tool_calls_to_single_tool_call_messages(
), f'Found pending tool calls but not expect to handle it with role {role}: {pending_tool_calls=}, {message=}'
converted_messages.append(message)
- if len(pending_tool_calls) > 0:
+ if not ignore_final_tool_result and len(pending_tool_calls) > 0:
raise FunctionCallConversionError(
f'Found pending tool calls but no tool result: {pending_tool_calls=}'
)