Skip to content

Commit

Permalink
Merge pull request #372 from kolbytn/convo-patch
Browse files Browse the repository at this point in the history
Convo patch
  • Loading branch information
MaxRobinsonTheGreat authored Dec 18, 2024
2 parents 89c94d9 + 44d110d commit afe43c0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 30 deletions.
7 changes: 3 additions & 4 deletions profiles/_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@
],

[
{"role": "system", "content": "work together with the other bot"},
{"role": "assistant", "content": "!startConversation(\"terrance\", \"Hey gpt! Let's work together on this.\"))"},
{"role": "user", "content": "terrance: (FROM OTHER BOT)Sounds good, what should we do first?"},
{"role": "assistant", "content": "I'll start by collecting some resources. !collectBlocks('stone', 10)"}
{"role": "system", "content": "work together with the other bot to build a house"},
{"role": "assistant", "content": "!startConversation(\"terrance\", \"Hey gpt! Let's work together to build a house. Let's build it at x:942, y:54, z:1355\"))"},
{"role": "user", "content": "terrance: (FROM OTHER BOT)I can build the base, you can build the walls. !newAction(\"Build a 10x10 wall of a house at x:942, y:54, z:1355\")"}
],

[
Expand Down
19 changes: 9 additions & 10 deletions src/agent/commands/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,12 @@ export const actionsList = [
'num': { type: 'int', description: 'The number of times to smelt the item.', domain: [1, Number.MAX_SAFE_INTEGER] }
},
perform: runAsAction(async (agent, item_name, num) => {
let response = await skills.smeltItem(agent.bot, item_name, num);
if (response.indexOf('Successfully') !== -1) {
// there is a bug where the bot's inventory is not updated after smelting
// only updates after a restart
agent.cleanKill(response + ' Safely restarting to update inventory.');
let success = await skills.smeltItem(agent.bot, item_name, num);
if (success) {
setTimeout(() => {
agent.cleanKill('Safely restarting to update inventory.');
}, 500);
}
return response;
})
},
{
Expand Down Expand Up @@ -386,12 +385,12 @@ export const actionsList = [
'message': { type: 'string', description: 'The message to send.' },
},
perform: async function (agent, player_name, message) {
if (convoManager.inConversation() && !convoManager.inConversation(player_name))
return 'You are already in conversation with other bot.';
if (!convoManager.isOtherAgent(player_name))
return player_name + ' is not a bot, cannot start conversation.';
if (convoManager.inConversation(player_name))
agent.history.add('system', 'You are already in conversation with ' + player_name + ' Don\'t use this command to talk to them.');
if (convoManager.inConversation() && !convoManager.inConversation(player_name))
convoManager.forceEndCurrentConversation();
else if (convoManager.inConversation(player_name))
agent.history.add('system', 'You are already in conversation with ' + player_name + '. Don\'t use this command to talk to them.');
convoManager.startConversation(player_name, message);
}
},
Expand Down
40 changes: 27 additions & 13 deletions src/agent/conversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,21 @@ class ConversationManager {
async recieveFromBot(sender, recieved) {
const convo = this._getConvo(sender);

if (convo.ignore_until_start && !recieved.start)
return;

// check if any convo is active besides the sender
if (Object.values(this.convos).some(c => c.active && c.name !== sender)) {
if (this.inConversation() && !this.inConversation(sender)) {
this.sendToBot(sender, `I'm talking to someone else, try again later. !endConversation("${sender}")`, false, false);
this.endConversation(sender);
return;
}

if (recieved.start) {
convo.reset();
this.startConversationFromOtherBot(sender);
}
if (convo.ignore_until_start)
return;


this._clearMonitorTimeouts();
convo.queue(recieved);

Expand Down Expand Up @@ -230,10 +232,12 @@ class ConversationManager {
endConversation(sender) {
if (this.convos[sender]) {
this.convos[sender].end();
this._stopMonitor();
this.activeConversation = null;
if (self_prompter_paused && !this.inConversation()) {
_resumeSelfPrompter();
if (this.activeConversation.name === sender) {
this._stopMonitor();
this.activeConversation = null;
if (self_prompter_paused && !this.inConversation()) {
_resumeSelfPrompter();
}
}
}
}
Expand All @@ -246,7 +250,15 @@ class ConversationManager {
_resumeSelfPrompter();
}
}


forceEndCurrentConversation() {
if (this.activeConversation) {
let sender = this.activeConversation.name;
this.sendToBot(sender, '!endConversation("' + sender + '")', false, false);
this.endConversation(sender);
}
}

scheduleSelfPrompter() {
self_prompter_paused = true;
}
Expand Down Expand Up @@ -332,8 +344,8 @@ function _handleFullInMessage(sender, recieved) {
let message = _tagMessage(recieved.message);
if (recieved.end) {
convoManager.endConversation(sender);
sender = 'system'; // bot will respond to system instead of the other bot
message = `Conversation with ${sender} ended with message: "${message}"`;
sender = 'system'; // bot will respond to system instead of the other bot
}
else if (recieved.start)
agent.shut_up = false;
Expand All @@ -348,6 +360,8 @@ function _tagMessage(message) {

async function _resumeSelfPrompter() {
await new Promise(resolve => setTimeout(resolve, 5000));
self_prompter_paused = false;
agent.self_prompter.start();
if (self_prompter_paused && !convoManager.inConversation()) {
self_prompter_paused = false;
agent.self_prompter.start();
}
}
3 changes: 3 additions & 0 deletions src/agent/prompter.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ export class Prompter {
let current_msg_time = this.most_recent_msg_time;
for (let i = 0; i < 3; i++) { // try 3 times to avoid hallucinations
await this.checkCooldown();
if (current_msg_time !== this.most_recent_msg_time) {
return '';
}
let prompt = this.profile.conversing;
prompt = await this.replaceStrings(prompt, messages, this.convo_examples);
let generation = await this.chat_model.sendRequest(messages, prompt);
Expand Down
6 changes: 3 additions & 3 deletions src/server/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ <h1>Mindcraft</h1>
`}
</div>
</div>
<button class="stop-btn" onclick="killAllAgents()">Stop All</button>
<button class="stop-btn" onclick="shutdown()">Shutdown</button>
`).join('') :
`).join('') +
`<button class="stop-btn" onclick="killAllAgents()">Stop All</button>
<button class="stop-btn" onclick="shutdown()">Shutdown</button>` :
'<div class="agent">No agents connected</div>';
});

Expand Down

0 comments on commit afe43c0

Please sign in to comment.