diff --git a/tools/server/public_simplechat/readme.md b/tools/server/public_simplechat/readme.md index 784c5c6ef6..a1764b740a 100644 --- a/tools/server/public_simplechat/readme.md +++ b/tools/server/public_simplechat/readme.md @@ -644,6 +644,12 @@ sliding window based drop off or even before they kick in, this can help in many handlers. Inturn run the calling through a setTimeout0, so that delayed/missing response situation rescuer timeout logic etal flow doesnt get messed for now. +* track tool calling and inturn maintain pending tool calls so that only still valid tool call responses + will be accepted when the asynchronous tool call response is recieved. Also take care of clearing + pending tool call tracking in unhappy paths like when exception noticied as part of tool call execution, + or if there is no response within the configured timeout period. + NOTE: Currently the logic supports only 1 pending tool call per chat session. + #### ToDo diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js index d5e6969805..6a583aab1c 100644 --- a/tools/server/public_simplechat/simplechat.js +++ b/tools/server/public_simplechat/simplechat.js @@ -753,6 +753,7 @@ class SimpleChat { try { return await this.me.toolsMgr.tool_call(this.chatId, toolcallid, toolname, toolargs) } catch (/** @type {any} */error) { + this.me.toolsMgr.toolcallpending_found_cleared(this.chatId, toolcallid, 'SC:HandleToolCall:Exc') return `Tool/Function call raised an exception:${error.name}:${error.message}` } } @@ -1213,6 +1214,7 @@ class MultiChatUI { this.ui_reset_userinput(false) } else { this.timers.toolcallResponseTimeout = setTimeout(() => { + this.me.toolsMgr.toolcallpending_found_cleared(chat.chatId, toolCallId, 'MCUI:HandleToolRun:TimeOut') chat.add(new ChatMessageEx(Roles.ToolTemp, ChatMessageEx.createToolCallResultAllInOne(toolCallId, toolname, `Tool/Function call ${toolname} taking too much time, aborting...`))) this.chat_show(chat.chatId) this.ui_reset_userinput(false) diff --git a/tools/server/public_simplechat/tools.mjs b/tools/server/public_simplechat/tools.mjs index 9c955415a6..76f95e0947 100644 --- a/tools/server/public_simplechat/tools.mjs +++ b/tools/server/public_simplechat/tools.mjs @@ -134,6 +134,7 @@ export class ToolsManager { this.tc_switch[fn]["handler"](chatid, toolcallid, fn, JSON.parse(toolargs)) return undefined } catch (/** @type {any} */error) { + this.toolcallpending_found_cleared(chatid, toolcallid, 'ToolsManager:ToolCall:Exc') return `Tool/Function call raised an exception:${error.name}:${error.message}` } }