Fix issue #8369: Handle invalid arguments in model tool calls (#8370)

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
This commit is contained in:
Xingyao Wang
2025-05-09 22:11:05 +08:00
committed by GitHub
parent b6c5a7e854
commit f8faa28bb1
6 changed files with 114 additions and 4 deletions

View File

@@ -163,11 +163,29 @@ def response_to_actions(
if 'view_range' in other_kwargs:
# Remove view_range from other_kwargs since it is not needed for FileEditAction
other_kwargs.pop('view_range')
# Filter out unexpected arguments
valid_kwargs = {}
# Get valid parameters from the str_replace_editor tool definition
str_replace_editor_tool = create_str_replace_editor_tool()
valid_params = set(
str_replace_editor_tool['function']['parameters'][
'properties'
].keys()
)
for key, value in other_kwargs.items():
if key in valid_params:
valid_kwargs[key] = value
else:
raise FunctionCallValidationError(
f'Unexpected argument {key} in tool call {tool_call.function.name}. Allowed arguments are: {valid_params}'
)
action = FileEditAction(
path=path,
command=command,
impl_source=FileEditSource.OH_ACI,
**other_kwargs,
**valid_kwargs,
)
# ================================================
# AgentThinkAction