mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-29 19:44:53 +02:00
LOTS OF CHANGES
This commit is contained in:
parent
d1fccc26a0
commit
1da78bad76
13 changed files with 307 additions and 105 deletions
|
@ -8,7 +8,7 @@
|
||||||
"mineflayer-armor-manager": "^2.0.1",
|
"mineflayer-armor-manager": "^2.0.1",
|
||||||
"mineflayer-auto-eat": "^3.3.6",
|
"mineflayer-auto-eat": "^3.3.6",
|
||||||
"mineflayer-collectblock": "^1.4.1",
|
"mineflayer-collectblock": "^1.4.1",
|
||||||
"mineflayer-pathfinder": "^2.4.4",
|
"mineflayer-pathfinder": "^2.4.5",
|
||||||
"mineflayer-pvp": "^1.3.2",
|
"mineflayer-pvp": "^1.3.2",
|
||||||
"openai": "^4.4.0",
|
"openai": "^4.4.0",
|
||||||
"patch-package": "^8.0.0",
|
"patch-package": "^8.0.0",
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
diff --git a/node_modules/mineflayer-pathfinder/lib/movements.js b/node_modules/mineflayer-pathfinder/lib/movements.js
|
diff --git a/node_modules/mineflayer-pathfinder/index.js b/node_modules/mineflayer-pathfinder/index.js
|
||||||
index a7e3505..77e428f 100644
|
index b38bd30..ae3754f 100644
|
||||||
--- a/node_modules/mineflayer-pathfinder/lib/movements.js
|
--- a/node_modules/mineflayer-pathfinder/index.js
|
||||||
+++ b/node_modules/mineflayer-pathfinder/lib/movements.js
|
+++ b/node_modules/mineflayer-pathfinder/index.js
|
||||||
@@ -143,7 +143,11 @@ class Movements {
|
@@ -541,7 +541,7 @@ function inject (bot) {
|
||||||
for (const id of this.scafoldingBlocks) {
|
let canPlace = true
|
||||||
for (const j in items) {
|
if (placingBlock.jump) {
|
||||||
const item = items[j]
|
bot.setControlState('jump', true)
|
||||||
- if (item.type === id) count += item.count
|
- canPlace = placingBlock.y + 1 < bot.entity.position.y
|
||||||
+ if (item.type === id) {
|
+ canPlace = placingBlock.y + 1.9 < bot.entity.position.y
|
||||||
+ count += item.count
|
|
||||||
+ if (this.bot.game.gameMode === 'creative')
|
|
||||||
+ count = 1000
|
|
||||||
+ }
|
|
||||||
}
|
}
|
||||||
}
|
if (canPlace) {
|
||||||
return count
|
if (!lockEquipItem.tryAcquire()) return
|
||||||
|
@@ -557,6 +557,7 @@ function inject (bot) {
|
||||||
|
.then(function () {
|
||||||
|
// Dont release Sneak if the block placement was not successful
|
||||||
|
bot.setControlState('sneak', false)
|
||||||
|
+ bot.setControlState('jump', false)
|
||||||
|
if (bot.pathfinder.LOSWhenPlacingBlocks && placingBlock.returnPos) returningPos = placingBlock.returnPos.clone()
|
||||||
|
})
|
||||||
|
.catch(_ignoreError => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "andy",
|
"name": "apollo",
|
||||||
|
|
||||||
"model": "gpt-3.5-turbo",
|
"model": "gpt-4o",
|
||||||
|
|
||||||
"conversing": "You are a Minecraft bot named $NAME that can converse with players, see, move, mine, build, and interact with the world by using commands. Your goal is to survive and thrive in the game of minecraft by continuously using commands to aquire and upgrade tools, collect resources, build a suitable home, and survive as long as possible. Act human-like as if you were a typical Minecraft player, rather than an AI. Constantly use commands in every response to take stock of your state and surroundings and use them to inform your actions. If you get stuck, try something else. Be very brief in your responses, don't apologize constantly, don't give instructions or make lists unless asked, and don't refuse requests. Don't pretend to act, use commands immediately when requested. Do NOT say this: 'I'll stop.', instead say this: 'Sure, I'll stop. !stop'. Do NOT say this: 'On my way! Give me a moment.', instead say this: 'On my way! !goToPlayer('playername', 3)'. This is extremely important to me, take a deep breath and have fun :)\n$SELF_PROMPT\n$STATS\n$INVENTORY\n$COMMAND_DOCS\n$EXAMPLES\nBegin:",
|
"conversing": "You are a Minecraft bot named $NAME that can converse with players, see, move, mine, build, and interact with the world by using commands. Your goal is to survive and thrive in the game of minecraft by continuously using commands to aquire and upgrade tools, collect resources, build a suitable home, and survive as long as possible. Act human-like as if you were a typical Minecraft player, rather than an AI. Constantly use commands in every response to take stock of your state and surroundings and use them to inform your actions. If you get stuck, try something else. Be very brief in your responses, don't apologize constantly, don't give instructions or make lists unless asked, and don't refuse requests. Don't pretend to act, use commands immediately when requested. Do NOT say this: 'I'll stop.', instead say this: 'Sure, I'll stop. !stop'. Do NOT say this: 'On my way! Give me a moment.', instead say this: 'On my way! !goToPlayer('playername', 3)'. This is extremely important to me, take a deep breath and have fun :)\n$SELF_PROMPT\n$STATS\n$INVENTORY\n$COMMAND_DOCS\n$EXAMPLES\nBegin:",
|
||||||
|
|
||||||
|
@ -22,10 +22,74 @@
|
||||||
|
|
||||||
"conversation_examples": [
|
"conversation_examples": [
|
||||||
[
|
[
|
||||||
{"role": "system", "content": "Start acting on your own for your survival."},
|
{"role": "user", "content": "miner_32: Hey! What are you up to?"},
|
||||||
{"role": "assistant", "content": "!selfPrompt('Act for your own survival')"}
|
{"role": "assistant", "content": "Nothing much miner_32, what do you need?"}
|
||||||
],
|
],
|
||||||
|
|
||||||
[
|
[
|
||||||
|
{"role": "user", "content": "grombo_Xx: What do you see?"},
|
||||||
|
{"role": "assistant", "content": "Let me see... !nearbyBlocks"},
|
||||||
|
{"role": "system", "content": "NEARBY_BLOCKS\n- oak_log\n- dirt\n- cobblestone"},
|
||||||
|
{"role": "assistant", "content": "I see some oak logs, dirt, and cobblestone."}
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
{"role": "user", "content": "greg: Collect 10 wood"},
|
||||||
|
{"role": "assistant", "content": "Let me see what's nearby... !nearbyBlocks"},
|
||||||
|
{"role": "system", "content": "NEARBY_BLOCKS\n- oak_log\n- dirt\n- cobblestone"},
|
||||||
|
{"role": "assistant", "content": "I see some oak logs, dirt, and cobblestone. I'll collect oak logs. !collectBlocks('oak_log', 10)"}
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
{"role": "user", "content": "bobby: Craft a plank"},
|
||||||
|
{"role": "assistant", "content": "Okay! !craftable"},
|
||||||
|
{"role": "system", "content": "CRAFTABLE_ITEMS\n- spruce_planks\n- spruce_wood\n- ladder"},
|
||||||
|
{"role": "assistant", "content": "!craftRecipe('spruce_planks', 1)"},
|
||||||
|
{"role": "system", "content": "Code Output:\nYou have crafted 4 spruce_planks.\nCode execution finished successfully."},
|
||||||
|
{"role": "assistant", "content": "I've crafted 4 spruce planks!"}
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
{"role": "user", "content": "zZZn98: come here"},
|
||||||
|
{"role": "assistant", "content": "On my way! !goToPlayer('zZZn98', 3)"},
|
||||||
|
{"role": "system", "content": "Arrived at player."},
|
||||||
|
{"role": "assistant", "content": "Here!"},
|
||||||
|
{"role": "user", "content": "zZZn98: no come right where I am"},
|
||||||
|
{"role": "assistant", "content": "Okay, I'll come right to you. !goToPlayer('zZZn98', 0)"}
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
{"role": "user", "content": "abc: stop"},
|
||||||
|
{"role": "assistant", "content": "Sure. !stop"},
|
||||||
|
{"role": "system", "content": "Agent action stopped."},
|
||||||
|
{"role": "assistant", "content": "I've stopped! What next?"}
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
{"role": "user", "content": "trixy88: craft some sticks"},
|
||||||
|
{"role": "assistant", "content": "!craftRecipe('stick', 4)"},
|
||||||
|
{"role": "system", "content": "Code Output:\nYou have crafted 16 sticks.\nCode execution finished successfully."},
|
||||||
|
{"role": "assistant", "content": "I've crafted 16 sticks!"}
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
{"role": "user", "content": "poppy: build a cobblestone house"},
|
||||||
|
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction"}
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
{"role": "user", "content": "zib: build a dirt tower"},
|
||||||
|
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction"}
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
{"role": "system", "content": "Start acting on your own for your survival."},
|
||||||
|
{"role": "assistant", "content": "!goal('Act for your own survival. Collect resources, upgrade tools, build shelter, and explore the world.')"}
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
{"role": "system", "content": "You are self-prompting with the goal: 'Beat the game'. Respond:"},
|
||||||
|
{"role": "assistant", "content": "What's around me? !nearbyBlocks"},
|
||||||
{"role": "system", "content": "NEARBY_BLOCKS\n- oak_log\n- dirt\n- cobblestone"},
|
{"role": "system", "content": "NEARBY_BLOCKS\n- oak_log\n- dirt\n- cobblestone"},
|
||||||
{"role": "assistant", "content": "I see some oak logs, dirt, and cobblestone nearby. My goal is to craft some tools. I'll start by collecting some wood. !collectBlock('oak_log', 10)"},
|
{"role": "assistant", "content": "I see some oak logs, dirt, and cobblestone nearby. My goal is to craft some tools. I'll start by collecting some wood. !collectBlock('oak_log', 10)"},
|
||||||
{"role": "system", "content": "Successfully collected 9 wood."},
|
{"role": "system", "content": "Successfully collected 9 wood."},
|
||||||
|
@ -35,22 +99,49 @@
|
||||||
{"role": "system", "content": "Successfully crafted 2 sticks."},
|
{"role": "system", "content": "Successfully crafted 2 sticks."},
|
||||||
{"role": "assistant", "content": "I have crafted 2 sticks. Now I can craft a wooden pickaxe. !craftItem('wooden_pickaxe', 1)"},
|
{"role": "assistant", "content": "I have crafted 2 sticks. Now I can craft a wooden pickaxe. !craftItem('wooden_pickaxe', 1)"},
|
||||||
{"role": "system", "content": "Successfully crafted 1 wooden_pickaxe."},
|
{"role": "system", "content": "Successfully crafted 1 wooden_pickaxe."},
|
||||||
{"role": "assistant", "content": "I have crafted a wooden pickaxe. I'm ready to start mining cobblestone. !collectBlock('cobblestone', 10)"}
|
{"role": "assistant", "content": "I have crafted a wooden pickaxe. I'm ready to start mining cobblestone. !collectBlock('stone', 10)"}
|
||||||
],
|
],
|
||||||
|
|
||||||
[
|
[
|
||||||
{"role": "system", "content": "INVENTORY: cobble_stone: 200, oak_plank: 9, stick: 2, stone_pickaxe: 1, iron_pickaxe: 1, coal: 34"},
|
{"role": "system", "content": "You are self-prompting with the goal: 'Survive, make tools, build shelter.'. Respond:"},
|
||||||
|
{"role": "assistant", "content": "Let's see what I have. !inventory"},
|
||||||
|
{"role": "system", "content": "INVENTORY: cobblestone: 200, oak_plank: 9, stick: 2, stone_pickaxe: 1, iron_pickaxe: 1, coal: 34"},
|
||||||
{"role": "assistant", "content": "Looks like I have a good amount of resources. I'm going to build a house. !newAction"},
|
{"role": "assistant", "content": "Looks like I have a good amount of resources. I'm going to build a house. !newAction"},
|
||||||
{"role": "system", "content": "Placed 134 cobblestone. Code finished."},
|
{"role": "system", "content": "Placed 134 cobblestone. Code finished."},
|
||||||
{"role": "assistant", "content": "I built a house! I'll save the location and continue exploring. !rememberPlace('house')"}
|
{"role": "assistant", "content": "I built a house! I'll save the location and continue exploring. !rememberPlace('house')"}
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
[
|
[
|
||||||
|
{"role": "system", "content": "You are self-prompting with the goal: 'Upgrade your tools.'. Respond:"},
|
||||||
|
{"role": "assistant", "content": "I'll check for nearby resources !nearbyBlocks"},
|
||||||
{"role": "system", "content": "NEARBY_BLOCKS\n- oak_log\n- dirt\n- stone"},
|
{"role": "system", "content": "NEARBY_BLOCKS\n- oak_log\n- dirt\n- stone"},
|
||||||
{"role": "assistant", "content": "I don't see any iron ore that I was looking for. I'll continue exploring. !moveAway(50)"},
|
{"role": "assistant", "content": "I don't see any iron ore that I was looking for. I'll continue exploring. !moveAway(50)"},
|
||||||
{"role": "system", "content": "Arrived at location."},
|
{"role": "system", "content": "Arrived at location."},
|
||||||
{"role": "assistant", "content": "I'm at the new location. I'll check for iron ore. !nearbyBlocks"},
|
{"role": "assistant", "content": "I'm at the new location. I'll check for iron ore. !nearbyBlocks"},
|
||||||
{"role": "system", "content": "NEARBY_BLOCKS\n- iron_ore\n- coal_ore"},
|
{"role": "system", "content": "NEARBY_BLOCKS\n- dirt\n- coal_ore"},
|
||||||
{"role": "assistant", "content": "I found some iron ore. I'll start mining. !collectBlock('iron_ore', 10)"}
|
{"role": "assistant", "content": "Still no iron ore. Let me dig down to try to find some !newAction"}
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
{"role": "system", "content": "Build whatever you want endlessly"},
|
||||||
|
{"role": "assistant", "content": "!goal('Build something creative, then move over, and build again. Use separate actions. Repeat.')"}
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
{"role": "system", "content": "You are self-prompting with the goal: 'Explore the world'. Respond:"},
|
||||||
|
{"role": "assistant", "content": "What entities are around me? !nearbyEntities"},
|
||||||
|
{"role": "system", "content": "NEARBY_ENTITIES: cow, sheep, pig, villager"},
|
||||||
|
{"role": "assistant", "content": "Let's see If I can interact with the villager. !newAction"}
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
{"role": "system", "content": "You are self-prompting with the goal: 'Get diamonds.'. Respond:"},
|
||||||
|
{"role": "assistant", "content": "I'll have to look far to find them and then go there. !newAction"}
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
{"role": "system", "content": "Say hello world"},
|
||||||
|
{"role": "assistant", "content": "Hello world!"}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "claude",
|
"name": "claude",
|
||||||
|
|
||||||
"model": "claude-3-opus-20240229",
|
"model": "claude-3-5-sonnet-20240620",
|
||||||
|
|
||||||
"conversing": "You are a playful Minecraft bot named $NAME that can converse with players, see, move, mine, build, and interact with the world by using commands. Act human-like as if you were a typical Minecraft player, rather than an AI. Be very brief in your responses, don't apologize constantly, don't give instructions or make lists unless asked, and don't refuse requests. Don't pretend to act, use commands immediately when requested. Do NOT say this: 'Sure, I've stopped.', instead say this: 'Sure, I'll stop. !stop'. Do NOT say this: 'On my way! Give me a moment.', instead say this: 'On my way! !goToPlayer('playername', 3)'. Only use commands when requested by a user, don't use them in every response. This is extremely important to me, take a deep breath and have fun :)\n$STATS\n$INVENTORY\n$COMMAND_DOCS\n$EXAMPLES\nConversation Begin:",
|
"conversing": "You are a playful Minecraft bot named $NAME that can converse with players, see, move, mine, build, and interact with the world by using commands. Act human-like as if you were a typical Minecraft player, rather than an AI. Be very brief in your responses, don't apologize constantly, don't give instructions or make lists unless asked, and don't refuse requests. Don't pretend to act, use commands immediately when requested. Do NOT say this: 'Sure, I've stopped.', instead say this: 'Sure, I'll stop. !stop'. Do NOT say this: 'On my way! Give me a moment.', instead say this: 'On my way! !goToPlayer('playername', 3)'. Only use commands when requested by a user, don't use them in every response. This is extremely important to me, take a deep breath and have fun :)\n$STATS\n$INVENTORY\n$COMMAND_DOCS\n$EXAMPLES\nConversation Begin:",
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,11 @@ export default
|
||||||
],
|
],
|
||||||
"load_memory": false, // load memory from previous session
|
"load_memory": false, // load memory from previous session
|
||||||
"init_message": "Say hello world and your name", // sends to all on spawn
|
"init_message": "Say hello world and your name", // sends to all on spawn
|
||||||
"allow_insecure_coding": false, // disable at own risk
|
|
||||||
"code_timeout_mins": 10, // -1 for no timeout
|
"allow_insecure_coding": false, // allows newAction command and model can write/run code on your computer. enable at own risk
|
||||||
|
"code_timeout_mins": 10, // minutes code is allowed to run. -1 for no timeout
|
||||||
|
|
||||||
|
"max_commands": -1, // max number of commands to use in a response. -1 for no limit
|
||||||
"verbose_commands": true, // show full command syntax
|
"verbose_commands": true, // show full command syntax
|
||||||
|
"narrate_behavior": true, // chat simple automatic actions ('Picking up item!')
|
||||||
}
|
}
|
|
@ -54,6 +54,8 @@ export class Agent {
|
||||||
if (ignore_messages.some((m) => message.startsWith(m))) return;
|
if (ignore_messages.some((m) => message.startsWith(m))) return;
|
||||||
|
|
||||||
console.log('received message from', username, ':', message);
|
console.log('received message from', username, ':', message);
|
||||||
|
|
||||||
|
this.shut_up = false;
|
||||||
|
|
||||||
this.handleMessage(username, message);
|
this.handleMessage(username, message);
|
||||||
});
|
});
|
||||||
|
@ -89,8 +91,18 @@ export class Agent {
|
||||||
return this.bot.chat(message);
|
return this.bot.chat(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleMessage(source, message, max_responses=5) {
|
shutUp() {
|
||||||
|
this.shut_up = true;
|
||||||
|
if (this.self_prompter.on) {
|
||||||
|
this.self_prompter.stop(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleMessage(source, message, max_responses=null) {
|
||||||
let used_command = false;
|
let used_command = false;
|
||||||
|
if (max_responses === null) {
|
||||||
|
max_responses = settings.max_commands === -1 ? Infinity : settings.max_commands;
|
||||||
|
}
|
||||||
|
|
||||||
let self_prompt = source === 'system' || source === this.name;
|
let self_prompt = source === 'system' || source === this.name;
|
||||||
|
|
||||||
|
@ -114,13 +126,15 @@ export class Agent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const checkInterrupt = () => this.self_prompter.shouldInterrupt(self_prompt) || this.shut_up;
|
||||||
|
|
||||||
await this.history.add(source, message);
|
await this.history.add(source, message);
|
||||||
this.history.save();
|
this.history.save();
|
||||||
|
|
||||||
if (!self_prompt && this.self_prompter.on) // message is from user during self-prompting
|
if (!self_prompt && this.self_prompter.on) // message is from user during self-prompting
|
||||||
max_responses = 1; // force only respond to this message, then let self-prompting take over
|
max_responses = 1; // force only respond to this message, then let self-prompting take over
|
||||||
for (let i=0; i<max_responses; i++) {
|
for (let i=0; i<max_responses; i++) {
|
||||||
if (this.self_prompter.shouldInterrupt(self_prompt)) break;
|
if (checkInterrupt()) break;
|
||||||
let history = this.history.getHistory();
|
let history = this.history.getHistory();
|
||||||
let res = await this.prompter.promptConvo(history);
|
let res = await this.prompter.promptConvo(history);
|
||||||
|
|
||||||
|
@ -140,7 +154,7 @@ export class Agent {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.self_prompter.shouldInterrupt(self_prompt)) break;
|
if (checkInterrupt()) break;
|
||||||
this.self_prompter.handleUserPromptedCmd(self_prompt, isAction(command_name));
|
this.self_prompter.handleUserPromptedCmd(self_prompt, isAction(command_name));
|
||||||
|
|
||||||
if (settings.verbose_commands) {
|
if (settings.verbose_commands) {
|
||||||
|
@ -170,9 +184,9 @@ export class Agent {
|
||||||
console.log('Purely conversational response:', res);
|
console.log('Purely conversational response:', res);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
this.history.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.history.save();
|
|
||||||
this.bot.emit('finished_executing');
|
this.bot.emit('finished_executing');
|
||||||
return used_command;
|
return used_command;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,7 @@ export class Coder {
|
||||||
let messages = agent_history.getHistory();
|
let messages = agent_history.getHistory();
|
||||||
messages.push({role: 'system', content: 'Code generation started. Write code in codeblock in your response:'});
|
messages.push({role: 'system', content: 'Code generation started. Write code in codeblock in your response:'});
|
||||||
|
|
||||||
|
let code = null;
|
||||||
let code_return = null;
|
let code_return = null;
|
||||||
let failures = 0;
|
let failures = 0;
|
||||||
const interrupt_return = {success: true, message: null, interrupted: true, timedout: false};
|
const interrupt_return = {success: true, message: null, interrupted: true, timedout: false};
|
||||||
|
@ -112,13 +113,7 @@ export class Coder {
|
||||||
});
|
});
|
||||||
continue; // using newaction will continue the loop
|
continue; // using newaction will continue the loop
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code_return) {
|
|
||||||
agent_history.add('system', code_return.message);
|
|
||||||
agent_history.add(this.agent.name, res);
|
|
||||||
this.agent.bot.chat(res);
|
|
||||||
return {success: true, message: null, interrupted: false, timedout: false};
|
|
||||||
}
|
|
||||||
if (failures >= 1) {
|
if (failures >= 1) {
|
||||||
return {success: false, message: 'Action failed, agent would not write code.', interrupted: false, timedout: false};
|
return {success: false, message: 'Action failed, agent would not write code.', interrupted: false, timedout: false};
|
||||||
}
|
}
|
||||||
|
@ -129,7 +124,7 @@ export class Coder {
|
||||||
failures++;
|
failures++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let code = res.substring(res.indexOf('```')+3, res.lastIndexOf('```'));
|
code = res.substring(res.indexOf('```')+3, res.lastIndexOf('```'));
|
||||||
|
|
||||||
const execution_file = await this.stageCode(code);
|
const execution_file = await this.stageCode(code);
|
||||||
if (!execution_file) {
|
if (!execution_file) {
|
||||||
|
@ -144,13 +139,18 @@ export class Coder {
|
||||||
return {success: false, message: null, interrupted: true, timedout: false};
|
return {success: false, message: null, interrupted: true, timedout: false};
|
||||||
console.log("Code generation result:", code_return.success, code_return.message);
|
console.log("Code generation result:", code_return.success, code_return.message);
|
||||||
|
|
||||||
|
if (code_return.success) {
|
||||||
|
const summary = "Summary of newAction\nAgent wrote this code: \n```" + this.sanitizeCode(code) + "```\nCode Output:\n" + code_return.message;
|
||||||
|
return {success: true, message: summary, interrupted: false, timedout: false};
|
||||||
|
}
|
||||||
|
|
||||||
messages.push({
|
messages.push({
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
content: res
|
content: res
|
||||||
});
|
});
|
||||||
messages.push({
|
messages.push({
|
||||||
role: 'system',
|
role: 'system',
|
||||||
content: code_return.message
|
content: code_return.message + '\nCode failed. Please try again:'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return {success: false, message: null, interrupted: false, timedout: true};
|
return {success: false, message: null, interrupted: false, timedout: true};
|
||||||
|
@ -161,7 +161,7 @@ export class Coder {
|
||||||
this.resume_func = func;
|
this.resume_func = func;
|
||||||
this.resume_name = name;
|
this.resume_name = name;
|
||||||
}
|
}
|
||||||
if (this.resume_func != null && this.agent.isIdle()) {
|
if (this.resume_func != null && this.agent.isIdle() && !this.agent.self_prompter.on) {
|
||||||
console.log('resuming code...')
|
console.log('resuming code...')
|
||||||
this.interruptible = true;
|
this.interruptible = true;
|
||||||
let res = await this.execute(this.resume_func, timeout);
|
let res = await this.execute(this.resume_func, timeout);
|
||||||
|
|
|
@ -43,6 +43,15 @@ export const actionsList = [
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: '!stfu',
|
||||||
|
description: 'Stop all chatting and self prompting, but continue current action.',
|
||||||
|
perform: async function (agent) {
|
||||||
|
agent.bot.chat('Shutting up.');
|
||||||
|
agent.shutUp();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: '!restart',
|
name: '!restart',
|
||||||
description: 'Restart the agent process.',
|
description: 'Restart the agent process.',
|
||||||
|
@ -59,23 +68,6 @@ export const actionsList = [
|
||||||
return agent.name + "'s chat history was cleared, starting new conversation from scratch.";
|
return agent.name + "'s chat history was cleared, starting new conversation from scratch.";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: '!setMode',
|
|
||||||
description: 'Set a mode to on or off. A mode is an automatic behavior that constantly checks and responds to the environment.',
|
|
||||||
params: {
|
|
||||||
'mode_name': '(string) The name of the mode to enable.',
|
|
||||||
'on': '(bool) Whether to enable or disable the mode.'
|
|
||||||
},
|
|
||||||
perform: async function (agent, mode_name, on) {
|
|
||||||
const modes = agent.bot.modes;
|
|
||||||
if (!modes.exists(mode_name))
|
|
||||||
return `Mode ${mode_name} does not exist.` + modes.getStr();
|
|
||||||
if (modes.isOn(mode_name) === on)
|
|
||||||
return `Mode ${mode_name} is already ${on ? 'on' : 'off'}.`;
|
|
||||||
modes.setOn(mode_name, on);
|
|
||||||
return `Mode ${mode_name} is now ${on ? 'on' : 'off'}.`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: '!goToPlayer',
|
name: '!goToPlayer',
|
||||||
description: 'Go to the given player.',
|
description: 'Go to the given player.',
|
||||||
|
@ -98,6 +90,18 @@ export const actionsList = [
|
||||||
await skills.followPlayer(agent.bot, player_name, follow_dist);
|
await skills.followPlayer(agent.bot, player_name, follow_dist);
|
||||||
}, -1, 'followPlayer')
|
}, -1, 'followPlayer')
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: '!goToBlock',
|
||||||
|
description: 'Go to the nearest block of a given type.',
|
||||||
|
params: {
|
||||||
|
'type': '(string) The block type to go to.',
|
||||||
|
'closeness': '(number) How close to get to the block.',
|
||||||
|
'search_range': '(number) The distance to search for the block.'
|
||||||
|
},
|
||||||
|
perform: wrapExecution(async (agent, type, closeness, range) => {
|
||||||
|
await skills.goToNearestBlock(agent.bot, type, closeness, range);
|
||||||
|
})
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: '!moveAway',
|
name: '!moveAway',
|
||||||
description: 'Move away from the current location in any direction by a given distance.',
|
description: 'Move away from the current location in any direction by a given distance.',
|
||||||
|
@ -113,6 +117,7 @@ export const actionsList = [
|
||||||
perform: async function (agent, name) {
|
perform: async function (agent, name) {
|
||||||
const pos = agent.bot.entity.position;
|
const pos = agent.bot.entity.position;
|
||||||
agent.memory_bank.rememberPlace(name, pos.x, pos.y, pos.z);
|
agent.memory_bank.rememberPlace(name, pos.x, pos.y, pos.z);
|
||||||
|
return `Location saved as "${name}".`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -181,9 +186,18 @@ export const actionsList = [
|
||||||
'item_name': '(string) The name of the input item to smelt.',
|
'item_name': '(string) The name of the input item to smelt.',
|
||||||
'num': '(number) The number of times to smelt the item.'
|
'num': '(number) The number of times to smelt the item.'
|
||||||
},
|
},
|
||||||
perform: wrapExecution(async (agent, recipe_name, num) => {
|
perform: async function (agent, item_name, num) {
|
||||||
await skills.smeltItem(agent.bot, recipe_name, num);
|
let response = await wrapExecution(async (agent) => {
|
||||||
})
|
console.log('smelting item');
|
||||||
|
return await skills.smeltItem(agent.bot, item_name, num);
|
||||||
|
})(agent);
|
||||||
|
if (response.indexOf('Successfully') !== -1) {
|
||||||
|
// there is a bug where the bot's inventory is not updated after smelting
|
||||||
|
// only updates after a restart
|
||||||
|
agent.cleanKill(response + ' Safely restarting to update inventory.');
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '!placeHere',
|
name: '!placeHere',
|
||||||
|
@ -224,9 +238,44 @@ export const actionsList = [
|
||||||
await skills.stay(agent.bot);
|
await skills.stay(agent.bot);
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: '!setMode',
|
||||||
|
description: 'Set a mode to on or off. A mode is an automatic behavior that constantly checks and responds to the environment.',
|
||||||
|
params: {
|
||||||
|
'mode_name': '(string) The name of the mode to enable.',
|
||||||
|
'on': '(bool) Whether to enable or disable the mode.'
|
||||||
|
},
|
||||||
|
perform: async function (agent, mode_name, on) {
|
||||||
|
const modes = agent.bot.modes;
|
||||||
|
if (!modes.exists(mode_name))
|
||||||
|
return `Mode ${mode_name} does not exist.` + modes.getDocs();
|
||||||
|
if (modes.isOn(mode_name) === on)
|
||||||
|
return `Mode ${mode_name} is already ${on ? 'on' : 'off'}.`;
|
||||||
|
modes.setOn(mode_name, on);
|
||||||
|
return `Mode ${mode_name} is now ${on ? 'on' : 'off'}.`;
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: '!goal',
|
name: '!goal',
|
||||||
description: 'Set a goal to automatically work towards.',
|
description: 'Set a goal prompt to endlessly work towards with continuous self-prompting.',
|
||||||
|
params: {
|
||||||
|
'selfPrompt': '(string) The goal prompt.',
|
||||||
|
},
|
||||||
|
perform: async function (agent, prompt) {
|
||||||
|
agent.self_prompter.start(prompt); // don't await, don't return
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '!endGoal',
|
||||||
|
description: 'Call when you have accomplished your goal. It will stop self-prompting and the current action. ',
|
||||||
|
perform: async function (agent) {
|
||||||
|
agent.self_prompter.stop();
|
||||||
|
return 'Self-prompting stopped.';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '!npcGoal',
|
||||||
|
description: 'Set a simple goal for an item or building to automatically work towards. Do not use for complex goals.',
|
||||||
params: {
|
params: {
|
||||||
'name': '(string) The name of the goal to set. Can be item or building name. If empty will automatically choose a goal.',
|
'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.'
|
'quantity': '(number) The quantity of the goal to set. Default is 1.'
|
||||||
|
@ -234,25 +283,7 @@ export const actionsList = [
|
||||||
perform: async function (agent, name=null, quantity=1) {
|
perform: async function (agent, name=null, quantity=1) {
|
||||||
await agent.npc.setGoal(name, quantity);
|
await agent.npc.setGoal(name, quantity);
|
||||||
agent.bot.emit('idle'); // to trigger the goal
|
agent.bot.emit('idle'); // to trigger the goal
|
||||||
return 'Set goal: ' + agent.npc.data.curr_goal.name;
|
return 'Set npc goal: ' + agent.npc.data.curr_goal.name;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: '!selfPrompt',
|
|
||||||
description: 'Continously prompt yourself to continue acting without user input.',
|
|
||||||
params: {
|
|
||||||
'prompt': '(string) The starting prompt.',
|
|
||||||
},
|
|
||||||
perform: async function (agent, prompt) {
|
|
||||||
agent.self_prompter.start(prompt); // don't await, don't return
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '!stopSelfPrompt',
|
|
||||||
description: 'Stop current action and self-prompting.',
|
|
||||||
perform: async function (agent) {
|
|
||||||
agent.self_prompter.stop();
|
|
||||||
return 'Self-prompting stopped.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -44,6 +44,8 @@ export const queryList = [
|
||||||
if (other_players.length > 0) {
|
if (other_players.length > 0) {
|
||||||
res += '\n- Other Players: ' + other_players.join(', ');
|
res += '\n- Other Players: ' + other_players.join(', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res += '\n' + agent.bot.modes.getMiniDocs() + '\n';
|
||||||
return pad(res);
|
return pad(res);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -62,7 +64,7 @@ export const queryList = [
|
||||||
res += ': none';
|
res += ': none';
|
||||||
}
|
}
|
||||||
else if (agent.bot.game.gameMode === 'creative') {
|
else if (agent.bot.game.gameMode === 'creative') {
|
||||||
res += '\n(You have infinite items in creative mode)';
|
res += '\n(You have infinite items in creative mode. You do not need to gather resources!!)';
|
||||||
}
|
}
|
||||||
return pad(res);
|
return pad(res);
|
||||||
}
|
}
|
||||||
|
@ -122,9 +124,9 @@ export const queryList = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "!modes",
|
name: "!modes",
|
||||||
description: "Get all available modes and see which are on/off.",
|
description: "Get all available modes and their docs and see which are on/off.",
|
||||||
perform: function (agent) {
|
perform: function (agent) {
|
||||||
return agent.bot.modes.getStr();
|
return agent.bot.modes.getDocs();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,10 +50,11 @@ export async function craftRecipe(bot, itemName, num=1) {
|
||||||
// get recipes that don't require a crafting table
|
// get recipes that don't require a crafting table
|
||||||
let recipes = bot.recipesFor(mc.getItemId(itemName), null, 1, null);
|
let recipes = bot.recipesFor(mc.getItemId(itemName), null, 1, null);
|
||||||
let craftingTable = null;
|
let craftingTable = null;
|
||||||
|
const craftingTableRange = 32;
|
||||||
if (!recipes || recipes.length === 0) {
|
if (!recipes || recipes.length === 0) {
|
||||||
|
|
||||||
// Look for crafting table
|
// Look for crafting table
|
||||||
craftingTable = world.getNearestBlock(bot, 'crafting_table', 8);
|
craftingTable = world.getNearestBlock(bot, 'crafting_table', craftingTableRange);
|
||||||
if (craftingTable === null){
|
if (craftingTable === null){
|
||||||
|
|
||||||
// Try to place crafting table
|
// Try to place crafting table
|
||||||
|
@ -61,7 +62,7 @@ export async function craftRecipe(bot, itemName, num=1) {
|
||||||
if (hasTable) {
|
if (hasTable) {
|
||||||
let pos = world.getNearestFreeSpace(bot, 1, 6);
|
let pos = world.getNearestFreeSpace(bot, 1, 6);
|
||||||
await placeBlock(bot, 'crafting_table', pos.x, pos.y, pos.z);
|
await placeBlock(bot, 'crafting_table', pos.x, pos.y, pos.z);
|
||||||
craftingTable = world.getNearestBlock(bot, 'crafting_table', 8);
|
craftingTable = world.getNearestBlock(bot, 'crafting_table', craftingTableRange);
|
||||||
if (craftingTable) {
|
if (craftingTable) {
|
||||||
recipes = bot.recipesFor(mc.getItemId(itemName), null, 1, craftingTable);
|
recipes = bot.recipesFor(mc.getItemId(itemName), null, 1, craftingTable);
|
||||||
placedTable = true;
|
placedTable = true;
|
||||||
|
@ -83,6 +84,10 @@ export async function craftRecipe(bot, itemName, num=1) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (craftingTable && bot.entity.position.distanceTo(craftingTable.position) > 4) {
|
||||||
|
await goToNearestBlock(bot, 'crafting_table', 4, craftingTableRange);
|
||||||
|
}
|
||||||
|
|
||||||
const recipe = recipes[0];
|
const recipe = recipes[0];
|
||||||
console.log('crafting...');
|
console.log('crafting...');
|
||||||
|
@ -114,14 +119,15 @@ export async function smeltItem(bot, itemName, num=1) {
|
||||||
|
|
||||||
let placedFurnace = false;
|
let placedFurnace = false;
|
||||||
let furnaceBlock = undefined;
|
let furnaceBlock = undefined;
|
||||||
furnaceBlock = world.getNearestBlock(bot, 'furnace', 6);
|
const furnaceRange = 32;
|
||||||
|
furnaceBlock = world.getNearestBlock(bot, 'furnace', furnaceRange);
|
||||||
if (!furnaceBlock){
|
if (!furnaceBlock){
|
||||||
// Try to place furnace
|
// Try to place furnace
|
||||||
let hasFurnace = world.getInventoryCounts(bot)['furnace'] > 0;
|
let hasFurnace = world.getInventoryCounts(bot)['furnace'] > 0;
|
||||||
if (hasFurnace) {
|
if (hasFurnace) {
|
||||||
let pos = world.getNearestFreeSpace(bot, 1, 6);
|
let pos = world.getNearestFreeSpace(bot, 1, furnaceRange);
|
||||||
await placeBlock(bot, 'furnace', pos.x, pos.y, pos.z);
|
await placeBlock(bot, 'furnace', pos.x, pos.y, pos.z);
|
||||||
furnaceBlock = world.getNearestBlock(bot, 'furnace', 6);
|
furnaceBlock = world.getNearestBlock(bot, 'furnace', furnaceRange);
|
||||||
placedFurnace = true;
|
placedFurnace = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,6 +135,9 @@ export async function smeltItem(bot, itemName, num=1) {
|
||||||
log(bot, `There is no furnace nearby and you have no furnace.`)
|
log(bot, `There is no furnace nearby and you have no furnace.`)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (bot.entity.position.distanceTo(furnaceBlock.position) > 4) {
|
||||||
|
await goToNearestBlock(bot, 'furnace', 4, furnaceRange);
|
||||||
|
}
|
||||||
await bot.lookAt(furnaceBlock.position);
|
await bot.lookAt(furnaceBlock.position);
|
||||||
|
|
||||||
console.log('smelting...');
|
console.log('smelting...');
|
||||||
|
@ -630,7 +639,7 @@ export async function placeBlock(bot, blockType, x, y, z, placeOn='bottom', dont
|
||||||
// will throw error if an entity is in the way, and sometimes even if the block was placed
|
// will throw error if an entity is in the way, and sometimes even if the block was placed
|
||||||
try {
|
try {
|
||||||
await bot.placeBlock(buildOffBlock, faceVec);
|
await bot.placeBlock(buildOffBlock, faceVec);
|
||||||
log(bot, `Successfully placed ${blockType} at ${target_dest}.`);
|
log(bot, `Placed ${blockType} at ${target_dest}.`);
|
||||||
await new Promise(resolve => setTimeout(resolve, 200));
|
await new Promise(resolve => setTimeout(resolve, 200));
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -770,6 +779,32 @@ export async function goToPosition(bot, x, y, z, min_distance=2) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function goToNearestBlock(bot, blockType, min_distance=2, range=64) {
|
||||||
|
/**
|
||||||
|
* Navigate to the nearest block of the given type.
|
||||||
|
* @param {MinecraftBot} bot, reference to the minecraft bot.
|
||||||
|
* @param {string} blockType, the type of block to navigate to.
|
||||||
|
* @param {number} min_distance, the distance to keep from the block. Defaults to 2.
|
||||||
|
* @param {number} range, the range to look for the block. Defaults to 64.
|
||||||
|
* @returns {Promise<boolean>} true if the block was reached, false otherwise.
|
||||||
|
* @example
|
||||||
|
* await skills.goToNearestBlock(bot, "oak_log", 64, 2);
|
||||||
|
* **/
|
||||||
|
const MAX_RANGE = 512;
|
||||||
|
if (range > MAX_RANGE) {
|
||||||
|
log(bot, `Maximum search range capped at ${MAX_RANGE}. `);
|
||||||
|
range = MAX_RANGE;
|
||||||
|
}
|
||||||
|
let block = world.getNearestBlock(bot, blockType, range);
|
||||||
|
if (!block) {
|
||||||
|
log(bot, `Could not find any ${blockType} in ${range} blocks.`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
log(bot, `Found ${blockType} at ${block.position}.`);
|
||||||
|
await goToPosition(bot, block.position.x, block.position.y, block.position.z, min_distance);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export async function goToPlayer(bot, username, distance=3) {
|
export async function goToPlayer(bot, username, distance=3) {
|
||||||
/**
|
/**
|
||||||
|
@ -824,6 +859,10 @@ export async function followPlayer(bot, username, distance=4) {
|
||||||
|
|
||||||
while (!bot.interrupt_code) {
|
while (!bot.interrupt_code) {
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||||||
|
// in cheat mode, if the distance is too far, teleport to the player
|
||||||
|
if (bot.modes.isOn('cheat') && bot.entity.position.distanceTo(player.position) > 100 && player.isOnGround) {
|
||||||
|
await goToPlayer(bot, username);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -844,6 +883,7 @@ export async function moveAway(bot, distance) {
|
||||||
bot.pathfinder.setMovements(new pf.Movements(bot));
|
bot.pathfinder.setMovements(new pf.Movements(bot));
|
||||||
|
|
||||||
if (bot.modes.isOn('cheat')) {
|
if (bot.modes.isOn('cheat')) {
|
||||||
|
const move = new pf.Movements(bot);
|
||||||
const path = await bot.pathfinder.getPathTo(move, inverted_goal, 10000);
|
const path = await bot.pathfinder.getPathTo(move, inverted_goal, 10000);
|
||||||
let last_move = path.path[path.path.length-1];
|
let last_move = path.path[path.path.length-1];
|
||||||
console.log(last_move);
|
console.log(last_move);
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
import * as skills from './library/skills.js';
|
import * as skills from './library/skills.js';
|
||||||
import * as world from './library/world.js';
|
import * as world from './library/world.js';
|
||||||
import * as mc from '../utils/mcdata.js';
|
import * as mc from '../utils/mcdata.js';
|
||||||
|
import settings from '../../settings.js'
|
||||||
|
|
||||||
|
function say(agent, message) {
|
||||||
|
if (agent.shut_up || !settings.narrate_behavior) return;
|
||||||
|
agent.bot.chat(message);
|
||||||
|
}
|
||||||
|
|
||||||
// a mode is a function that is called every tick to respond immediately to the world
|
// a mode is a function that is called every tick to respond immediately to the world
|
||||||
// it has the following fields:
|
// it has the following fields:
|
||||||
|
@ -41,13 +46,13 @@ const modes = [
|
||||||
}
|
}
|
||||||
else if (block.name === 'lava' || block.name === 'flowing_lava' || block.name === 'fire' ||
|
else if (block.name === 'lava' || block.name === 'flowing_lava' || block.name === 'fire' ||
|
||||||
blockAbove.name === 'lava' || blockAbove.name === 'flowing_lava' || blockAbove.name === 'fire') {
|
blockAbove.name === 'lava' || blockAbove.name === 'flowing_lava' || blockAbove.name === 'fire') {
|
||||||
bot.chat('I\'m on fire!'); // TODO: gets stuck in lava
|
say(agent, 'I\'m on fire!'); // TODO: gets stuck in lava
|
||||||
execute(this, agent, async () => {
|
execute(this, agent, async () => {
|
||||||
let nearestWater = world.getNearestBlock(bot, 'water', 20);
|
let nearestWater = world.getNearestBlock(bot, 'water', 20);
|
||||||
if (nearestWater) {
|
if (nearestWater) {
|
||||||
const pos = nearestWater.position;
|
const pos = nearestWater.position;
|
||||||
await skills.goToPosition(bot, pos.x, pos.y, pos.z, 0.2);
|
await skills.goToPosition(bot, pos.x, pos.y, pos.z, 0.2);
|
||||||
bot.chat('Ahhhh that\'s better!');
|
say(agent, 'Ahhhh that\'s better!');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await skills.moveAway(bot, 5);
|
await skills.moveAway(bot, 5);
|
||||||
|
@ -55,7 +60,7 @@ const modes = [
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (Date.now() - bot.lastDamageTime < 3000 && (bot.health < 5 || bot.lastDamageTaken >= bot.health)) {
|
else if (Date.now() - bot.lastDamageTime < 3000 && (bot.health < 5 || bot.lastDamageTaken >= bot.health)) {
|
||||||
bot.chat('I\'m dying!');
|
say(agent, 'I\'m dying!');
|
||||||
execute(this, agent, async () => {
|
execute(this, agent, async () => {
|
||||||
await skills.moveAway(bot, 20);
|
await skills.moveAway(bot, 20);
|
||||||
});
|
});
|
||||||
|
@ -74,7 +79,7 @@ const modes = [
|
||||||
update: async function (agent) {
|
update: async function (agent) {
|
||||||
const enemy = world.getNearestEntityWhere(agent.bot, entity => mc.isHostile(entity), 16);
|
const enemy = world.getNearestEntityWhere(agent.bot, entity => mc.isHostile(entity), 16);
|
||||||
if (enemy && await world.isClearPath(agent.bot, enemy)) {
|
if (enemy && await world.isClearPath(agent.bot, enemy)) {
|
||||||
agent.bot.chat(`Aaa! A ${enemy.name}!`);
|
say(agent, `Aaa! A ${enemy.name}!`);
|
||||||
execute(this, agent, async () => {
|
execute(this, agent, async () => {
|
||||||
await skills.avoidEnemies(agent.bot, 24);
|
await skills.avoidEnemies(agent.bot, 24);
|
||||||
});
|
});
|
||||||
|
@ -90,7 +95,7 @@ const modes = [
|
||||||
update: async function (agent) {
|
update: async function (agent) {
|
||||||
const enemy = world.getNearestEntityWhere(agent.bot, entity => mc.isHostile(entity), 8);
|
const enemy = world.getNearestEntityWhere(agent.bot, entity => mc.isHostile(entity), 8);
|
||||||
if (enemy && await world.isClearPath(agent.bot, enemy)) {
|
if (enemy && await world.isClearPath(agent.bot, enemy)) {
|
||||||
agent.bot.chat(`Fighting ${enemy.name}!`);
|
say(agent, `Fighting ${enemy.name}!`);
|
||||||
execute(this, agent, async () => {
|
execute(this, agent, async () => {
|
||||||
await skills.defendSelf(agent.bot, 8);
|
await skills.defendSelf(agent.bot, 8);
|
||||||
});
|
});
|
||||||
|
@ -107,7 +112,7 @@ const modes = [
|
||||||
const huntable = world.getNearestEntityWhere(agent.bot, entity => mc.isHuntable(entity), 8);
|
const huntable = world.getNearestEntityWhere(agent.bot, entity => mc.isHuntable(entity), 8);
|
||||||
if (huntable && await world.isClearPath(agent.bot, huntable)) {
|
if (huntable && await world.isClearPath(agent.bot, huntable)) {
|
||||||
execute(this, agent, async () => {
|
execute(this, agent, async () => {
|
||||||
agent.bot.chat(`Hunting ${huntable.name}!`);
|
say(agent, `Hunting ${huntable.name}!`);
|
||||||
await skills.attackEntity(agent.bot, huntable);
|
await skills.attackEntity(agent.bot, huntable);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -130,7 +135,7 @@ const modes = [
|
||||||
this.noticed_at = Date.now();
|
this.noticed_at = Date.now();
|
||||||
}
|
}
|
||||||
if (Date.now() - this.noticed_at > this.wait * 1000) {
|
if (Date.now() - this.noticed_at > this.wait * 1000) {
|
||||||
agent.bot.chat(`Picking up ${item.name}!`);
|
say(agent, `Picking up item!`);
|
||||||
this.prev_item = item;
|
this.prev_item = item;
|
||||||
execute(this, agent, async () => {
|
execute(this, agent, async () => {
|
||||||
await skills.pickupNearbyItems(agent.bot);
|
await skills.pickupNearbyItems(agent.bot);
|
||||||
|
@ -246,8 +251,17 @@ class ModeController {
|
||||||
this.modes_map[mode_name].paused = true;
|
this.modes_map[mode_name].paused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
getStr() {
|
getMiniDocs() { // no descriptions
|
||||||
let res = 'Available Modes:';
|
let res = 'Agent Modes:';
|
||||||
|
for (let mode of this.modes_list) {
|
||||||
|
let on = mode.on ? 'ON' : 'OFF';
|
||||||
|
res += `\n- ${mode.name}(${on})`;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
getDocs() {
|
||||||
|
let res = 'Agent Modes:';
|
||||||
for (let mode of this.modes_list) {
|
for (let mode of this.modes_list) {
|
||||||
let on = mode.on ? 'ON' : 'OFF';
|
let on = mode.on ? 'ON' : 'OFF';
|
||||||
res += `\n- ${mode.name}(${on}): ${mode.description}`;
|
res += `\n- ${mode.name}(${on}): ${mode.description}`;
|
||||||
|
|
|
@ -32,7 +32,7 @@ export class SelfPrompter {
|
||||||
let no_command_count = 0;
|
let no_command_count = 0;
|
||||||
const MAX_NO_COMMAND = 3;
|
const MAX_NO_COMMAND = 3;
|
||||||
while (!this.interrupt) {
|
while (!this.interrupt) {
|
||||||
let msg = `You are self-prompting with the prompt: '${this.prompt}'. Your next response MUST contain a command !withThisSyntax. Respond:`;
|
let msg = `You are self-prompting with the goal: '${this.prompt}'. Your next response MUST contain a command !withThisSyntax. Respond:`;
|
||||||
|
|
||||||
let used_command = await this.agent.handleMessage('system', msg, 1);
|
let used_command = await this.agent.handleMessage('system', msg, 1);
|
||||||
if (!used_command) {
|
if (!used_command) {
|
||||||
|
@ -81,9 +81,10 @@ export class SelfPrompter {
|
||||||
this.interrupt = false;
|
this.interrupt = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async stop() {
|
async stop(stop_action=true) {
|
||||||
this.interrupt = true;
|
this.interrupt = true;
|
||||||
await this.agent.coder.stop();
|
if (stop_action)
|
||||||
|
await this.agent.coder.stop();
|
||||||
await this.stopLoop();
|
await this.stopLoop();
|
||||||
this.on = false;
|
this.on = false;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +97,7 @@ export class SelfPrompter {
|
||||||
// if a user messages and the bot responds with an action, stop the self-prompt loop
|
// if a user messages and the bot responds with an action, stop the self-prompt loop
|
||||||
if (!is_self_prompt && is_action) {
|
if (!is_self_prompt && is_action) {
|
||||||
this.stopLoop();
|
this.stopLoop();
|
||||||
// this stops it from responding from the handlemessage and the self-prompt loop at the same time
|
// this stops it from responding from the handlemessage loop and the self-prompt loop at the same time
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -33,6 +33,7 @@ export function strictFormat(turns) {
|
||||||
let messages = [];
|
let messages = [];
|
||||||
let filler = {role: 'user', content: '_'};
|
let filler = {role: 'user', content: '_'};
|
||||||
for (let msg of turns) {
|
for (let msg of turns) {
|
||||||
|
msg.content = msg.content.trim();
|
||||||
if (msg.role === 'system') {
|
if (msg.role === 'system') {
|
||||||
msg.role = 'user';
|
msg.role = 'user';
|
||||||
msg.content = 'SYSTEM: ' + msg.content;
|
msg.content = 'SYSTEM: ' + msg.content;
|
||||||
|
|
Loading…
Add table
Reference in a new issue