fix: preserve adjacent inline data: URIs in OpenAPI tool results

process_tool_result() iterated over tool_result while calling
tool_result.remove(item) inside the loop. list.remove() shifts every
later element down by one, so the iterator skipped the item immediately
after each extracted data: URI. When an OpenAPI tool returned two or more
adjacent inline data: URIs, only the first became an attachment; the
second survived into the text payload and was json.dumps()'d into the
model context as a raw base64 blob.

Collect the non-data items into a new list and assign back in place
instead of mutating during iteration.
This commit is contained in:
jaideeppyne 2026-08-13 08:41:42 +05:30
parent 90bb94abf9
commit aae99ff6f3

View file

@ -1049,6 +1049,7 @@ async def process_tool_result(
tool_response.append(resource.get('uri'))
tool_result = tool_response[0] if len(tool_response) == 1 else tool_response
else: # OpenAPI
kept_items = []
for item in tool_result:
if isinstance(item, str) and item.startswith('data:'):
tool_result_files.append(
@ -1057,7 +1058,9 @@ async def process_tool_result(
'content': item,
}
)
tool_result.remove(item)
else:
kept_items.append(item)
tool_result[:] = kept_items
if isinstance(tool_result, list):
tool_result = {'results': tool_result}