task fixes

This commit is contained in:
Kolby Nottingham 2024-12-10 13:13:45 -08:00
parent a15ab15bcd
commit 88e0174ef1
4 changed files with 32 additions and 32 deletions

View file

@ -23,17 +23,15 @@
},
"construction": {
"type": "construction",
"goal": "Build a house"
"goal": "Build a house",
"initial_inventory": {
"oak_planks": 20
}
},
"techtree_1_shears_with_2_iron_ingot": {
"goal": "Build a shear.",
"initial_inventory": {
"andy": {
"iron_ingot": 1
},
"randy": {
"iron_ingot": 1
}
"iron_ingot": 1
},
"target": "shears",
"number_of_target": 1,
@ -41,8 +39,7 @@
"timeout": 60
},
"multiagent_techtree_1_stone_pickaxe": {
"goal": "Collaborate with other agents to build an stone pickaxe",
"conversation": "Let's build a stone pickaxe",
"conversation": "Let's collaborate to build a stone pickaxe",
"agent_names": [
"andy",
"randy"

View file

@ -8,7 +8,7 @@ import { ActionManager } from './action_manager.js';
import { NPCContoller } from './npc/controller.js';
import { MemoryBank } from './memory_bank.js';
import { SelfPrompter } from './self_prompter.js';
import { isOtherAgent, initConversationManager, sendToBot, endAllChats, responseScheduledFor, inConversation } from './conversation.js';
import { isOtherAgent, initConversationManager, sendToBot, endAllChats, responseScheduledFor } from './conversation.js';
import { handleTranslation, handleEnglishTranslation } from '../utils/translator.js';
import { addViewer } from './viewer.js';
import settings from '../../settings.js';
@ -78,7 +78,6 @@ export class Agent {
this.validator = null;
this.blocked_actions = [];
}
console.log("Is validated:", this.validator && this.validator.validate());
this.bot.on('login', () => {
console.log(this.name, 'logged in!');
@ -438,15 +437,18 @@ export class Agent {
}
}, INTERVAL);
this.bot.emit('idle');
// Check for task completion
if (this.task) {
setInterval(async () => {
setInterval(() => {
if (this.validator && this.validator.validate())
this.killBots();
if (this.task.goal && !this.self_prompter.on)
this.cleanKill('Task unsuccessful: Agent ended goal', 3);
if (this.task.conversation && !inConversation())
this.cleanKill('Task unsuccessful: Agent ended conversation', 3);
// TODO check for other terminal conditions
// if (this.task.goal && !this.self_prompter.on)
// this.cleanKill('Agent ended goal', 3);
// if (this.task.conversation && !inConversation())
// this.cleanKill('Agent ended conversation', 3);
if (this.taskTimeout) {
const elapsedTime = (Date.now() - this.taskStartTime) / 1000;
if (elapsedTime >= this.taskTimeout) {
@ -457,8 +459,6 @@ export class Agent {
}, 1000);
}
this.bot.emit('idle');
}
async killBots() {

View file

@ -33,9 +33,14 @@ const argv = yargs(args)
type: 'string',
description: 'automatically prompt the agent on startup'
})
.option('task', {
.option('task_path', {
alias: 't',
type: 'string',
description: 'task filepath to use for agent'
})
.option('task_id', {
alias: 'i',
type: 'string',
description: 'task ID to execute'
})
.option('count_id', {
@ -50,7 +55,7 @@ const argv = yargs(args)
try {
console.log('Starting agent with profile:', argv.profile);
const agent = new Agent();
await agent.start(argv.profile, argv.load_memory, argv.init_message, argv.count_id, argv.task);
await agent.start(argv.profile, argv.load_memory, argv.init_message, argv.count_id, argv.task_path, argv.task_id);
} catch (error) {
console.error('Failed to start agent process:', {
message: error.message || 'No error message',

View file

@ -1,18 +1,17 @@
import yaml from 'js-yaml'
import { readFileSync } from 'fs';
import { executeCommand } from './commands/index.js';
import { getPosition } from './library/world.js'
import { isOtherAgent } from '../agent/conversation.js';
import { executeCommand } from '../agent/commands/index.js';
import { getPosition } from '../agent/library/world.js'
export function loadTask(taskId) {
export function loadTask(task_path, task_id) {
try {
const taskType = taskId.split('_')[0];
const tasksFile = readFileSync(`tasks/${taskType}_tasks.yaml`, 'utf8');
const tasks = yaml.load(tasksFile);
const task = tasks[taskId];
const tasksFile = readFileSync(task_path, 'utf8');
const tasks = JSON.parse(tasksFile);
const task = tasks[task_id];
if (!task) {
throw new Error(`Task ${taskId} not found`);
throw new Error(`Task ${task_id} not found`);
}
return task;
} catch (error) {
console.error('Error loading task:', error);
@ -30,8 +29,7 @@ export async function initBotTask(agent) {
//wait for a bit so inventory is cleared
await new Promise((resolve) => setTimeout(resolve, 500));
console.log("agent_number" in task.agent_number > 1);
if ("agent_number" in task.agent_number > 1) {
if (task.agent_number > 1) {
var initial_inventory = task.initial_inventory[bot.username];
console.log("Initial inventory:", initial_inventory);
} else if (task) {