added self prompt to prompter, verbose commands

This commit is contained in:
MaxRobinsonTheGreat 2024-06-23 20:15:28 -05:00
parent 46aa27fdfc
commit 9c17900cc5
5 changed files with 57 additions and 24 deletions

View file

@ -3,12 +3,23 @@
"model": "gpt-3.5-turbo",
"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$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:",
"coding": "You are an intelligent mineflayer bot $NAME that plays minecraft by writing javascript codeblocks. Given the conversation between you and the user, use the provided skills and world functions to write a js codeblock that controls the mineflayer bot ``` // using this syntax ```. The code will be executed and you will recieve it's output. If you are satisfied with the response, respond without a codeblock in a conversational way. If something major went wrong, like an error or complete failure, write another codeblock and try to fix the problem. Minor mistakes are acceptable. Be maximally efficient, creative, and clear. Do not use commands !likeThis, only use codeblocks. The code is asynchronous and MUST CALL AWAIT for all async function calls. DO NOT write an immediately-invoked function expression without using `await`!! DO NOT WRITE LIKE THIS: ```(async () => {console.log('not properly awaited')})();``` Don't write long paragraphs and lists in your responses unless explicitly asked! Only summarize the code you write with a sentence or two when done. This is extremely important to me, take a deep breath and good luck! \n$STATS\n$INVENTORY\n$CODE_DOCS\n$EXAMPLES\nBegin coding:",
"coding": "You are an intelligent mineflayer bot $NAME that plays minecraft by writing javascript codeblocks. Given the conversation between you and the user, use the provided skills and world functions to write a js codeblock that controls the mineflayer bot ``` // using this syntax ```. The code will be executed and you will recieve it's output. If you are satisfied with the response, respond without a codeblock in a conversational way. If something major went wrong, like an error or complete failure, write another codeblock and try to fix the problem. Minor mistakes are acceptable. Be maximally efficient, creative, and clear. Do not use commands !likeThis, only use codeblocks. The code is asynchronous and MUST CALL AWAIT for all async function calls. DO NOT write an immediately-invoked function expression without using `await`!! DO NOT WRITE LIKE THIS: ```(async () => {console.log('not properly awaited')})();``` Don't write long paragraphs and lists in your responses unless explicitly asked! Only summarize the code you write with a sentence or two when done. This is extremely important to me, take a deep breath and good luck! \n$SELF_PROMPT\n$STATS\n$INVENTORY\n$CODE_DOCS\n$EXAMPLES\nBegin coding:",
"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: ",
"modes": {
"self_preservation": true,
"cowardice": true,
"self_defense": true,
"hunting": true,
"item_collecting": true,
"torch_placing": true,
"idle_staring": true,
"cheat": false
},
"conversation_examples": [
[
{"role": "system", "content": "Start acting on your own for your survival."},
@ -82,4 +93,4 @@
]
]
}
}

View file

@ -14,4 +14,5 @@ export default
"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
"verbose_commands": true, // show full command syntax
}

View file

@ -72,7 +72,7 @@ export class Agent {
this.self_prompter.start(prompt);
}
else if (init_message) {
this.handleMessage('system', init_message, true);
this.handleMessage('system', init_message, 2);
}
else {
this.bot.chat('Hello world! I am ' + this.name);
@ -89,10 +89,12 @@ export class Agent {
return this.bot.chat(message);
}
async handleMessage(source, message, self_prompt=false) {
async handleMessage(source, message, max_responses=5) {
let used_command = false;
if (source !== 'system' && source !== this.name && !self_prompt) {
let self_prompt = source === 'system' || source === this.name;
if (!self_prompt) {
const user_command_name = containsCommand(message);
if (user_command_name) {
if (!commandExists(user_command_name)) {
@ -111,11 +113,14 @@ export class Agent {
return true;
}
}
let MAX_ATTEMPTS = 5;
if (!self_prompt && this.self_prompter.on) // message from user during self-prompting
MAX_ATTEMPTS = 1; // immediately respond to this message, then let self-prompting take over
for (let i=0; i<MAX_ATTEMPTS; i++) {
if (self_prompt && this.self_prompter.on && this.self_prompter.interrupt) break;
await this.history.add(source, message);
this.history.save();
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
for (let i=0; i<max_responses; i++) {
if (this.self_prompter.shouldInterrupt(self_prompt)) break;
let history = this.history.getHistory();
let res = await this.prompter.promptConvo(history);
@ -126,7 +131,7 @@ export class Agent {
res = truncCommandMessage(res); // everything after the command is ignored
this.history.add(this.name, res);
if (!commandExists(command_name)) {
this.history.add('system', `Command ${command_name} does not exist. Use !newAction to perform custom actions.`);
this.history.add('system', `Command ${command_name} does not exist.`);
console.warn('Agent hallucinated command:', command_name)
continue;
}
@ -135,18 +140,18 @@ export class Agent {
continue;
}
// commented for now, maybe should add a 'verbose' option to settings.json to enable cleaner output
// let pre_message = res.substring(0, res.indexOf(command_name)).trim();
// let chat_message = `*used ${command_name.substring(1)}*`;
// if (pre_message.length > 0)
// chat_message = `${pre_message} ${chat_message}`;
this.cleanChat(res);
if (this.self_prompter.shouldInterrupt(self_prompt)) break;
this.self_prompter.handleUserPromptedCmd(self_prompt, isAction(command_name));
if (self_prompt && this.self_prompter.on && this.self_prompter.interrupt) break;
if (isAction(command_name) && !self_prompt && this.self_prompter.on) {
this.self_prompter.stopLoop(); // so agent doesn't respond from self-prompting loop
// will be automatically restarted by self-prompter
if (settings.verbose_commands) {
this.cleanChat(res);
}
else { // only output command name
let pre_message = res.substring(0, res.indexOf(command_name)).trim();
let chat_message = `*used ${command_name.substring(1)}*`;
if (pre_message.length > 0)
chat_message = `${pre_message} ${chat_message}`;
this.cleanChat(res);
}
let execute_res = await executeCommand(this, res);

View file

@ -124,6 +124,10 @@ export class Prompter {
prompt = prompt.replaceAll('$TO_SUMMARIZE', stringifyTurns(to_summarize));
if (prompt.includes('$CONVO'))
prompt = prompt.replaceAll('$CONVO', 'Recent conversation:\n' + stringifyTurns(messages));
if (prompt.includes('$SELF_PROMPT')) {
let self_prompt = this.agent.self_prompter.on ? `Use this self-prompt to guide your behavior: "${this.agent.self_prompter.prompt}"\n` : '';
prompt = prompt.replaceAll('$SELF_PROMPT', self_prompt);
}
if (prompt.includes('$LAST_GOALS')) {
let goal_text = '';
for (let goal in last_goals) {

View file

@ -34,7 +34,7 @@ export class SelfPrompter {
while (!this.interrupt) {
let msg = `You are self-prompting with the prompt: '${this.prompt}'. Your next response MUST contain a command !withThisSyntax. Respond:`;
let used_command = await this.agent.handleMessage('system', msg, true);
let used_command = await this.agent.handleMessage('system', msg, 1);
if (!used_command) {
no_command_count++;
if (no_command_count >= MAX_NO_COMMAND) {
@ -87,4 +87,16 @@ export class SelfPrompter {
await this.stopLoop();
this.on = false;
}
shouldInterrupt(is_self_prompt) { // to be called from handleMessage
return is_self_prompt && this.on && this.interrupt;
}
handleUserPromptedCmd(is_self_prompt, is_action) {
// if a user messages and the bot responds with an action, stop the self-prompt loop
if (!is_self_prompt && is_action) {
this.stopLoop();
// this stops it from responding from the handlemessage and the self-prompt loop at the same time
}
}
}