From 88e0174ef1a9c23ef65b2d3ad5f4cb329d7607a1 Mon Sep 17 00:00:00 2001 From: Kolby Nottingham Date: Tue, 10 Dec 2024 13:13:45 -0800 Subject: [PATCH] task fixes --- example_tasks.json | 15 ++++++--------- src/agent/agent.js | 18 +++++++++--------- src/process/init-agent.js | 9 +++++++-- src/utils/tasks.js | 22 ++++++++++------------ 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/example_tasks.json b/example_tasks.json index 8fcff1e..ddd37aa 100644 --- a/example_tasks.json +++ b/example_tasks.json @@ -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" diff --git a/src/agent/agent.js b/src/agent/agent.js index d2adfe2..d14921b 100644 --- a/src/agent/agent.js +++ b/src/agent/agent.js @@ -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() { diff --git a/src/process/init-agent.js b/src/process/init-agent.js index f91faa2..88c99b9 100644 --- a/src/process/init-agent.js +++ b/src/process/init-agent.js @@ -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', diff --git a/src/utils/tasks.js b/src/utils/tasks.js index 0b3377c..0fdb717 100644 --- a/src/utils/tasks.js +++ b/src/utils/tasks.js @@ -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) {