cleaned init params

This commit is contained in:
Maximus 2023-12-21 20:42:01 -07:00
parent c0da4a58f0
commit 1a854fe0d5
8 changed files with 29 additions and 124 deletions

3
.gitignore vendored
View file

@ -3,4 +3,5 @@ node_modules/
package-lock.json
scratch.js
!agent_code/template.js
bots/**/action-code/**
bots/**/action-code/**
bots/**/save.json

View file

@ -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."
}
]
}

View file

@ -1,3 +1,3 @@
import { AgentProcess } from './src/process/agent-process.js';
new AgentProcess('andy').start(true, false);
new AgentProcess('andy').start('assist');

View file

@ -8,16 +8,14 @@ import { Events } from './events.js';
export class Agent {
constructor(name, save_path, load_path=null, init_message=null) {
constructor(name, profile=null, init_message=null) {
this.name = name;
this.bot = initBot(name);
this.history = new History(this, save_path);
this.history = new History(this);
this.history.loadExamples();
this.coder = new Coder(this);
if (load_path) {
this.history.load(load_path);
}
this.history.load(profile);
this.events = new Events(this, this.history.events)

View file

@ -1,4 +1,4 @@
import { writeFile, readFile, unlink } from 'fs';
import { writeFile, readFile, unlink, mkdirSync } from 'fs';
export class Coder {
constructor(agent) {
@ -17,6 +17,8 @@ export class Coder {
if (err) throw err;
this.code_template = data;
});
mkdirSync('.' + this.fp, { recursive: true });
}
queueCode(code) {

View file

@ -5,9 +5,9 @@ import { sendRequest, embed, cosineSimilarity } from '../utils/gpt.js';
export class History {
constructor(agent, save_path) {
constructor(agent) {
this.name = agent.name;
this.save_path = save_path;
this.save_path = `./bots/${this.name}/save.json`;
this.turns = [];
// These define an agent's long term memory
@ -148,12 +148,9 @@ export class History {
await this.setExamples();
}
save(save_path=null) {
if (save_path == null)
save_path = this.save_path;
if (save_path === '' || save_path == null) return;
save() {
// save history object to json file
mkdirSync('bots', { recursive: true });
mkdirSync(`./bots/${this.name}`, { recursive: true });
let data = {
'name': this.name,
'bio': this.bio,
@ -162,7 +159,7 @@ export class History {
'turns': this.turns
};
const json_data = JSON.stringify(data, null, 4);
writeFileSync(save_path, json_data, (err) => {
writeFileSync(this.save_path, json_data, (err) => {
if (err) {
throw err;
}
@ -170,10 +167,8 @@ export class History {
});
}
load(load_path=null) {
if (load_path == null)
load_path = this.save_path;
if (load_path === '' || load_path == null) return;
load(profile) {
const load_path = profile? `./bots/${this.name}/${profile}.json` : this.save_path;
try {
// load history object from json file
const data = readFileSync(load_path, 'utf8');
@ -183,8 +178,7 @@ export class History {
this.events = obj.events;
this.turns = obj.turns;
} catch (err) {
console.log('No history file found for ' + this.name + '.');
console.log(load_path);
console.error(`No file for profile '${load_path}' for agent ${this.name}.`);
}
}
}

View file

@ -4,13 +4,12 @@ export class AgentProcess {
constructor(name) {
this.name = name;
}
start(clear_memory=false, autostart=false, profile='assist') {
start(profile='assist', init_message=null) {
let args = ['src/process/init-agent.js', this.name];
args.push('-p', profile);
if (clear_memory)
args.push('-c');
if (autostart)
args.push('-a');
if (profile)
args.push('-p', profile);
if (init_message)
args.push('-m', init_message);
const agentProcess = spawn('node', args, {
stdio: 'inherit',
@ -28,7 +27,7 @@ export class AgentProcess {
process.exit(1);
}
console.log('Restarting agent...');
this.start(false, true);
this.start('save', 'Agent process restarted. Notify the user and decide what to do.');
last_restart = Date.now();
}
});

View file

@ -3,7 +3,7 @@ import yargs from 'yargs';
const args = process.argv.slice(2);
if (args.length < 1) {
console.log('Usage: node init_agent.js <agent_name> [-c] [-a]');
console.log('Usage: node init_agent.js <agent_name> [profile] [init_message]');
process.exit(1);
}
@ -13,20 +13,11 @@ const argv = yargs(args)
type: 'string',
description: 'profile to use for agent'
})
.option('clear_memory', {
alias: 'c',
type: 'boolean',
description: 'restart memory from scratch'
})
.option('autostart', {
alias: 'a',
type: 'boolean',
.option('init_message', {
alias: 'm',
type: 'string',
description: 'automatically prompt the agent on startup'
}).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 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);
const name = args[0];
new Agent(name, argv.profile, argv.init_message);