SimpleChatTC:ToolTemp: Ensure add removes non promoted ToolTemp

This commit is contained in:
hanishkvc 2025-10-28 02:17:15 +05:30
parent 4eb3322017
commit 13d312fe0d
1 changed files with 10 additions and 0 deletions

View File

@ -407,11 +407,21 @@ class SimpleChat {
/** /**
* Add an entry into xchat. * Add an entry into xchat.
* If the last message in chat history is a ToolTemp message, discard it
* as the runtime logic is asking for adding new message instead of promoting the tooltemp message.
*
* NOTE: A new copy is created and added into xchat. * NOTE: A new copy is created and added into xchat.
* Also update iLastSys system prompt index tracker * Also update iLastSys system prompt index tracker
* @param {ChatMessageEx} chatMsg * @param {ChatMessageEx} chatMsg
*/ */
add(chatMsg) { add(chatMsg) {
if (this.xchat.length > 0) {
let lastIndex = this.xchat.length - 1;
if (this.xchat[lastIndex].ns.role == Roles.ToolTemp) {
console.debug("DBUG:SimpleChat:Add:Discarding prev ToolTemp message...")
this.xchat.pop()
}
}
this.xchat.push(ChatMessageEx.newFrom(chatMsg)); this.xchat.push(ChatMessageEx.newFrom(chatMsg));
if (chatMsg.ns.role == Roles.System) { if (chatMsg.ns.role == Roles.System) {
this.iLastSys = this.xchat.length - 1; this.iLastSys = this.xchat.length - 1;