From 81cdc718bd1a3ad2bd3b734055b70189c488cc91 Mon Sep 17 00:00:00 2001 From: MaxRobinsonTheGreat Date: Sat, 27 Apr 2024 23:28:34 -0500 Subject: [PATCH 1/4] added memory bank and commands for saving places --- src/agent/agent.js | 2 ++ src/agent/commands/actions.js | 22 ++++++++++++++++++++++ src/agent/commands/queries.js | 7 +++++++ src/agent/history.js | 5 +++++ src/agent/memory_bank.js | 21 +++++++++++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 src/agent/memory_bank.js diff --git a/src/agent/agent.js b/src/agent/agent.js index 0736d8a..042cc26 100644 --- a/src/agent/agent.js +++ b/src/agent/agent.js @@ -5,6 +5,7 @@ import { initModes } from './modes.js'; import { initBot } from '../utils/mcdata.js'; import { containsCommand, commandExists, executeCommand, truncCommandMessage } from './commands/index.js'; import { NPCContoller } from './npc/controller.js'; +import { MemoryBank } from './memory_bank.js'; export class Agent { @@ -14,6 +15,7 @@ export class Agent { this.history = new History(this); this.coder = new Coder(this); this.npc = new NPCContoller(this); + this.memory_bank = new MemoryBank(); await this.prompter.initExamples(); diff --git a/src/agent/commands/actions.js b/src/agent/commands/actions.js index 2a84982..f409211 100644 --- a/src/agent/commands/actions.js +++ b/src/agent/commands/actions.js @@ -103,6 +103,28 @@ export const actionsList = [ await skills.moveAway(agent.bot, distance); }) }, + { + name: '!rememberHere', + description: 'Save the current location with a given name.', + params: {'name': '(string) The name to remember the location as.'}, + perform: async function (agent, name) { + const pos = agent.bot.entity.position; + agent.memory_bank.rememberPlace(name, pos.x, pos.y, pos.z); + } + }, + { + name: '!goToPlace', + description: 'Go to a saved location.', + params: {'name': '(string) The name of the location to go to.'}, + perform: wrapExecution(async (agent, name) => { + const pos = agent.memory_bank.recallPlace(name); + if (!pos) { + skills.log(agent.bot, `No location named "${name}" saved.`); + return; + } + await skills.goToPosition(agent.bot, pos[0], pos[1], pos[2], 1); + }) + }, { name: '!givePlayer', description: 'Give the specified item to the given player.', diff --git a/src/agent/commands/queries.js b/src/agent/commands/queries.js index 19260b4..b6f2449 100644 --- a/src/agent/commands/queries.js +++ b/src/agent/commands/queries.js @@ -122,5 +122,12 @@ export const queryList = [ perform: function (agent) { return agent.bot.modes.getStr(); } + }, + { + name: '!savedPlaces', + description: 'List all saved locations.', + perform: async function (agent) { + return "Saved place names: " + Object.keys(agent.memory_bank.places).join(', '); + } } ]; diff --git a/src/agent/history.js b/src/agent/history.js index b79ac80..659113b 100644 --- a/src/agent/history.js +++ b/src/agent/history.js @@ -58,6 +58,9 @@ export class History { const modes = this.agent.bot.modes.getJson(); if (modes !== null) data.modes = modes; + const memory_bank = this.agent.memory_bank.getJson(); + if (memory_bank !== null) + data.memory_bank = memory_bank; const json_data = JSON.stringify(data, null, 4); writeFileSync(this.memory_fp, json_data, (err) => { if (err) { @@ -76,6 +79,8 @@ export class History { this.agent.npc.data = NPCData.fromObject(obj.npc); if (obj.modes) this.agent.bot.modes.loadJson(obj.modes); + if (obj.memory_bank) + this.agent.memory_bank.loadJson(obj.memory_bank); this.turns = obj.turns; } catch (err) { console.error(`Error reading ${this.name}'s memory file: ${err.message}`); diff --git a/src/agent/memory_bank.js b/src/agent/memory_bank.js new file mode 100644 index 0000000..3ddcc73 --- /dev/null +++ b/src/agent/memory_bank.js @@ -0,0 +1,21 @@ +export class MemoryBank { + constructor() { + this.memory = {}; + } + + rememberPlace(name, x, y, z) { + this.memory[name] = [x, y, z]; + } + + recallPlace(name) { + return this.memory[name]; + } + + getJson() { + return this.memory + } + + loadJson(json) { + this.memory = json; + } +} \ No newline at end of file From 04eb3d07f58809f0a08a82a94a68a8d244bf4c53 Mon Sep 17 00:00:00 2001 From: MaxRobinsonTheGreat Date: Sat, 27 Apr 2024 23:36:58 -0500 Subject: [PATCH 2/4] fixed memory bank query --- src/agent/commands/queries.js | 2 +- src/agent/memory_bank.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/agent/commands/queries.js b/src/agent/commands/queries.js index b6f2449..99f5fa9 100644 --- a/src/agent/commands/queries.js +++ b/src/agent/commands/queries.js @@ -127,7 +127,7 @@ export const queryList = [ name: '!savedPlaces', description: 'List all saved locations.', perform: async function (agent) { - return "Saved place names: " + Object.keys(agent.memory_bank.places).join(', '); + return "Saved place names: " + agent.memory_bank.getKeys(); } } ]; diff --git a/src/agent/memory_bank.js b/src/agent/memory_bank.js index 3ddcc73..a32ab78 100644 --- a/src/agent/memory_bank.js +++ b/src/agent/memory_bank.js @@ -18,4 +18,8 @@ export class MemoryBank { loadJson(json) { this.memory = json; } + + getKeys() { + return Object.keys(this.memory).join(', ') + } } \ No newline at end of file From f0542833f26e46b555af7ea8b5354b4f4fac9535 Mon Sep 17 00:00:00 2001 From: MaxRobinsonTheGreat Date: Sat, 27 Apr 2024 23:37:13 -0500 Subject: [PATCH 3/4] fixed null block crash --- src/agent/modes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agent/modes.js b/src/agent/modes.js index 0081682..ef99b59 100644 --- a/src/agent/modes.js +++ b/src/agent/modes.js @@ -26,13 +26,13 @@ const modes = [ const bot = agent.bot; const block = bot.blockAt(bot.entity.position); const blockAbove = bot.blockAt(bot.entity.position.offset(0, 1, 0)); - if (blockAbove.name === 'water' || blockAbove.name === 'flowing_water') { + if (blockAbove && (blockAbove.name === 'water' || blockAbove.name === 'flowing_water')) { // does not call execute so does not interrupt other actions if (!bot.pathfinder.goal) { bot.setControlState('jump', true); } } - else if (this.fall_blocks.some(name => blockAbove.name.includes(name))) { + else if (blockAbove && this.fall_blocks.some(name => blockAbove.name.includes(name))) { execute(this, agent, async () => { await skills.moveAway(bot, 2); }); From e27aa7e8aa4df3b641086da9c922a75c0e287c37 Mon Sep 17 00:00:00 2001 From: Kolby Nottingham Date: Mon, 29 Apr 2024 14:23:38 -0700 Subject: [PATCH 4/4] memory bank example --- andy.json | 7 +++++++ andy_npc.json | 7 +++++++ pollux.json | 7 +++++++ radley.json | 7 +++++++ 4 files changed, 28 insertions(+) diff --git a/andy.json b/andy.json index 147211e..70d7355 100644 --- a/andy.json +++ b/andy.json @@ -104,6 +104,13 @@ {"role": "assistant", "content": "Okay, first I'll turn off hunting mode !setMode('hunting', false)"}, {"role": "system", "content": "'hunting' mode disabled."}, {"role": "assistant", "content": "Now I'll follow you !followPlayer('umpire_man')"} + ], + + [ + {"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": "user", "content": "brug: Go to your base."}, + {"role": "assistant", "content": "On my way! !goToPlace('base')"} ] ], diff --git a/andy_npc.json b/andy_npc.json index 561f302..c47497d 100644 --- a/andy_npc.json +++ b/andy_npc.json @@ -121,6 +121,13 @@ {"role": "assistant", "content": "Okay, first I'll turn off hunting mode !setMode('hunting', false)"}, {"role": "system", "content": "'hunting' mode disabled."}, {"role": "assistant", "content": "Now I'll follow you !followPlayer('umpire_man')"} + ], + + [ + {"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": "user", "content": "brug: Go to your base."}, + {"role": "assistant", "content": "On my way! !goToPlace('base')"} ] ], diff --git a/pollux.json b/pollux.json index e2de8eb..e94e5eb 100644 --- a/pollux.json +++ b/pollux.json @@ -102,6 +102,13 @@ {"role": "assistant", "content": "Okay, first I'll turn off hunting mode !setMode('hunting', false)"}, {"role": "system", "content": "'hunting' mode disabled."}, {"role": "assistant", "content": "Now I'll follow you !followPlayer('umpire_man')"} + ], + + [ + {"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": "user", "content": "brug: Go to your base."}, + {"role": "assistant", "content": "On my way! !goToPlace('base')"} ] ], diff --git a/radley.json b/radley.json index a5dae28..a9bceda 100644 --- a/radley.json +++ b/radley.json @@ -104,6 +104,13 @@ {"role": "assistant", "content": "Okay, first I'll turn off hunting mode !setMode('hunting', false)"}, {"role": "system", "content": "'hunting' mode disabled."}, {"role": "assistant", "content": "Now I'll follow you !followPlayer('umpire_man')"} + ], + + [ + {"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": "user", "content": "brug: Go to your base."}, + {"role": "assistant", "content": "On my way! !goToPlace('base')"} ] ],