From 472f4f45322f40f324f7f062a1ae3b0306f03a10 Mon Sep 17 00:00:00 2001 From: Sam Machin Date: Wed, 23 Apr 2025 14:15:16 +0100 Subject: [PATCH] clientTools over webhooks (#1167) * clientTools over webhooks * lint * simpler toolHook response --- lib/tasks/llm/index.js | 9 ++++++++- lib/utils/http-requestor.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/tasks/llm/index.js b/lib/tasks/llm/index.js index 2491b687..d16ec721 100644 --- a/lib/tasks/llm/index.js +++ b/lib/tasks/llm/index.js @@ -82,8 +82,15 @@ class TaskLlm extends Task { await this.cs?.requestor.request('llm:event', this.eventHook, data); } + async sendToolHook(tool_call_id, data) { - await this.cs?.requestor.request('llm:tool-call', this.toolHook, {tool_call_id, ...data}); + const tool_response = await this.cs?.requestor.request('llm:tool-call', this.toolHook, {tool_call_id, ...data}); + // if the toolHook was a websocket it will return undefined, otherwise it should return an object + if (typeof tool_response != 'undefined') { + tool_response.type = 'client_tool_result'; + tool_response.invocation_id = tool_call_id; + this.processToolOutput(tool_call_id, tool_response); + } } async processToolOutput(tool_call_id, data) { diff --git a/lib/utils/http-requestor.js b/lib/utils/http-requestor.js index cbac3d45..150b0e12 100644 --- a/lib/utils/http-requestor.js +++ b/lib/utils/http-requestor.js @@ -219,7 +219,7 @@ class HttpRequestor extends BaseRequestor { const rtt = this._roundTrip(startAt); if (buf) this.stats.histogram('app.hook.response_time', rtt, ['hook_type:app']); - if (buf && Array.isArray(buf)) { + if (buf && (Array.isArray(buf) || type == 'llm:tool-call')) { this.logger.info({response: buf}, `HttpRequestor:request ${method} ${url} succeeded in ${rtt}ms`); return buf; }