u
This commit is contained in:
@@ -102,3 +102,54 @@ test('LLMOrbiter finishes immediately in 1 iteration when content is returned wi
|
||||
assert.equal(result.iterations, 1);
|
||||
assert.equal(result.content, 'Hello there!');
|
||||
});
|
||||
|
||||
test('LLMOrbiter calls onToolResult before onUsage in a tool-calling iteration', async () => {
|
||||
const events = [];
|
||||
const testTool = defineTool({
|
||||
name: 'test_tool',
|
||||
description: 'Test tool',
|
||||
parameters: { type: 'object', properties: {} },
|
||||
invoke: async () => {
|
||||
return { ok: true, data: 42 };
|
||||
},
|
||||
});
|
||||
|
||||
const mock = new MockProvider([
|
||||
{
|
||||
tool_calls: [
|
||||
{
|
||||
id: 'call_1',
|
||||
type: 'function',
|
||||
function: { name: 'test_tool', arguments: '{}' },
|
||||
},
|
||||
],
|
||||
content: null,
|
||||
usage: { prompt_tokens: 10, completion_tokens: 5 },
|
||||
},
|
||||
{
|
||||
tool_calls: undefined,
|
||||
content: 'All done.',
|
||||
usage: { prompt_tokens: 20, completion_tokens: 8 },
|
||||
},
|
||||
]);
|
||||
|
||||
const orbiter = new LLMOrbiter(mock, {
|
||||
onToolCall: ({ name }) => events.push(`tool_call:${name}`),
|
||||
onToolResult: ({ name }) => events.push(`tool_result:${name}`),
|
||||
onUsage: (u) => events.push(`usage:${u.input}:${u.output}`),
|
||||
});
|
||||
|
||||
const result = await orbiter.run({
|
||||
prompt: 'Run tool',
|
||||
tools: [testTool],
|
||||
});
|
||||
|
||||
assert.equal(result.content, 'All done.');
|
||||
assert.deepEqual(events, [
|
||||
'tool_call:test_tool',
|
||||
'tool_result:test_tool',
|
||||
'usage:10:5',
|
||||
'usage:20:8',
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user