Skip to content

Commit cc12dd9

Browse files
committed
SimpleChatTC:TCPending: Clear pending in unhappy paths
ie if exception raised during tool call execution and or time out occurs
1 parent 3894f4e commit cc12dd9

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

tools/server/public_simplechat/readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,12 @@ sliding window based drop off or even before they kick in, this can help in many
644644
handlers. Inturn run the calling through a setTimeout0, so that delayed/missing response
645645
situation rescuer timeout logic etal flow doesnt get messed for now.
646646

647+
* track tool calling and inturn maintain pending tool calls so that only still valid tool call responses
648+
will be accepted when the asynchronous tool call response is recieved. Also take care of clearing
649+
pending tool call tracking in unhappy paths like when exception noticied as part of tool call execution,
650+
or if there is no response within the configured timeout period.
651+
NOTE: Currently the logic supports only 1 pending tool call per chat session.
652+
647653

648654
#### ToDo
649655

tools/server/public_simplechat/simplechat.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ class SimpleChat {
753753
try {
754754
return await this.me.toolsMgr.tool_call(this.chatId, toolcallid, toolname, toolargs)
755755
} catch (/** @type {any} */error) {
756+
this.me.toolsMgr.toolcallpending_found_cleared(this.chatId, toolcallid, 'SC:HandleToolCall:Exc')
756757
return `Tool/Function call raised an exception:${error.name}:${error.message}`
757758
}
758759
}
@@ -1213,6 +1214,7 @@ class MultiChatUI {
12131214
this.ui_reset_userinput(false)
12141215
} else {
12151216
this.timers.toolcallResponseTimeout = setTimeout(() => {
1217+
this.me.toolsMgr.toolcallpending_found_cleared(chat.chatId, toolCallId, 'MCUI:HandleToolRun:TimeOut')
12161218
chat.add(new ChatMessageEx(Roles.ToolTemp, ChatMessageEx.createToolCallResultAllInOne(toolCallId, toolname, `Tool/Function call ${toolname} taking too much time, aborting...`)))
12171219
this.chat_show(chat.chatId)
12181220
this.ui_reset_userinput(false)

tools/server/public_simplechat/tools.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export class ToolsManager {
134134
this.tc_switch[fn]["handler"](chatid, toolcallid, fn, JSON.parse(toolargs))
135135
return undefined
136136
} catch (/** @type {any} */error) {
137+
this.toolcallpending_found_cleared(chatid, toolcallid, 'ToolsManager:ToolCall:Exc')
137138
return `Tool/Function call raised an exception:${error.name}:${error.message}`
138139
}
139140
}

0 commit comments

Comments
 (0)