diff --git a/.gitignore b/.gitignore index f7aae85..791d367 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ .vscode/ node_modules/ package-lock.json -temp.js scratch.js -agent_code/** -!agent_code/template.js \ No newline at end of file +!agent_code/template.js +bots/**/action-code/** \ No newline at end of file diff --git a/bots/assist.json b/bots/andy/assist.json similarity index 100% rename from bots/assist.json rename to bots/andy/assist.json diff --git a/bots/andy/memories.json b/bots/andy/memories.json new file mode 100644 index 0000000..a4d62b5 --- /dev/null +++ b/bots/andy/memories.json @@ -0,0 +1,80 @@ +{ + "name": "andy", + "bio": "You are playing minecraft and assisting other players in tasks.", + "memory": "", + "events": [], + "turns": [ + { + "role": "user", + "content": "sumixam0: come here andy" + }, + { + "role": "assistant", + "content": "```\n// I am going to navigate to sumixam0. \nawait skills.goToPlayer(bot, 'sumixam0');\n```" + }, + { + "role": "system", + "content": "Code output:\nYou have reached at 300.7930424155586, 78, -115.19151414785698.\nPlayer is now at (300.7930424155586, 78, -115.19151414785698).\nCode finished.\n" + }, + { + "role": "assistant", + "content": "I'm here, sumixam0! What can I do for you?" + }, + { + "role": "user", + "content": "sumixam0: follow me!" + }, + { + "role": "assistant", + "content": "Sure, I'll follow you, Sumixam0!\n```\n// I am going to follow sumixam0.\nawait skills.followPlayer(bot, 'sumixam0');\n```" + }, + { + "role": "user", + "content": "sumixam0: place some dirt" + }, + { + "role": "assistant", + "content": "Sure, I'll place some dirt.\n```\n// I am going to place dirt at my current position.\nlet position = world.getPosition(bot);\nawait skills.placeBlock(bot, 'dirt', position.x, position.y, position.z);\n```" + }, + { + "role": "system", + "content": "Code output:\nDon't have any dirt to place.\nCode finished.\n" + }, + { + "role": "assistant", + "content": "I apologize, but I don't have any dirt to place at the moment." + }, + { + "role": "user", + "content": "sumixam0: try again" + }, + { + "role": "assistant", + "content": "Sure, let me try again.\n```\n// I am going to place dirt at my current position.\nlet position = world.getPosition(bot);\nawait skills.placeBlock(bot, 'dirt', position.x, position.y - 1, position.z);\n```" + }, + { + "role": "system", + "content": "Code output:\nCannot place block at (303, 77, -116) because grass_block is in the way.\nCode finished.\n" + }, + { + "role": "assistant", + "content": "I apologize, but I am unable to place the dirt block here because there is grass in the way." + }, + { + "role": "user", + "content": "sumixam0: try placing one higher" + }, + { + "role": "assistant", + "content": "Alright, I'll try placing the dirt block one block higher.\n```\n// I am going to place dirt one block higher than my current position.\nlet position = world.getPosition(bot);\nawait skills.placeBlock(bot, 'dirt', position.x, position.y, position.z);\n```" + }, + { + "role": "system", + "content": "Code output:\nSuccessfully placed dirt at (303, 78, -116).\nCode finished.\n" + }, + { + "role": "assistant", + "content": "I have successfully placed a dirt block one block higher." + } + ] +} \ No newline at end of file diff --git a/agent_code/template.js b/bots/template.js similarity index 55% rename from agent_code/template.js rename to bots/template.js index 52d0544..1e61d60 100644 --- a/agent_code/template.js +++ b/bots/template.js @@ -1,5 +1,5 @@ -import * as skills from '../utils/skills.js'; -import * as world from '../utils/world.js'; +import * as skills from '../../../src/agent/skills.js'; +import * as world from '../../../src/agent/world.js'; import Vec3 from 'vec3'; const log = skills.log; diff --git a/main.js b/main.js index ea78372..1a73182 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,3 @@ -import { AgentProcess } from './controller/agent-process.js'; +import { AgentProcess } from './src/process/agent-process.js'; new AgentProcess('andy').start(true, false); \ No newline at end of file diff --git a/agent.js b/src/agent/agent.js similarity index 89% rename from agent.js rename to src/agent/agent.js index a6beffd..2b8938d 100644 --- a/agent.js +++ b/src/agent/agent.js @@ -1,10 +1,10 @@ -import { initBot } from './utils/mcdata.js'; -import { sendRequest } from './utils/gpt.js'; -import { History } from './utils/history.js'; -import { Coder } from './utils/coder.js'; -import { getQuery, containsQuery } from './utils/queries.js'; -import { containsCodeBlock } from './utils/skill-library.js'; -import { Events } from './utils/events.js'; +import { initBot } from '../utils/mcdata.js'; +import { sendRequest } from '../utils/gpt.js'; +import { History } from './history.js'; +import { Coder } from './coder.js'; +import { getQuery, containsQuery } from './queries.js'; +import { containsCodeBlock } from './skill-library.js'; +import { Events } from './events.js'; export class Agent { diff --git a/utils/coder.js b/src/agent/coder.js similarity index 95% rename from utils/coder.js rename to src/agent/coder.js index 0b6e405..0f3e8ce 100644 --- a/utils/coder.js +++ b/src/agent/coder.js @@ -6,14 +6,14 @@ export class Coder { this.queued_code = ''; this.current_code = ''; this.file_counter = 0; - this.fp = './agent_code/'; + this.fp = '/bots/'+agent.name+'/action-code/'; this.agent.bot.interrupt_code = false; this.executing = false; this.agent.bot.output = ''; this.code_template = ''; this.timedout = false; - readFile(this.fp+'template.js', 'utf8', (err, data) => { + readFile('./bots/template.js', 'utf8', (err, data) => { if (err) throw err; this.code_template = data; }); @@ -67,7 +67,7 @@ export class Coder { console.log("writing to file...", src) - let filename = this.fp + this.file_counter + '.js'; + let filename = this.file_counter + '.js'; // if (this.file_counter > 0) { // let prev_filename = this.fp + (this.file_counter-1) + '.js'; // unlink(prev_filename, (err) => { @@ -77,7 +77,7 @@ export class Coder { // } commented for now, useful to keep files for debugging this.file_counter++; - let write_result = await this.writeFilePromise(filename, src); + let write_result = await this.writeFilePromise('.' + this.fp + filename, src) if (write_result) { console.error('Error writing code execution file: ' + result); @@ -86,7 +86,7 @@ export class Coder { let TIMEOUT; try { console.log('executing code...\n'); - let execution_file = await import('.'+filename); + let execution_file = await import('../..' + this.fp + filename); await this.stop(); this.current_code = this.queued_code; diff --git a/utils/context.js b/src/agent/context.js similarity index 98% rename from utils/context.js rename to src/agent/context.js index 3518b10..c5cd572 100644 --- a/utils/context.js +++ b/src/agent/context.js @@ -1,7 +1,7 @@ import { readFileSync } from 'fs'; import { getNearestBlock, getNearbyMobTypes, getNearbyPlayerNames, getNearbyBlockTypes, getInventoryCounts } from './world.js'; -import { getAllItems } from './mcdata.js'; +import { getAllItems } from '../utils/mcdata.js'; export function getStats(bot) { diff --git a/utils/events.js b/src/agent/events.js similarity index 100% rename from utils/events.js rename to src/agent/events.js diff --git a/utils/history.js b/src/agent/history.js similarity index 98% rename from utils/history.js rename to src/agent/history.js index 93d46be..d8d469a 100644 --- a/utils/history.js +++ b/src/agent/history.js @@ -1,7 +1,7 @@ import { writeFileSync, readFileSync, mkdirSync } from 'fs'; import { getQueryDocs } from './queries.js'; import { getSkillDocs } from './skill-library.js'; -import { sendRequest, embed, cosineSimilarity } from './gpt.js'; +import { sendRequest, embed, cosineSimilarity } from '../utils/gpt.js'; export class History { @@ -86,7 +86,7 @@ export class History { async loadExamples() { let examples = []; try { - const data = readFileSync('utils/examples.json', 'utf8'); + const data = readFileSync('./src/examples.json', 'utf8'); examples = JSON.parse(data); } catch (err) { console.log('No history examples found.'); diff --git a/utils/queries.js b/src/agent/queries.js similarity index 100% rename from utils/queries.js rename to src/agent/queries.js diff --git a/utils/skill-library.js b/src/agent/skill-library.js similarity index 100% rename from utils/skill-library.js rename to src/agent/skill-library.js diff --git a/utils/skills.js b/src/agent/skills.js similarity index 99% rename from utils/skills.js rename to src/agent/skills.js index 2b119bc..1c9396e 100644 --- a/utils/skills.js +++ b/src/agent/skills.js @@ -1,4 +1,4 @@ -import { getItemId, getItemName } from "./mcdata.js"; +import { getItemId, getItemName } from "../utils/mcdata.js"; import { getNearestBlocks, getNearestBlock, getInventoryCounts, getInventoryStacks, getNearbyMobs, getNearbyBlocks } from "./world.js"; import pf from 'mineflayer-pathfinder'; import Vec3 from 'vec3'; diff --git a/utils/world.js b/src/agent/world.js similarity index 99% rename from utils/world.js rename to src/agent/world.js index 9cf6749..131e36d 100644 --- a/utils/world.js +++ b/src/agent/world.js @@ -1,4 +1,4 @@ -import { getAllBlockIds } from './mcdata.js'; +import { getAllBlockIds } from '../utils/mcdata.js'; export function getNearestBlocks(bot, block_types, distance=16, count=1) { diff --git a/utils/examples.json b/src/examples.json similarity index 100% rename from utils/examples.json rename to src/examples.json diff --git a/controller/agent-process.js b/src/process/agent-process.js similarity index 95% rename from controller/agent-process.js rename to src/process/agent-process.js index 929317e..48eb412 100644 --- a/controller/agent-process.js +++ b/src/process/agent-process.js @@ -5,7 +5,7 @@ export class AgentProcess { this.name = name; } start(clear_memory=false, autostart=false, profile='assist') { - let args = ['controller/init-agent.js', this.name]; + let args = ['src/process/init-agent.js', this.name]; args.push('-p', profile); if (clear_memory) args.push('-c'); diff --git a/controller/init-agent.js b/src/process/init-agent.js similarity index 81% rename from controller/init-agent.js rename to src/process/init-agent.js index 96d9381..4421596 100644 --- a/controller/init-agent.js +++ b/src/process/init-agent.js @@ -1,4 +1,4 @@ -import { Agent } from '../agent.js'; +import { Agent } from '../agent/agent.js'; import yargs from 'yargs'; const args = process.argv.slice(2); @@ -25,8 +25,8 @@ const argv = yargs(args) }).argv const name = argv._[0]; -const save_path = './bots/'+name+'.json'; -const load_path = !!argv.clear_memory ? './bots/'+argv.profile+'.json' : save_path; +const save_path = `./bots/${name}/memories.json`; +const load_path = !!argv.clear_memory ? `./bots/${name}/${argv.profile}.json` : save_path; const init_message = !!argv.autostart ? 'Agent process restarted. Notify the user and decide what to do.' : null; new Agent(name, save_path, load_path, init_message); diff --git a/utils/gpt.js b/src/utils/gpt.js similarity index 100% rename from utils/gpt.js rename to src/utils/gpt.js diff --git a/utils/mcdata.js b/src/utils/mcdata.js similarity index 100% rename from utils/mcdata.js rename to src/utils/mcdata.js