This commit is contained in:
Timothy Jaeryang Baek committed 2026-11-09 08:05:51 +09:00
1 parent 227287b3b5
commit d612241790
3 files changed
+13 -10

No files matched your search

+6 -3
View File
@@ -93,12 +93,13 @@ def stage_ask_user_tool_calls(
for tool_call in ask_user_calls:
call_id = tool_call.get('id') or make_output_id('fc')
raw_arguments = tool_call.get('function', {}).get('arguments', '{}')
arguments = raw_arguments
function = tool_call.get('function', {})
arguments = function.get('arguments', '{}')
original_arguments = function.get('original_arguments', arguments)
if not error:
try:
parsed_arguments = JSONCodec.loads(raw_arguments or '{}')
parsed_arguments = JSONCodec.loads(arguments or '{}')
if not isinstance(parsed_arguments, dict):
raise ValueError('ask_user arguments must be an object.')
arguments = JSONCodec.dumps(normalize_ask_user_request(parsed_arguments))
@@ -131,6 +132,8 @@ def stage_ask_user_tool_calls(
),
None,
)
if arguments != original_arguments:
item['original_arguments'] = (existing_item or {}).get('original_arguments', original_arguments)
if existing_item:
existing_item.update(item)
else:
+3 -3
View File
@@ -349,14 +349,14 @@ def get_provider_function(item: dict) -> dict:
function = dict(function)
if 'original_arguments' in function:
function['arguments'] = function['original_arguments']
raw_arguments = function.get('arguments')
original_arguments = function.get('arguments')
if error := prepare_tool_call(function):
function['arguments'] = JSONCodec.dumps({'error': error})
else:
try:
# A valid JSON object goes back as the model wrote it, so its cached output still matches.
if isinstance(JSONCodec.loads(raw_arguments), dict):
function['arguments'] = raw_arguments
if isinstance(JSONCodec.loads(original_arguments), dict):
function['arguments'] = original_arguments
except (TypeError, ValueError):
pass
return {
+4 -4
View File
@@ -293,9 +293,9 @@ def tool_repetition_error(call, previous_calls):
def prepare_tool_call(call, schema=None, *, display_labels=False, approval_review=False):
"""Normalize a call before approval; return an actionable error for the model."""
raw = call.get('arguments', '{}')
original_arguments = call.get('arguments', '{}')
try:
arguments = dict(parse_arguments(raw))
arguments = dict(parse_arguments(original_arguments))
if display_labels and '__labels__' in arguments:
labels = arguments.pop('__labels__')
call.pop('display_labels', None)
@@ -312,8 +312,8 @@ def prepare_tool_call(call, schema=None, *, display_labels=False, approval_revie
except ValueError as exc:
return f'Error: {exc} Correct the arguments before retrying.'
normalized = json.dumps(arguments, ensure_ascii=False)
if normalized != raw:
call.setdefault('original_arguments', raw)
if normalized != original_arguments:
call.setdefault('original_arguments', original_arguments)
call['arguments'] = normalized
return None