Skip to content

Commit e927512

Browse files
committed
Add aibot test coverage for handling multiple tool calls in one response
1 parent c7a2bd6 commit e927512

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

packages/ai-bot/tests/responding-test.ts

+108
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,112 @@ module('Responding', (hooks) => {
425425
'The replacement event with the tool call event should replace the original message',
426426
);
427427
});
428+
429+
test.only('Handles multiple tool calls', async () => {
430+
const weatherCheck1Args = {
431+
description: 'Check the weather in NYC',
432+
attributes: {
433+
zipCode: '10011',
434+
},
435+
};
436+
const weatherCheck2Args = {
437+
description: 'Check the weather in Beverly Hills',
438+
attributes: {
439+
zipCode: '90210',
440+
},
441+
};
442+
await responder.initialize();
443+
444+
await responder.onChunk({} as any, snapshotWithContent('some content'));
445+
446+
let snapshot = {
447+
choices: [
448+
{
449+
message: {
450+
tool_calls: [
451+
{
452+
id: 'tool-call-1-id',
453+
type: 'function' as 'function',
454+
function: {
455+
name: 'checkWeather',
456+
arguments: JSON.stringify(weatherCheck1Args),
457+
},
458+
},
459+
{
460+
id: 'tool-call-2-id',
461+
type: 'function' as 'function',
462+
function: {
463+
name: 'checkWeather',
464+
arguments: JSON.stringify(weatherCheck2Args),
465+
},
466+
},
467+
],
468+
},
469+
finish_reason: null,
470+
logprobs: null,
471+
index: 0,
472+
},
473+
],
474+
id: '',
475+
created: 0,
476+
model: 'llm',
477+
};
478+
await responder.onChunk({} as any, snapshot);
479+
480+
await responder.finalize();
481+
482+
let sentEvents = fakeMatrixClient.getSentEvents();
483+
assert.equal(
484+
sentEvents.length,
485+
3,
486+
'Thinking message, and event with content, and event with two tool calls should be sent',
487+
);
488+
assert.equal(
489+
sentEvents[0].content.body,
490+
thinkingMessage,
491+
'Thinking message should be sent first',
492+
);
493+
assert.deepEqual(
494+
sentEvents[2].content[APP_BOXEL_COMMAND_REQUESTS_KEY],
495+
[
496+
{
497+
id: 'tool-call-1-id',
498+
name: 'checkWeather',
499+
arguments: {
500+
description: 'Check the weather in NYC',
501+
attributes: {
502+
zipCode: '10011',
503+
},
504+
},
505+
},
506+
{
507+
id: 'tool-call-2-id',
508+
name: 'checkWeather',
509+
arguments: {
510+
description: 'Check the weather in Beverly Hills',
511+
attributes: {
512+
zipCode: '90210',
513+
},
514+
},
515+
},
516+
],
517+
'Command requests should be sent with correct content',
518+
);
519+
assert.deepEqual(
520+
sentEvents[1].content['m.relates_to'],
521+
{
522+
rel_type: 'm.replace',
523+
event_id: '0',
524+
},
525+
'The replacement event with content should replace the original message',
526+
);
527+
assert.deepEqual(
528+
sentEvents[2].content['m.relates_to'],
529+
{
530+
rel_type: 'm.replace',
531+
event_id: '0',
532+
},
533+
'The replacement event with the tool calls should replace the original message',
534+
);
535+
});
428536
});

0 commit comments

Comments
 (0)