This commit is contained in:
seb
2026-10-05 22:27:20 +02:00
parent 7d55b9774a
commit 4b4b03172a
5 changed files with 229 additions and 18 deletions

View File

@@ -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',
]);
});