Skip to content
Open
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
5 changes: 2 additions & 3 deletions packages/core/src/core/coreToolScheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,9 @@ describe('convertToFunctionResponse', () => {
functionResponse: {
name: toolName,
id: callId,
response: { output: 'Tool execution succeeded.' },
response: { output: 'Some textual descriptionAnother text part' },
},
},
...llmContent,
]);
});

Expand Down Expand Up @@ -656,7 +655,7 @@ describe('convertToFunctionResponse', () => {
functionResponse: {
name: toolName,
id: callId,
response: { output: 'Tool execution succeeded.' },
response: { output: '' },
},
},
]);
Expand Down
26 changes: 8 additions & 18 deletions packages/core/src/core/coreToolScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import type { Part, PartListUnion } from '@google/genai';
import { getResponseTextFromParts } from '../utils/generateContentResponseUtilities.js';
import type { ModifyContext } from '../tools/modifiable-tool.js';
import { partToString } from '../utils/partUtils.js';
import {
isModifiableDeclarativeTool,
modifyWithEditor,
Expand Down Expand Up @@ -174,12 +175,13 @@ export function convertToFunctionResponse(
}

if (Array.isArray(contentToProcess)) {
const functionResponse = createFunctionResponsePart(
callId,
toolName,
'Tool execution succeeded.',
);
return [functionResponse, ...toParts(contentToProcess)];
return [
createFunctionResponsePart(
callId,
toolName,
partToString(contentToProcess),
),
];
}

// After this point, contentToProcess is a single Part object.
Expand Down Expand Up @@ -220,18 +222,6 @@ export function convertToFunctionResponse(
];
}

function toParts(input: PartListUnion): Part[] {
const parts: Part[] = [];
for (const part of Array.isArray(input) ? input : [input]) {
if (typeof part === 'string') {
parts.push({ text: part });
} else if (part) {
parts.push(part);
}
}
return parts;
}

const createErrorResponse = (
request: ToolCallRequestInfo,
error: Error,
Expand Down
Loading