fix: parse tagged local-model tool calls
This commit is contained in:
@@ -150,3 +150,43 @@ test('scheduled presence cannot create pending mutating actions', async () => {
|
||||
assert.equal(result.trace[0].status, 'rejected');
|
||||
assert.equal(executions, 0);
|
||||
});
|
||||
|
||||
test('ChatML-style tagged tool calls are executed without leaking protocol text', async () => {
|
||||
const calls = [];
|
||||
let responseIndex = 0;
|
||||
const responses = [
|
||||
'<|tool_call>call:get_evidence{query:"Russia planned attack military escalation",limit:5}<tool_call|>',
|
||||
JSON.stringify({ type: 'final', answer: 'The retrieved evidence does not confirm a specific planned attack.', confidence: 'medium', evidence: ['evt-russia'], notify: false, priority: 'routine' }),
|
||||
];
|
||||
const agent = new TerminalAgent({
|
||||
provider: {
|
||||
isConfigured: true,
|
||||
async complete() { return { text: responses[responseIndex++] }; },
|
||||
},
|
||||
registry: new TerminalToolRegistry([{
|
||||
name: 'get_evidence',
|
||||
handler: async args => { calls.push(args); return [{ id: 'evt-russia' }]; },
|
||||
}]),
|
||||
});
|
||||
|
||||
const result = await agent.run('Wie sieht es mit dem angeblich geplanten Angriff von Russland aus?');
|
||||
assert.deepEqual(calls, [{ query: 'Russia planned attack military escalation', limit: 5 }]);
|
||||
assert.equal(result.trace[0].tool, 'get_evidence');
|
||||
assert.doesNotMatch(result.answer, /tool_call|call:get_evidence/i);
|
||||
});
|
||||
|
||||
test('malformed tagged protocol is repaired instead of returned to the user', async () => {
|
||||
let responseIndex = 0;
|
||||
const responses = [
|
||||
'<|tool_call>call:get_evidence{broken arguments}<tool_call|>',
|
||||
JSON.stringify({ type: 'final', answer: 'I could not run the malformed tool request.', confidence: 'low', evidence: [], notify: false, priority: 'routine' }),
|
||||
];
|
||||
const agent = new TerminalAgent({
|
||||
provider: { isConfigured: true, async complete() { return { text: responses[responseIndex++] }; } },
|
||||
registry: new TerminalToolRegistry([]),
|
||||
});
|
||||
|
||||
const result = await agent.run('Check the claim');
|
||||
assert.equal(result.answer, 'I could not run the malformed tool request.');
|
||||
assert.doesNotMatch(result.answer, /tool_call|call:get_evidence/i);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user