From ae99cedec52e6a01ad70344557870beec7338ccd Mon Sep 17 00:00:00 2001 From: MaxRobinsonTheGreat Date: Thu, 12 Dec 2024 19:42:29 -0600 Subject: [PATCH 1/2] better examples, little model fixes, less chatty --- profiles/_default.json | 4 +++- profiles/grok.json | 2 +- profiles/qwen.json | 10 ++++------ src/agent/agent.js | 1 + src/agent/conversation.js | 12 ++++++------ src/agent/library/skills.js | 20 ++++++++++++++++---- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/profiles/_default.json b/profiles/_default.json index 8b9fffe..c6a776b 100644 --- a/profiles/_default.json +++ b/profiles/_default.json @@ -32,7 +32,9 @@ {"role": "system", "content": "say hi to john_goodman"}, {"role": "assistant", "content": "!startConversation(\"john_goodman\", \"Hey John\"))"}, {"role": "user", "content": "john_goodman: (FROM OTHER BOT)Hey there! What's up?"}, - {"role": "assistant", "content": "Hey John, not much. Just saying hi. Bye! !endConversation('john_goodman')"} + {"role": "assistant", "content": "Hey John, not much. Just saying hi."}, + {"role": "user", "content": "john_goodman: (FROM OTHER BOT)Bye!"}, + {"role": "assistant", "content": "Bye! !endConversation('john_goodman')"} ], [ diff --git a/profiles/grok.json b/profiles/grok.json index 599bd1e..eeb3a38 100644 --- a/profiles/grok.json +++ b/profiles/grok.json @@ -1,5 +1,5 @@ { - "name": "grok", + "name": "Grok", "model": "grok-beta", diff --git a/profiles/qwen.json b/profiles/qwen.json index b7ba37a..7af2347 100644 --- a/profiles/qwen.json +++ b/profiles/qwen.json @@ -1,15 +1,13 @@ { "name": "qwen", + "cooldown": 5000, + "model": { "api": "qwen", - "url": "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation", + "url": "https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/text-generation/generation", "model": "qwen-max" }, - "embedding": { - "api": "qwen", - "url": "https://dashscope.aliyuncs.com/api/v1/services/embeddings/text-embedding/text-embedding", - "model": "text-embedding-v2" - } + "embedding": "openai" } \ No newline at end of file diff --git a/src/agent/agent.js b/src/agent/agent.js index 7c514f0..06bcf3d 100644 --- a/src/agent/agent.js +++ b/src/agent/agent.js @@ -310,6 +310,7 @@ export class Agent { } async routeResponse(to_player, message) { + if (this.shut_up) return; let self_prompt = to_player === 'system' || to_player === this.name; if (self_prompt && this.last_sender) { // this is for when the agent is prompted by system while still in conversation diff --git a/src/agent/conversation.js b/src/agent/conversation.js index 1b09441..1cd57a3 100644 --- a/src/agent/conversation.js +++ b/src/agent/conversation.js @@ -134,7 +134,7 @@ class ConversationManager { convo.active = true; this.activeConversation = convo; this._startMonitor(); - this.sendToBot(send_to, message, true); + this.sendToBot(send_to, message, true, false); } startConversationFromOtherBot(name) { @@ -144,14 +144,14 @@ class ConversationManager { this._startMonitor(); } - sendToBot(send_to, message, start=false) { + sendToBot(send_to, message, start=false, open_chat=true) { if (!this.isOtherAgent(send_to)) { - agent.bot.whisper(send_to, message); + console.warn(`${agent.name} tried to send bot message to non-bot ${send_to}`); return; } const convo = this._getConvo(send_to); - if (settings.chat_bot_messages && !start) + if (settings.chat_bot_messages && open_chat) agent.openChat(`(To ${send_to}) ${message}`); if (convo.ignore_until_start) @@ -174,7 +174,7 @@ class ConversationManager { // check if any convo is active besides the sender if (Object.values(this.convos).some(c => c.active && c.name !== sender)) { - this.sendToBot(sender, `I'm talking to someone else, try again later. !endConversation("${sender}")`); + this.sendToBot(sender, `I'm talking to someone else, try again later. !endConversation("${sender}")`, false, false); return; } @@ -240,7 +240,7 @@ class ConversationManager { endAllConversations() { for (const sender in this.convos) { - this.convos[sender].end(); + this.endConversation(sender); } if (self_prompter_paused) { _resumeSelfPrompter(); diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index 7c8819f..23f30ad 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -897,10 +897,7 @@ export async function giveToPlayer(bot, itemType, username, num=1) { } // if we are too close, make some distance if (bot.entity.position.distanceTo(player.position) < 2) { - let goal = new pf.goals.GoalNear(player.position.x, player.position.y, player.position.z, 2); - let inverted_goal = new pf.goals.GoalInvert(goal); - bot.pathfinder.setMovements(new pf.Movements(bot)); - await bot.pathfinder.goto(inverted_goal); + await moveAwayFromEntity(bot, player, 2); } await bot.lookAt(player.position); if (await discard(bot, itemType, num)) { @@ -1106,6 +1103,21 @@ export async function moveAway(bot, distance) { return true; } +export async function moveAwayFromEntity(bot, entity, distance=16) { + /** + * Move away from the given entity. + * @param {MinecraftBot} bot, reference to the minecraft bot. + * @param {Entity} entity, the entity to move away from. + * @param {number} distance, the distance to move away. + * @returns {Promise} true if the bot moved away, false otherwise. + **/ + let goal = new pf.goals.GoalFollow(entity, distance); + let inverted_goal = new pf.goals.GoalInvert(goal); + bot.pathfinder.setMovements(new pf.Movements(bot)); + await bot.pathfinder.goto(inverted_goal); + return true; +} + export async function avoidEnemies(bot, distance=16) { /** * Move a given distance away from all nearby enemy mobs. From 7ad48c29adb9288e205adce4a46747eec53f71fc Mon Sep 17 00:00:00 2001 From: MaxRobinsonTheGreat Date: Fri, 13 Dec 2024 10:42:41 -0600 Subject: [PATCH 2/2] added full shutdown from ui/task --- src/agent/agent.js | 22 +++++++++++----------- src/agent/agent_proxy.js | 4 ++++ src/agent/tasks.js | 2 +- src/process/main_proxy.js | 10 ++++++++++ src/server/mind_server.js | 22 ++++++++++++++++++++++ src/server/public/index.html | 10 ++++++++++ 6 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/agent/agent.js b/src/agent/agent.js index 5e9cc5f..79e1d29 100644 --- a/src/agent/agent.js +++ b/src/agent/agent.js @@ -438,22 +438,18 @@ export class Agent { }, INTERVAL); this.bot.emit('idle'); - - // Check for task completion - if (this.task.data) { - setInterval(() => { - let res = this.task.isDone(); - if (res) { - // TODO kill other bots - this.cleanKill(res.message, res.code); - } - }, 1000); - } } async update(delta) { await this.bot.modes.update(); this.self_prompter.update(delta); + if (this.task.data) { + let res = this.task.isDone(); + if (res) { + console.log('Task finished:', res.message); + this.killAll(); + } + } } isIdle() { @@ -466,4 +462,8 @@ export class Agent { this.history.save(); process.exit(code); } + + killAll() { + serverProxy.shutdown(); + } } diff --git a/src/agent/agent_proxy.js b/src/agent/agent_proxy.js index 81395ac..feeba37 100644 --- a/src/agent/agent_proxy.js +++ b/src/agent/agent_proxy.js @@ -48,6 +48,10 @@ class AgentServerProxy { this.socket.emit('login-agent', this.agent.name); } + shutdown() { + this.socket.emit('shutdown'); + } + getSocket() { return this.socket; } diff --git a/src/agent/tasks.js b/src/agent/tasks.js index 881b933..f7527f1 100644 --- a/src/agent/tasks.js +++ b/src/agent/tasks.js @@ -179,7 +179,7 @@ export class Task { await new Promise((resolve) => setTimeout(resolve, 10000)); if (available_agents.length < this.data.agent_count) { console.log(`Missing ${this.data.agent_count - available_agents.length} bot(s).`); - this.agent.cleanKill('Not all required players/bots are present in the world. Exiting.', 4); + this.agent.killAll(); } } diff --git a/src/process/main_proxy.js b/src/process/main_proxy.js index 44c2733..8336458 100644 --- a/src/process/main_proxy.js +++ b/src/process/main_proxy.js @@ -35,6 +35,16 @@ class MainProxy { this.socket.on('register-agents-success', () => { console.log('Agents registered'); }); + + this.socket.on('shutdown', () => { + console.log('Shutting down'); + for (let agentName in this.agent_processes) { + this.agent_processes[agentName].stop(); + } + setTimeout(() => { + process.exit(0); + }, 2000); + }); } addAgent(agent) { diff --git a/src/server/mind_server.js b/src/server/mind_server.js index ae952d3..5d99290 100644 --- a/src/server/mind_server.js +++ b/src/server/mind_server.js @@ -101,6 +101,19 @@ export function createMindServer(port = 8080) { } }); + socket.on('stop-all-agents', () => { + console.log('Killing all agents'); + stopAllAgents(); + }); + + socket.on('shutdown', () => { + console.log('Shutting down'); + for (let manager of Object.values(agentManagers)) { + manager.emit('shutdown'); + } + process.exit(0); + }); + }); server.listen(port, 'localhost', () => { @@ -121,6 +134,15 @@ function agentsUpdate(socket) { socket.emit('agents-update', agents); } +function stopAllAgents() { + for (const agentName in inGameAgents) { + let manager = agentManagers[agentName]; + if (manager) { + manager.emit('stop-agent', agentName); + } + } +} + // Optional: export these if you need access to them from other files export const getIO = () => io; export const getServer = () => server; diff --git a/src/server/public/index.html b/src/server/public/index.html index b597ed9..43ada99 100644 --- a/src/server/public/index.html +++ b/src/server/public/index.html @@ -85,6 +85,8 @@ `} + + `).join('') : '
No agents connected
'; }); @@ -100,6 +102,14 @@ function stopAgent(agentName) { socket.emit('stop-agent', agentName); } + + function killAllAgents() { + socket.emit('stop-all-agents'); + } + + function shutdown() { + socket.emit('shutdown'); + } \ No newline at end of file