mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-07-03 07:05:20 +02:00
prompted goals init
This commit is contained in:
parent
23c5d50ed8
commit
4fd6aa2021
6 changed files with 66 additions and 7 deletions
|
@ -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: ",
|
||||
|
||||
"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": {
|
||||
"goals": [
|
||||
"wooden_pickaxe",
|
||||
|
|
|
@ -36,6 +36,7 @@ export const actionsList = [
|
|||
await agent.coder.stop();
|
||||
agent.coder.clear();
|
||||
agent.coder.cancelResume();
|
||||
agent.bot.emit('idle');
|
||||
return 'Agent stopped.';
|
||||
}
|
||||
},
|
||||
|
@ -196,5 +197,18 @@ export const actionsList = [
|
|||
perform: wrapExecution(async (agent) => {
|
||||
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;
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
|
@ -16,6 +16,7 @@ export class NPCContoller {
|
|||
this.item_goal = new ItemGoal(agent, this.data);
|
||||
this.build_goal = new BuildGoal(agent);
|
||||
this.constructions = {};
|
||||
this.last_goals = {};
|
||||
}
|
||||
|
||||
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() {
|
||||
if (!this.agent.isIdle()) return;
|
||||
await this.agent.coder.execute(async () => {
|
||||
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
|
||||
let building = this.currentBuilding();
|
||||
if (building == this.data.home) {
|
||||
|
@ -123,15 +140,18 @@ export class NPCContoller {
|
|||
|
||||
async executeGoal() {
|
||||
// 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 = [];
|
||||
|
||||
let acted = false;
|
||||
for (let goal of goals) {
|
||||
|
||||
// Obtain goal item or block
|
||||
if (this.constructions[goal.name] === undefined) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -162,9 +182,17 @@ export class NPCContoller {
|
|||
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() {
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
export class NPCData {
|
||||
constructor() {
|
||||
this.goals = [];
|
||||
this.curr_goal = null;
|
||||
this.built = {};
|
||||
this.home = null;
|
||||
this.do_routine = true;
|
||||
}
|
||||
|
||||
toObject() {
|
||||
let obj = {};
|
||||
if (this.goals.length > 0)
|
||||
obj.goals = this.goals;
|
||||
if (this.curr_goal)
|
||||
obj.curr_goal = this.curr_goal;
|
||||
if (Object.keys(this.built).length > 0)
|
||||
obj.built = this.built;
|
||||
if (this.home)
|
||||
obj.home = this.home;
|
||||
obj.do_routine = this.do_routine;
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -28,10 +33,14 @@ export class NPCData {
|
|||
npc.goals.push({name: goal.name, quantity: goal.quantity});
|
||||
}
|
||||
}
|
||||
if (obj.curr_goal)
|
||||
npc.curr_goal = obj.curr_goal;
|
||||
if (obj.built)
|
||||
npc.built = obj.built;
|
||||
if (obj.home)
|
||||
npc.home = obj.home;
|
||||
if (obj.do_routine !== undefined)
|
||||
npc.do_routine = obj.do_routine;
|
||||
return npc;
|
||||
}
|
||||
}
|
|
@ -309,7 +309,7 @@ export class ItemGoal {
|
|||
let next_info = this.goal.getNext(item_quantity);
|
||||
if (!next_info) {
|
||||
console.log(`Invalid item goal ${this.goal.name}`);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
let next = next_info.node;
|
||||
let quantity = next_info.quantity;
|
||||
|
@ -330,12 +330,12 @@ export class ItemGoal {
|
|||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
this.agent.bot.emit('idle');
|
||||
}
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wait for the bot to be idle before attempting to execute the next goal
|
||||
if (!this.agent.isIdle())
|
||||
return;
|
||||
return false;
|
||||
|
||||
// Execute the next goal
|
||||
let init_quantity = world.getInventoryCounts(this.agent.bot)[next.name] || 0;
|
||||
|
@ -350,5 +350,6 @@ export class ItemGoal {
|
|||
} else {
|
||||
console.log(`Failed to obtain ${next.name} for goal ${this.goal.name}`);
|
||||
}
|
||||
return final_quantity > init_quantity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,4 +95,9 @@ export class Prompter {
|
|||
prompt = await this.replaceStrings(prompt, null, null, prev_mem, to_summarize);
|
||||
return await this.model.sendRequest([], prompt);
|
||||
}
|
||||
|
||||
async promptGoalSetting(messages, last_goals) {
|
||||
// TODO
|
||||
return {name: '', quantity: 0};
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue