better continue conversation logic/monitor

This commit is contained in:
MaxRobinsonTheGreat 2024-12-05 16:06:05 -06:00
parent f068b4c7ce
commit 9cd39dc5df
4 changed files with 33 additions and 7 deletions

View file

@ -149,7 +149,7 @@
{"role": "user", "content": "brug: Remember that your base is here."}, {"role": "user", "content": "brug: Remember that your base is here."},
{"role": "assistant", "content": "Sure, I'll save this location as my base. !rememberHere(\"base\")"}, {"role": "assistant", "content": "Sure, I'll save this location as my base. !rememberHere(\"base\")"},
{"role": "user", "content": "brug: Go to your base."}, {"role": "user", "content": "brug: Go to your base."},
{"role": "assistant", "content": "On my way! !goToPlace(\"base\")"} {"role": "assistant", "content": "On my way! !goToRememberedPlace(\"base\")"}
], ],
[ [

View file

@ -149,10 +149,15 @@ export class Agent {
this.history.add('system', prompt); this.history.add('system', prompt);
await this.self_prompter.start(prompt); await this.self_prompter.start(prompt);
} }
else if (save_data?.last_sender) { if (save_data?.last_sender) {
this.last_sender = save_data.last_sender; this.last_sender = save_data.last_sender;
if (convoManager.isOtherAgent(this.last_sender)) if (convoManager.isOtherAgent(this.last_sender)) {
convoManager.recieveFromBot(this.last_sender, `You have restarted and this message is auto-generated. Continue the conversation with me.`); const package = {
message: `You have restarted and this message is auto-generated. Continue the conversation with me.`,
start: true
};
convoManager.recieveFromBot(this.last_sender, package);
}
} }
else if (init_message) { else if (init_message) {
await this.handleMessage('system', init_message, 2); await this.handleMessage('system', init_message, 2);
@ -254,7 +259,7 @@ export class Agent {
let history = this.history.getHistory(); let history = this.history.getHistory();
let res = await this.prompter.promptConvo(history); let res = await this.prompter.promptConvo(history);
console.log(`${this.name} full response: ""${res}""`); console.log(`${this.name} full response to ${source}: ""${res}""`);
if (res.trim().length === 0) { if (res.trim().length === 0) {
console.warn('no response') console.warn('no response')

View file

@ -60,6 +60,26 @@ class ConversationManager {
return this.convos[name]; return this.convos[name];
} }
_startMonitor() {
clearInterval(this.connection_monitor);
this.connection_monitor = setInterval(() => {
if (!this.activeConversation) {
clearInterval(this.connection_monitor);
return; // will clean itself up
}
let cur_name = this.activeConversation.name;
if (!this.isOtherAgent(cur_name)) {
if (!self_prompter_paused) {
this.endConversation(cur_name);
agent.handleMessage('system', `${cur_name} disconnected, conversation has ended.`);
}
else {
this.endConversation(cur_name);
}
}
}, 10000);
}
async startConversation(send_to, message) { async startConversation(send_to, message) {
const convo = this._getConvo(send_to); const convo = this._getConvo(send_to);
convo.reset(); convo.reset();
@ -72,6 +92,7 @@ class ConversationManager {
return; return;
convo.active = true; convo.active = true;
this.activeConversation = convo; this.activeConversation = convo;
this._startMonitor();
this.sendToBot(send_to, message, true); this.sendToBot(send_to, message, true);
} }

View file

@ -247,13 +247,13 @@ export class Prompter {
return generation; return generation;
} }
this.awaiting_convo = false; this.awaiting_convo = false;
return ""; return '';
} }
async promptCoding(messages) { async promptCoding(messages) {
if (this.awaiting_coding) { if (this.awaiting_coding) {
console.warn('Already awaiting coding response, returning no response.'); console.warn('Already awaiting coding response, returning no response.');
return ''; return '```//no response```';
} }
this.awaiting_coding = true; this.awaiting_coding = true;
await this.checkCooldown(); await this.checkCooldown();