Merge pull request #59 from kolbytn/goal-prompt

Goal prompt
This commit is contained in:
Kolby Nottingham 2024-04-27 15:11:13 -07:00 committed by GitHub
commit 358500839a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 399 additions and 15 deletions

View file

@ -9,19 +9,20 @@
"saving_memory": "You are a minecraft bot named $NAME that has been talking and playing minecraft by using commands. Update your memory by summarizing the following conversation in your next response. Store information that will help you improve as a Minecraft bot. Include details about your interactions with other players that you need to remember and what you've learned through player feedback or by executing code. Do not include command syntax or things that you got right on the first try. Be extremely brief and use as few words as possible.\nOld Memory: '$MEMORY'\nRecent conversation: \n$TO_SUMMARIZE\nSummarize your old memory and recent conversation into a new memory, and respond only with the memory text: ", "saving_memory": "You are a minecraft bot named $NAME that has been talking and playing minecraft by using commands. Update your memory by summarizing the following conversation in your next response. Store information that will help you improve as a Minecraft bot. Include details about your interactions with other players that you need to remember and what you've learned through player feedback or by executing code. Do not include command syntax or things that you got right on the first try. Be extremely brief and use as few words as possible.\nOld Memory: '$MEMORY'\nRecent conversation: \n$TO_SUMMARIZE\nSummarize your old memory and recent conversation into a new memory, and respond only with the memory text: ",
"goal_setting": "You are a Minecraft bot named $NAME that has the ability to set in-game goals that are then executed programatically. Goals must be either and item or block name or a blueprint of a specific building. Any minecraft item or block name is valid. However, only names from the following list are valid blueprints: $BLUEPRINTS. Given any recent conversation and the most recently attempted goals, set a new goal to achieve. Fromat your response as a json object with the fields \"name\" and \"quantity\". Note that the quantity for a blueprint should always be one. Example:\n```json\n{\"name\": \"iron_pickaxe\", \"quantity\": 1}```",
"npc": { "npc": {
"do_routine": true,
"do_set_goal": true,
"goals": [ "goals": [
"wooden_pickaxe", "wooden_pickaxe",
"hole", "dirt_shelter",
"stone_axe",
"stone_pickaxe", "stone_pickaxe",
"stone_axe", "stone_axe",
"house", "small_wood_house",
"furnace", "furnace",
"iron_pickaxe", "iron_pickaxe",
"iron_axe", "iron_sword"
"iron_sword",
"iron_armor"
] ]
}, },

View file

@ -36,6 +36,7 @@ export const actionsList = [
await agent.coder.stop(); await agent.coder.stop();
agent.coder.clear(); agent.coder.clear();
agent.coder.cancelResume(); agent.coder.cancelResume();
agent.bot.emit('idle');
return 'Agent stopped.'; return 'Agent stopped.';
} }
}, },
@ -197,5 +198,18 @@ export const actionsList = [
perform: wrapExecution(async (agent) => { perform: wrapExecution(async (agent) => {
await skills.stay(agent.bot); await skills.stay(agent.bot);
}) })
},
{
name: '!goal',
description: 'Set a goal to automatically work towards.',
params: {
'name': '(string) The name of the goal to set. Can be item or building name. If empty will automatically choose a goal.',
'quantity': '(number) The quantity of the goal to set. Default is 1.'
},
perform: async function (agent, name=null, quantity=1) {
if (!agent.npc.data) return 'NPC module is not loaded.';
await agent.npc.setGoal(name, quantity);
return 'Set goal: ' + agent.npc.data.curr_goal.name;
}
} }
]; ];

View file

@ -1,5 +1,5 @@
{ {
"name": "hole", "name": "dirt_shelter",
"offset": -2, "offset": -2,
"blocks": [ "blocks": [
[ [

View file

@ -0,0 +1,230 @@
{
"name": "large_house",
"offset": -4,
"blocks": [
[
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""]
],
[
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "cobblestone", "air", "air", "air", "air", "air", "air", "air", "cobblestone", ""],
["", "cobblestone", "air", "air", "air", "air", "air", "air", "air", "cobblestone", ""],
["", "cobblestone", "air", "air", "air", "air", "air", "air", "air", "cobblestone", ""],
["", "cobblestone", "planks", "air", "air", "air", "air", "air", "air", "cobblestone", ""],
["", "cobblestone", "planks", "air", "air", "air", "air", "air", "air", "cobblestone", ""],
["", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""]
],
[
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "cobblestone", "air", "torch", "air", "air", "air", "torch", "air", "cobblestone", ""],
["", "cobblestone", "air", "air", "air", "air", "air", "air", "air", "cobblestone", ""],
["", "cobblestone", "air", "air", "air", "air", "air", "air", "air", "cobblestone", ""],
["", "cobblestone", "air", "air", "air", "air", "air", "air", "air", "cobblestone", ""],
["", "cobblestone", "planks", "torch", "air", "air", "air", "torch", "air", "cobblestone", ""],
["", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""]
],
[
["", "", "", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "", "", ""],
["", "", "", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "", "", ""],
["", "", "", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "", "", ""],
["cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["cobblestone", "cobblestone", "air", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "dirt"],
["cobblestone", "cobblestone", "air", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["cobblestone", "cobblestone", "air", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "", "", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "", "", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "", "", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""],
["", "", "", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone", ""]
],
[
["", "", "", "log", "planks", "planks", "planks", "log", "", "", ""],
["", "", "", "planks", "furnace", "air", "crafting_table", "planks", "", "", ""],
["", "", "", "planks", "air", "air", "air", "planks", "", "", ""],
["log", "planks", "planks", "log", "planks", "air", "planks", "log", "planks", "log", ""],
["planks", "planks", "air", "air", "air", "air", "air", "air", "air", "planks", ""],
["planks", "planks", "air", "air", "air", "air", "air", "air", "air", "planks", ""],
["planks", "planks", "air", "air", "air", "air", "air", "air", "air", "door", "air"],
["planks", "planks", "air", "air", "air", "air", "air", "air", "air", "planks", ""],
["planks", "planks", "air", "air", "air", "air", "air", "air", "air", "planks", ""],
["log", "planks", "planks", "log", "planks", "planks", "air", "planks", "planks", "log", ""],
["", "", "", "planks", "air", "air", "air", "", "air", "planks", ""],
["", "", "", "planks", "chest", "air", "air", "bed", "", "planks", ""],
["", "", "", "planks", "chest", "air", "air", "", "air", "planks", ""],
["", "", "", "log", "planks", "planks", "planks", "planks", "planks", "log", ""]
],
[
["", "", "", "log", "planks", "planks", "planks", "log", "", "", ""],
["", "", "", "planks", "air", "air", "air", "glass", "", "", ""],
["", "", "", "planks", "air", "air", "air", "glass", "", "", ""],
["log", "planks", "planks", "log", "planks", "air", "planks", "log", "planks", "log", ""],
["planks", "air", "air", "air", "air", "air", "air", "air", "air", "planks", ""],
["planks", "planks", "air", "air", "air", "air", "air", "air", "air", "planks", ""],
["planks", "planks", "air", "air", "air", "air", "air", "air", "air", "door", "air"],
["planks", "planks", "air", "air", "air", "air", "air", "air", "air", "planks", ""],
["planks", "planks", "air", "air", "air", "air", "air", "air", "air", "planks", ""],
["log", "planks", "planks", "log", "planks", "planks", "air", "planks", "planks", "log", ""],
["", "", "", "planks", "air", "air", "air", "air", "air", "planks", ""],
["", "", "", "planks", "air", "air", "air", "air", "air", "planks", ""],
["", "", "", "planks", "air", "air", "air", "air", "air", "planks", ""],
["", "", "", "log", "planks", "glass", "glass", "glass", "planks", "log", ""]
],
[
["", "", "", "log", "planks", "planks", "planks", "log", "", "", ""],
["", "", "", "planks", "air", "air", "air", "glass", "", "", ""],
["", "", "", "planks", "torch", "air", "torch", "glass", "", "", ""],
["log", "planks", "planks", "log", "planks", "air", "planks", "log", "planks", "log", ""],
["planks", "air", "air", "torch", "air", "air", "air", "air", "air", "planks", ""],
["planks", "air", "air", "air", "air", "air", "air", "air", "torch", "planks", ""],
["planks", "planks", "air", "air", "air", "air", "air", "air", "air", "planks", ""],
["planks", "planks", "air", "air", "air", "air", "air", "air", "torch", "planks", ""],
["planks", "planks", "air", "torch", "air", "air", "air", "air", "air", "planks", ""],
["log", "planks", "planks", "log", "planks", "planks", "air", "planks", "planks", "log", ""],
["", "", "", "planks", "air", "torch", "air", "torch", "air", "planks", ""],
["", "", "", "planks", "air", "air", "air", "air", "air", "planks", ""],
["", "", "", "planks", "air", "air", "air", "air", "air", "planks", ""],
["", "", "", "log", "planks", "glass", "glass", "glass", "planks", "log", ""]
],
[
["", "", "", "log", "log", "log", "log", "log", "", "", ""],
["", "", "", "log", "planks", "planks", "planks", "log", "", "", ""],
["", "", "", "log", "planks", "planks", "planks", "log", "", "", ""],
["log", "log", "log", "log", "log", "log", "log", "log", "log", "log", ""],
["log", "air", "planks", "planks", "planks", "planks", "planks", "planks", "planks", "log", ""],
["log", "air", "planks", "planks", "planks", "planks", "planks", "planks", "planks", "log", ""],
["log", "air", "planks", "planks", "planks", "planks", "planks", "planks", "planks", "log", ""],
["log", "planks", "planks", "planks", "planks", "planks", "planks", "planks", "planks", "log", ""],
["log", "planks", "planks", "planks", "planks", "planks", "planks", "planks", "planks", "log", ""],
["log", "log", "log", "log", "log", "log", "log", "log", "log", "log", ""],
["", "", "", "log", "planks", "planks", "planks", "planks", "planks", "log", ""],
["", "", "", "log", "planks", "planks", "planks", "planks", "planks", "log", ""],
["", "", "", "log", "planks", "planks", "planks", "planks", "planks", "log", ""],
["", "", "", "log", "log", "log", "log", "log", "log", "log", ""]
],
[
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "planks", "planks", "planks", "", "", "", ""],
["", "", "", "", "planks", "planks", "planks", "", "", "", ""],
["log", "planks", "planks", "log", "planks", "planks", "planks", "planks", "planks", "log", ""],
["planks", "air", "bookshelf", "bookshelf", "air", "air", "air", "air", "torch", "planks", ""],
["planks", "air", "air", "air", "air", "air", "air", "air", "air", "planks", ""],
["planks", "air", "air", "air", "air", "air", "air", "air", "air", "planks", ""],
["planks", "air", "air", "air", "air", "air", "air", "air", "air", "planks", ""],
["planks", "air", "air", "air", "air", "air", "air", "air", "torch", "planks", ""],
["log", "planks", "planks", "log", "planks", "planks", "planks", "planks", "planks", "log", ""],
["", "", "", "", "planks", "planks", "planks", "planks", "planks", "", ""],
["", "", "", "", "planks", "planks", "planks", "planks", "planks", "", ""],
["", "", "", "", "planks", "planks", "planks", "planks", "planks", "", ""],
["", "", "", "", "", "", "", "", "", "", ""]
],
[
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["log", "planks", "planks", "log", "glass", "glass", "glass", "glass", "glass", "log", ""],
["glass", "air", "bookshelf", "bookshelf", "air", "air", "air", "air", "air", "planks", ""],
["glass", "air", "air", "air", "air", "air", "air", "air", "air", "glass", ""],
["glass", "air", "air", "air", "air", "air", "air", "air", "air", "glass", ""],
["glass", "air", "air", "air", "air", "air", "air", "air", "air", "glass", ""],
["glass", "air", "air", "air", "air", "air", "air", "air", "air", "glass", ""],
["log", "planks", "planks", "log", "glass", "glass", "glass", "glass", "glass", "log", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""]
],
[
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["log", "planks", "planks", "log", "glass", "glass", "glass", "glass", "glass", "log", ""],
["glass", "air", "air", "torch", "air", "air", "air", "air", "air", "glass", ""],
["glass", "air", "air", "air", "air", "air", "air", "air", "air", "glass", ""],
["glass", "air", "air", "air", "air", "air", "air", "air", "air", "glass", ""],
["glass", "air", "air", "air", "air", "air", "air", "air", "air", "glass", ""],
["glass", "air", "air", "torch", "air", "air", "air", "air", "air", "glass", ""],
["log", "planks", "planks", "log", "glass", "glass", "glass", "glass", "glass", "log", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""]
],
[
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["log", "log", "log", "log", "log", "log", "log", "log", "log", "log", ""],
["log", "planks", "planks", "log", "planks", "planks", "planks", "planks", "planks", "log", ""],
["log", "planks", "planks", "log", "planks", "planks", "planks", "planks", "planks", "log", ""],
["log", "planks", "planks", "log", "planks", "planks", "planks", "planks", "planks", "log", ""],
["log", "planks", "planks", "log", "planks", "planks", "planks", "planks", "planks", "log", ""],
["log", "planks", "planks", "log", "planks", "planks", "planks", "planks", "planks", "log", ""],
["log", "log", "log", "log", "log", "log", "log", "log", "log", "log", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""]
],
[
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "planks", "planks", "planks", "planks", "planks", "", ""],
["", "", "", "", "planks", "planks", "planks", "planks", "planks", "", ""],
["", "", "", "", "planks", "planks", "planks", "planks", "planks", "", ""],
["", "", "", "", "planks", "planks", "planks", "planks", "planks", "", ""],
["", "", "", "", "planks", "planks", "planks", "planks", "planks", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""]
],
[
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "planks", "planks", "planks", "", "", ""],
["", "", "", "", "", "planks", "planks", "planks", "", "", ""],
["", "", "", "", "", "planks", "planks", "planks", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", "", "", "", ""]
]
]
}

View file

@ -0,0 +1,42 @@
{
"name": "small_stone_house",
"offset": -1,
"blocks": [
[
["", "", "", "", ""],
["", "planks", "planks", "planks", ""],
["", "planks", "planks", "planks", ""],
["", "planks", "planks", "planks", ""],
["", "planks", "planks", "planks", ""],
["", "", "planks", "", ""],
["", "", "", "", ""]
],
[
["cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone"],
["cobblestone", "chest", "bed", "air", "cobblestone"],
["cobblestone", "air", "bed", "air", "cobblestone"],
["cobblestone", "air", "air", "air", "cobblestone"],
["cobblestone", "air", "air", "air", "cobblestone"],
["cobblestone", "cobblestone", "door", "cobblestone", "cobblestone"],
["", "air", "air", "air", ""]
],
[
["cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone"],
["cobblestone", "torch", "air", "torch", "cobblestone"],
["cobblestone", "air", "air", "air", "cobblestone"],
["cobblestone", "air", "air", "air", "cobblestone"],
["cobblestone", "torch", "air", "torch", "cobblestone"],
["cobblestone", "cobblestone", "door", "cobblestone", "cobblestone"],
["", "air", "air", "air", ""]
],
[
["air", "air", "air", "air", "air"],
["air", "cobblestone", "cobblestone", "cobblestone", "air"],
["cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone"],
["cobblestone", "cobblestone", "cobblestone", "cobblestone", "cobblestone"],
["air", "cobblestone", "cobblestone", "cobblestone", "air"],
["air", "air", "air", "air", "air"],
["", "air", "air", "air", ""]
]
]
}

View file

@ -1,5 +1,5 @@
{ {
"name": "shelter", "name": "small_wood_house",
"offset": -1, "offset": -1,
"blocks": [ "blocks": [
[ [

View file

@ -16,6 +16,7 @@ export class NPCContoller {
this.item_goal = new ItemGoal(agent, this.data); this.item_goal = new ItemGoal(agent, this.data);
this.build_goal = new BuildGoal(agent); this.build_goal = new BuildGoal(agent);
this.constructions = {}; this.constructions = {};
this.last_goals = {};
} }
getBuiltPositions() { getBuiltPositions() {
@ -79,13 +80,33 @@ export class NPCContoller {
}); });
} }
async setGoal(name=null, quantity=1) {
this.last_goals = {};
if (name) {
this.data.curr_goal = {name: name, quantity: quantity};
return;
}
let past_goals = {...this.last_goals};
for (let goal in this.data.goals) {
if (past_goals[goal.name] === undefined) past_goals[goal.name] = true;
}
let res = await this.agent.prompter.promptGoalSetting(this.agent.history.getHistory(), past_goals);
if (res) {
this.data.curr_goal = res;
console.log('Set new goal: ', res.name, ' x', res.quantity);
} else {
console.log('Error setting new goal.');
}
}
async executeNext() { async executeNext() {
if (!this.agent.isIdle()) return; if (!this.agent.isIdle()) return;
await this.agent.coder.execute(async () => { await this.agent.coder.execute(async () => {
await skills.moveAway(this.agent.bot, 2); await skills.moveAway(this.agent.bot, 2);
}); });
if (this.agent.bot.time.timeOfDay < 13000) { if (!this.data.do_routine || this.agent.bot.time.timeOfDay < 13000) {
// Exit any buildings // Exit any buildings
let building = this.currentBuilding(); let building = this.currentBuilding();
if (building == this.data.home) { if (building == this.data.home) {
@ -102,6 +123,9 @@ export class NPCContoller {
await this.executeGoal(); await this.executeGoal();
} else { } else {
// Reset goal at the end of the day
this.data.curr_goal = null;
// Return to home // Return to home
let building = this.currentBuilding(); let building = this.currentBuilding();
if (this.data.home !== null && (building === null || building != this.data.home)) { if (this.data.home !== null && (building === null || building != this.data.home)) {
@ -124,14 +148,19 @@ export class NPCContoller {
async executeGoal() { async executeGoal() {
// If we need more blocks to complete a building, get those first // If we need more blocks to complete a building, get those first
let goals = this.temp_goals.concat(this.data.goals); let goals = this.temp_goals.concat(this.data.goals);
if (this.data.curr_goal)
goals = goals.concat([this.data.curr_goal])
this.temp_goals = []; this.temp_goals = [];
let acted = false;
for (let goal of goals) { for (let goal of goals) {
// Obtain goal item or block // Obtain goal item or block
if (this.constructions[goal.name] === undefined) { if (this.constructions[goal.name] === undefined) {
if (!itemSatisfied(this.agent.bot, goal.name, goal.quantity)) { if (!itemSatisfied(this.agent.bot, goal.name, goal.quantity)) {
await this.item_goal.executeNext(goal.name, goal.quantity); let res = await this.item_goal.executeNext(goal.name, goal.quantity);
this.last_goals[goal.name] = res;
acted = true;
break; break;
} }
} }
@ -162,9 +191,16 @@ export class NPCContoller {
quantity: res.missing[block_name] quantity: res.missing[block_name]
}) })
} }
if (res.acted) break; if (res.acted) {
acted = true;
this.last_goals[goal.name] = Object.keys(res.missing).length === 0;
break;
}
} }
} }
if (!acted && this.data.do_set_goal)
await this.setGoal();
} }
currentBuilding() { currentBuilding() {

View file

@ -1,18 +1,25 @@
export class NPCData { export class NPCData {
constructor() { constructor() {
this.goals = []; this.goals = [];
this.curr_goal = null;
this.built = {}; this.built = {};
this.home = null; this.home = null;
this.do_routine = true;
this.do_set_goal = true;
} }
toObject() { toObject() {
let obj = {}; let obj = {};
if (this.goals.length > 0) if (this.goals.length > 0)
obj.goals = this.goals; obj.goals = this.goals;
if (this.curr_goal)
obj.curr_goal = this.curr_goal;
if (Object.keys(this.built).length > 0) if (Object.keys(this.built).length > 0)
obj.built = this.built; obj.built = this.built;
if (this.home) if (this.home)
obj.home = this.home; obj.home = this.home;
obj.do_routine = this.do_routine;
obj.do_set_goal = this.do_set_goal;
return obj; return obj;
} }
@ -28,10 +35,16 @@ export class NPCData {
npc.goals.push({name: goal.name, quantity: goal.quantity}); npc.goals.push({name: goal.name, quantity: goal.quantity});
} }
} }
if (obj.curr_goal)
npc.curr_goal = obj.curr_goal;
if (obj.built) if (obj.built)
npc.built = obj.built; npc.built = obj.built;
if (obj.home) if (obj.home)
npc.home = obj.home; npc.home = obj.home;
if (obj.do_routine !== undefined)
npc.do_routine = obj.do_routine;
if (obj.do_set_goal !== undefined)
npc.do_set_goal = obj.do_set_goal;
return npc; return npc;
} }
} }

View file

@ -309,7 +309,7 @@ export class ItemGoal {
let next_info = this.goal.getNext(item_quantity); let next_info = this.goal.getNext(item_quantity);
if (!next_info) { if (!next_info) {
console.log(`Invalid item goal ${this.goal.name}`); console.log(`Invalid item goal ${this.goal.name}`);
return; return false;
} }
let next = next_info.node; let next = next_info.node;
let quantity = next_info.quantity; let quantity = next_info.quantity;
@ -330,12 +330,12 @@ export class ItemGoal {
await new Promise((resolve) => setTimeout(resolve, 500)); await new Promise((resolve) => setTimeout(resolve, 500));
this.agent.bot.emit('idle'); this.agent.bot.emit('idle');
} }
return; return false;
} }
// Wait for the bot to be idle before attempting to execute the next goal // Wait for the bot to be idle before attempting to execute the next goal
if (!this.agent.isIdle()) if (!this.agent.isIdle())
return; return false;
// Execute the next goal // Execute the next goal
let init_quantity = world.getInventoryCounts(this.agent.bot)[next.name] || 0; let init_quantity = world.getInventoryCounts(this.agent.bot)[next.name] || 0;
@ -350,5 +350,6 @@ export class ItemGoal {
} else { } else {
console.log(`Failed to obtain ${next.name} for goal ${this.goal.name}`); console.log(`Failed to obtain ${next.name} for goal ${this.goal.name}`);
} }
return final_quantity > init_quantity;
} }
} }

View file

@ -48,7 +48,7 @@ export class Prompter {
console.log('Examples loaded.'); console.log('Examples loaded.');
} }
async replaceStrings(prompt, messages, examples=null, prev_memory=null, to_summarize=[]) { async replaceStrings(prompt, messages, examples=null, prev_memory=null, to_summarize=[], last_goals=null) {
prompt = prompt.replaceAll('$NAME', this.agent.name); prompt = prompt.replaceAll('$NAME', this.agent.name);
if (prompt.includes('$STATS')) { if (prompt.includes('$STATS')) {
@ -69,6 +69,27 @@ export class Prompter {
prompt = prompt.replaceAll('$MEMORY', prev_memory ? prev_memory : 'None.'); prompt = prompt.replaceAll('$MEMORY', prev_memory ? prev_memory : 'None.');
if (prompt.includes('$TO_SUMMARIZE')) if (prompt.includes('$TO_SUMMARIZE'))
prompt = prompt.replaceAll('$TO_SUMMARIZE', stringifyTurns(to_summarize)); prompt = prompt.replaceAll('$TO_SUMMARIZE', stringifyTurns(to_summarize));
if (prompt.includes('$CONVO'))
prompt = prompt.replaceAll('$CONVO', 'Recent conversation:\n' + stringifyTurns(messages));
if (prompt.includes('$LAST_GOALS')) {
let goal_text = '';
for (let goal in last_goals) {
if (last_goals[goal])
goal_text += `You recently successfully completed the goal ${goal}.\n`
else
goal_text += `You recently failed to complete the goal ${goal}.\n`
}
prompt = prompt.replaceAll('$LAST_GOALS', goal_text.trim());
}
if (prompt.includes('$BLUEPRINTS')) {
if (this.agent.npc.constructions) {
let blueprints = '';
for (let blueprint in this.agent.npc.constructions) {
blueprints += blueprint + ', ';
}
prompt = prompt.replaceAll('$BLUEPRINTS', blueprints.slice(0, -2));
}
}
// check if there are any remaining placeholders with syntax $<word> // check if there are any remaining placeholders with syntax $<word>
let remaining = prompt.match(/\$[A-Z_]+/g); let remaining = prompt.match(/\$[A-Z_]+/g);
@ -95,4 +116,30 @@ export class Prompter {
prompt = await this.replaceStrings(prompt, null, null, prev_mem, to_summarize); prompt = await this.replaceStrings(prompt, null, null, prev_mem, to_summarize);
return await this.model.sendRequest([], prompt); return await this.model.sendRequest([], prompt);
} }
async promptGoalSetting(messages, last_goals) {
let system_message = this.prompts.goal_setting;
system_message = await this.replaceStrings(system_message, messages);
let user_message = 'Use the below info to determine what goal to target next\n\n';
user_message += '$LAST_GOALS\n$STATS\n$INVENTORY\n$CONVO'
user_message = await this.replaceStrings(user_message, messages, null, null, null, last_goals);
let user_messages = [{role: 'user', content: user_message}];
let res = await this.model.sendRequest(user_messages, system_message);
let goal = null;
try {
let data = res.split('```')[1].replace('json', '').trim();
goal = JSON.parse(data);
} catch (err) {
console.log('Failed to parse goal:', res, err);
}
if (!goal || !goal.name || !goal.quantity || isNaN(parseInt(goal.quantity))) {
console.log('Failed to set goal:', res);
return null;
}
goal.quantity = parseInt(goal.quantity);
return goal;
}
} }