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

View file

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

View file

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

View file

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