perf(bridge): 商品检索改用短关键词并恢复分阶段计时

This commit is contained in:
wangliang
2026-10-23 16:32:03 +08:00
parent a0d386b752
commit 0959777048
6 changed files with 174 additions and 12 deletions
+38
View File
@@ -357,3 +357,41 @@ test('agent: extracts lead fields when the LLM skips collect_info (company menti
assert.equal(twenty.calls.filter((c) => c[0] === 'createOpportunity').length, 1);
assert.ok(twenty.calls.some((c) => c[0] === 'createCompany' && c[1] === 'Leadfix GmbH'));
});
test('agent: product pre-retrieval sends cleaned keyword instead of the full sentence', async () => {
const queries = [];
const tools = [{
name: 'search_products',
description: 'fake',
parameters: { type: 'object', properties: {} },
handler: async (args) => {
queries.push(args.query);
return { products: [{ name: 'Steel Ring', price: '€2,50', stock: 10, url: 'https://www.yehwang.com/p/steel-ring.html' }], count: 1 };
},
}];
tools.leadStore = { get: async () => null, save: async () => null };
let sent = '';
let recorded = null;
const agent = createAgent({ sites: [], defaultSite: 'www' }, {
llm: {
enabled: true,
model: 'fake',
chat: async () => ({ content: 'Steel Ring — €2,50,库存 10 件。', toolCalls: [], usage: null }),
},
client: {
getMessages: async () => [{ id: 1, text_content: 'We need 500 stainless steel rings wholesale.', sender_type: 'contact', private: false }],
sendMessage: async (_uuid, content) => { sent = content; },
sendPrivateNote: async () => {},
},
tools,
verification: { getVerifiedEmail: async () => null, sendCode: async () => ({}), verifyCode: async () => ({}) },
metrics: { record: async (m) => { recorded = m; }, enabled: false },
contextManager: { compressHistory: async (_c, h) => h },
});
const conv = { uuid: 'conv-clean-1', inbox_id: '1', channel: 'livechat', contact: { type: 'visitor' } };
await agent.run(conv, { uuid: 'msg-clean-1', text_content: 'We need 500 stainless steel rings wholesale.', content: '...' });
assert.deepEqual(queries, ['stainless steel rings']);
assert.match(sent, /Steel Ring/);
assert.equal(typeof recorded.audit.timing.llm_ms, 'number');
assert.equal(typeof recorded.audit.timing.tool_ms, 'number');
});