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