diff --git a/src/agent/conversation.js b/src/agent/conversation.js index 89522c9..aadea3c 100644 --- a/src/agent/conversation.js +++ b/src/agent/conversation.js @@ -96,10 +96,10 @@ class ConversationManager { end, }; - sendBotChatToServer(send_to, JSON.stringify(json)); + sendBotChatToServer(send_to, json); } - async recieveFromBot(sender, json) { + async recieveFromBot(sender, recieved) { const convo = this._getConvo(sender); // check if any convo is active besides the sender @@ -108,7 +108,6 @@ class ConversationManager { return; } - const recieved = JSON.parse(json); if (recieved.start) { convo.reset(); } @@ -243,7 +242,7 @@ function _compileInMessages(convo) { } function _handleFullInMessage(sender, recieved) { - console.log(`responding to **${JSON.stringify(recieved)}**`); + console.log(`${agent.name} responding to "${recieved.message}" from ${sender}`); const convo = convoManager._getConvo(sender); convo.active = true; diff --git a/src/agent/prompter.js b/src/agent/prompter.js index 1e91469..f23a028 100644 --- a/src/agent/prompter.js +++ b/src/agent/prompter.js @@ -34,6 +34,8 @@ export class Prompter { let chat = this.profile.model; this.cooldown = this.profile.cooldown ? this.profile.cooldown : 0; this.last_prompt_time = 0; + this.awaiting_convo = false; + this.awaiting_coding = false; // try to get "max_tokens" parameter, else null let max_tokens = null; @@ -225,6 +227,11 @@ export class Prompter { } async promptConvo(messages) { + if (this.awaiting_convo) { + console.warn('Already awaiting conversation response, returning no response.'); + return ''; + } + this.awaiting_convo = true; for (let i = 0; i < 3; i++) { // try 3 times to avoid hallucinations await this.checkCooldown(); let prompt = this.profile.conversing; @@ -236,16 +243,25 @@ export class Prompter { console.warn('LLM hallucinated message as another bot. Trying again...'); continue; } + this.awaiting_convo = false; return generation; } - return "*no response*"; + this.awaiting_convo = false; + return ""; } async promptCoding(messages) { + if (this.awaiting_coding) { + console.warn('Already awaiting coding response, returning no response.'); + return ''; + } + this.awaiting_coding = true; await this.checkCooldown(); let prompt = this.profile.coding; prompt = await this.replaceStrings(prompt, messages, this.coding_examples); - return await this.chat_model.sendRequest(messages, prompt); + let resp = await this.chat_model.sendRequest(messages, prompt); + this.awaiting_coding = false; + return resp; } async promptMemSaving(to_summarize) { diff --git a/src/server/mind_server.js b/src/server/mind_server.js index c1f5931..ae952d3 100644 --- a/src/server/mind_server.js +++ b/src/server/mind_server.js @@ -72,7 +72,7 @@ export function createMindServer(port = 8080) { console.warn(`Agent ${agentName} tried to send a message but is not logged in`); return; } - console.log(`${curAgentName} sending message to ${agentName}: ${json}`); + console.log(`${curAgentName} sending message to ${agentName}: ${json.message}`); inGameAgents[agentName].emit('chat-message', curAgentName, json); });