prompted goals init

This commit is contained in:
Kolby Nottingham 2024-04-23 20:47:01 -07:00
parent 23c5d50ed8
commit 4fd6aa2021
6 changed files with 66 additions and 7 deletions

View file

@ -9,6 +9,8 @@
"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}\n```",
"npc": { "npc": {
"goals": [ "goals": [
"wooden_pickaxe", "wooden_pickaxe",

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.';
} }
}, },
@ -196,5 +197,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

@ -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,29 @@ export class NPCContoller {
}); });
} }
setGoal(name=null, quantity=1) {
this.last_goals = {};
if (name) {
this.data.curr_goal = {name: name, quantity: quantity};
return;
}
let res = this.agent.prompter.promptGoalSetting(this.agent.history.getHistory(), this.last_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) {
@ -123,15 +140,18 @@ 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).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,11 +182,19 @@ 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.setGoal();
}
}
currentBuilding() { currentBuilding() {
let bot_pos = this.agent.bot.entity.position; let bot_pos = this.agent.bot.entity.position;
for (let name in this.data.built) { for (let name in this.data.built) {

View file

@ -1,18 +1,23 @@
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;
} }
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;
return obj; return obj;
} }
@ -28,10 +33,14 @@ 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;
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

@ -95,4 +95,9 @@ 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) {
// TODO
return {name: '', quantity: 0};
}
} }