diff --git a/.gitignore b/.gitignore index 791d367..f7aae85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .vscode/ node_modules/ package-lock.json +temp.js scratch.js -!agent_code/template.js -bots/**/action-code/** \ No newline at end of file +agent_code/** +!agent_code/template.js \ No newline at end of file diff --git a/src/agent/agent.js b/agent.js similarity index 89% rename from src/agent/agent.js rename to agent.js index 2b8938d..a6beffd 100644 --- a/src/agent/agent.js +++ b/agent.js @@ -1,10 +1,10 @@ -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'; +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'; export class Agent { diff --git a/bots/template.js b/agent_code/template.js similarity index 55% rename from bots/template.js rename to agent_code/template.js index 1e61d60..52d0544 100644 --- a/bots/template.js +++ b/agent_code/template.js @@ -1,5 +1,5 @@ -import * as skills from '../../../src/agent/skills.js'; -import * as world from '../../../src/agent/world.js'; +import * as skills from '../utils/skills.js'; +import * as world from '../utils/world.js'; import Vec3 from 'vec3'; const log = skills.log; diff --git a/bots/andy/memories.json b/bots/andy/memories.json deleted file mode 100644 index a4d62b5..0000000 --- a/bots/andy/memories.json +++ /dev/null @@ -1,80 +0,0 @@ -{ - "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/bots/andy/assist.json b/bots/assist.json similarity index 100% rename from bots/andy/assist.json rename to bots/assist.json diff --git a/src/process/agent-process.js b/controller/agent-process.js similarity index 95% rename from src/process/agent-process.js rename to controller/agent-process.js index 48eb412..929317e 100644 --- a/src/process/agent-process.js +++ b/controller/agent-process.js @@ -5,7 +5,7 @@ export class AgentProcess { this.name = name; } start(clear_memory=false, autostart=false, profile='assist') { - let args = ['src/process/init-agent.js', this.name]; + let args = ['controller/init-agent.js', this.name]; args.push('-p', profile); if (clear_memory) args.push('-c'); diff --git a/src/process/init-agent.js b/controller/init-agent.js similarity index 81% rename from src/process/init-agent.js rename to controller/init-agent.js index 4421596..96d9381 100644 --- a/src/process/init-agent.js +++ b/controller/init-agent.js @@ -1,4 +1,4 @@ -import { Agent } from '../agent/agent.js'; +import { Agent } from '../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}/memories.json`; -const load_path = !!argv.clear_memory ? `./bots/${name}/${argv.profile}.json` : save_path; +const save_path = './bots/'+name+'.json'; +const load_path = !!argv.clear_memory ? './bots/'+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/main.js b/main.js index 1a73182..ea78372 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,3 @@ -import { AgentProcess } from './src/process/agent-process.js'; +import { AgentProcess } from './controller/agent-process.js'; new AgentProcess('andy').start(true, false); \ No newline at end of file diff --git a/src/agent/coder.js b/utils/coder.js similarity index 95% rename from src/agent/coder.js rename to utils/coder.js index 0f3e8ce..0b6e405 100644 --- a/src/agent/coder.js +++ b/utils/coder.js @@ -6,14 +6,14 @@ export class Coder { this.queued_code = ''; this.current_code = ''; this.file_counter = 0; - this.fp = '/bots/'+agent.name+'/action-code/'; + this.fp = './agent_code/'; this.agent.bot.interrupt_code = false; this.executing = false; this.agent.bot.output = ''; this.code_template = ''; this.timedout = false; - readFile('./bots/template.js', 'utf8', (err, data) => { + readFile(this.fp+'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.file_counter + '.js'; + let filename = this.fp + 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('.' + this.fp + filename, src) + let write_result = await this.writeFilePromise(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('../..' + this.fp + filename); + let execution_file = await import('.'+filename); await this.stop(); this.current_code = this.queued_code; diff --git a/src/agent/context.js b/utils/context.js similarity index 98% rename from src/agent/context.js rename to utils/context.js index c5cd572..3518b10 100644 --- a/src/agent/context.js +++ b/utils/context.js @@ -1,7 +1,7 @@ import { readFileSync } from 'fs'; import { getNearestBlock, getNearbyMobTypes, getNearbyPlayerNames, getNearbyBlockTypes, getInventoryCounts } from './world.js'; -import { getAllItems } from '../utils/mcdata.js'; +import { getAllItems } from './mcdata.js'; export function getStats(bot) { diff --git a/src/agent/events.js b/utils/events.js similarity index 100% rename from src/agent/events.js rename to utils/events.js diff --git a/src/examples.json b/utils/examples.json similarity index 100% rename from src/examples.json rename to utils/examples.json diff --git a/src/utils/gpt.js b/utils/gpt.js similarity index 100% rename from src/utils/gpt.js rename to utils/gpt.js diff --git a/src/agent/history.js b/utils/history.js similarity index 98% rename from src/agent/history.js rename to utils/history.js index d8d469a..93d46be 100644 --- a/src/agent/history.js +++ b/utils/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 '../utils/gpt.js'; +import { sendRequest, embed, cosineSimilarity } from './gpt.js'; export class History { @@ -86,7 +86,7 @@ export class History { async loadExamples() { let examples = []; try { - const data = readFileSync('./src/examples.json', 'utf8'); + const data = readFileSync('utils/examples.json', 'utf8'); examples = JSON.parse(data); } catch (err) { console.log('No history examples found.'); diff --git a/src/utils/mcdata.js b/utils/mcdata.js similarity index 100% rename from src/utils/mcdata.js rename to utils/mcdata.js diff --git a/src/agent/queries.js b/utils/queries.js similarity index 100% rename from src/agent/queries.js rename to utils/queries.js diff --git a/src/agent/skill-library.js b/utils/skill-library.js similarity index 100% rename from src/agent/skill-library.js rename to utils/skill-library.js diff --git a/src/agent/skills.js b/utils/skills.js similarity index 99% rename from src/agent/skills.js rename to utils/skills.js index 1c9396e..2b119bc 100644 --- a/src/agent/skills.js +++ b/utils/skills.js @@ -1,4 +1,4 @@ -import { getItemId, getItemName } from "../utils/mcdata.js"; +import { getItemId, getItemName } from "./mcdata.js"; import { getNearestBlocks, getNearestBlock, getInventoryCounts, getInventoryStacks, getNearbyMobs, getNearbyBlocks } from "./world.js"; import pf from 'mineflayer-pathfinder'; import Vec3 from 'vec3'; diff --git a/src/agent/world.js b/utils/world.js similarity index 99% rename from src/agent/world.js rename to utils/world.js index 131e36d..9cf6749 100644 --- a/src/agent/world.js +++ b/utils/world.js @@ -1,4 +1,4 @@ -import { getAllBlockIds } from '../utils/mcdata.js'; +import { getAllBlockIds } from './mcdata.js'; export function getNearestBlocks(bot, block_types, distance=16, count=1) {