Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/core/src/core/coreToolScheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -889,15 +889,22 @@ describe('convertToFunctionResponse', () => {
{ text: 'Another text part' },
];
const result = convertToFunctionResponse(toolName, callId, llmContent);
// All content should be inside the FunctionResponse:
// - text parts joined into response.output
// - media parts in response.parts
expect(result).toEqual([
{
functionResponse: {
name: toolName,
id: callId,
response: { output: 'Tool execution succeeded.' },
response: {
output: 'Some textual description\nAnother text part',
},
parts: [
{ inlineData: { mimeType: 'image/jpeg', data: 'base64data...' } },
],
},
},
...llmContent,
]);
});

Expand Down
26 changes: 20 additions & 6 deletions packages/core/src/core/coreToolScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,26 @@ export function convertToFunctionResponse(
}

if (Array.isArray(contentToProcess)) {
const functionResponse = createFunctionResponsePart(
callId,
toolName,
'Tool execution succeeded.',
);
return [functionResponse, ...toParts(contentToProcess)];
// Extract text and media from all parts so that EVERYTHING is inside
// the FunctionResponse.
const textParts: string[] = [];
const mediaParts: FunctionResponsePart[] = [];

for (const part of toParts(contentToProcess)) {
if (part.text !== undefined) {
textParts.push(part.text);
} else if (part.inlineData) {
mediaParts.push({ inlineData: part.inlineData });
} else if (part.fileData) {
mediaParts.push({ fileData: part.fileData });
}
// Other exotic part types (e.g. functionCall) are intentionally
// dropped here – they should not appear inside tool results.
}

const output =
textParts.length > 0 ? textParts.join('\n') : 'Tool execution succeeded.';
return [createFunctionResponsePart(callId, toolName, output, mediaParts)];
}

// After this point, contentToProcess is a single Part object.
Expand Down
Loading