fixing small bugs related to single agent support

This commit is contained in:
Isadora White 2025-03-09 13:01:54 -07:00
parent 3576c6fb07
commit 2f80b65d42
4 changed files with 37 additions and 39 deletions

View file

@ -146,7 +146,8 @@ def launch_parallel_experiments(task_path,
template_profile=template_profile, template_profile=template_profile,
model=model, model=model,
api=api, api=api,
insecure_coding=insecure_coding) insecure_coding=insecure_coding,
num_agents=num_agents)
time.sleep(5) time.sleep(5)
def launch_server_experiment(task_path, def launch_server_experiment(task_path,
@ -408,6 +409,7 @@ def main():
parser = argparse.ArgumentParser(description='Run Minecraft AI agent experiments') parser = argparse.ArgumentParser(description='Run Minecraft AI agent experiments')
parser.add_argument('--task_path', default="multiagent_crafting_tasks.json", help='Path to the task file') parser.add_argument('--task_path', default="multiagent_crafting_tasks.json", help='Path to the task file')
parser.add_argument('--task_id', default=None, help='ID of the task to run') parser.add_argument('--task_id', default=None, help='ID of the task to run')
parser.add_argument('--num_agents', default=2, type=int, help='Number of agents to run')
parser.add_argument('--num_exp', default=1, type=int, help='Number of experiments to run') parser.add_argument('--num_exp', default=1, type=int, help='Number of experiments to run')
parser.add_argument('--num_parallel', default=1, type=int, help='Number of parallel servers to run') parser.add_argument('--num_parallel', default=1, type=int, help='Number of parallel servers to run')
parser.add_argument('--exp_name', default="exp", help='Name of the experiment') parser.add_argument('--exp_name', default="exp", help='Name of the experiment')
@ -442,7 +444,8 @@ def main():
model=args.model, model=args.model,
api=args.api, api=args.api,
world_name=args.world_name, world_name=args.world_name,
insecure_coding=args.insecure_coding) insecure_coding=args.insecure_coding,
num_agents=args.num_agents)
cmd = "aws s3" cmd = "aws s3"
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -149,6 +149,7 @@ export class Task {
this.reset_function = null; this.reset_function = null;
this.blocked_actions = []; this.blocked_actions = [];
this.task_id = task_id; this.task_id = task_id;
console.log('Task ID:', task_id);
if (task_path && task_id) { if (task_path && task_id) {
this.data = this.loadTask(task_path, task_id); this.data = this.loadTask(task_path, task_id);
this.task_type = this.data.type; this.task_type = this.data.type;
@ -219,12 +220,14 @@ export class Task {
const tasksFile = readFileSync(task_path, 'utf8'); const tasksFile = readFileSync(task_path, 'utf8');
const tasks = JSON.parse(tasksFile); const tasks = JSON.parse(tasksFile);
let task = tasks[task_id]; let task = tasks[task_id];
console.log(task);
console.log(this.agent.count_id);
if (!task) { if (!task) {
throw new Error(`Task ${task_id} not found`); throw new Error(`Task ${task_id} not found`);
} }
if ((!task.agent_count || task.agent_count <= 1) && this.agent.count_id > 0) { // if ((!task.agent_count || task.agent_count <= 1) && this.agent.count_id > 0) {
task = null; // task = null;
} // }
return task; return task;
} catch (error) { } catch (error) {

View file

@ -331,7 +331,8 @@ export class Prompter {
// } // }
async saveToFile(logFile, logEntry) { async saveToFile(logFile, logEntry) {
task_id = this.task_id; let task_id = this.agent.task.task_id;
console.log(task_id)
let logDir; let logDir;
if (this.task_id === null) { if (this.task_id === null) {
logDir = path.join(__dirname, `../../bots/${this.agent.name}/logs`); logDir = path.join(__dirname, `../../bots/${this.agent.name}/logs`);
@ -340,6 +341,8 @@ export class Prompter {
} }
await fs.mkdir(logDir, { recursive: true }); await fs.mkdir(logDir, { recursive: true });
logFile = path.join(logDir, logFile);
await fs.appendFile(logFile, String(logEntry), 'utf-8'); await fs.appendFile(logFile, String(logEntry), 'utf-8');
} }
@ -375,7 +378,7 @@ export class Prompter {
} else { } else {
logEntry = `[${timestamp}] Task ID: ${task_id}\nPrompt:\n${prompt}\n\nConversation:\n${JSON.stringify(messages, null, 2)}\n\nResponse:\n${generation}\n\n`; logEntry = `[${timestamp}] Task ID: ${task_id}\nPrompt:\n${prompt}\n\nConversation:\n${JSON.stringify(messages, null, 2)}\n\nResponse:\n${generation}\n\n`;
} }
const logFile = `conversation/${timestamp}.txt`; const logFile = `conversation_${timestamp}.txt`;
await this.saveToFile(logFile, logEntry); await this.saveToFile(logFile, logEntry);
} catch (error) { } catch (error) {
@ -411,12 +414,14 @@ export class Prompter {
prompt = await this.replaceStrings(prompt, messages, this.coding_examples); prompt = await this.replaceStrings(prompt, messages, this.coding_examples);
let logEntry; let logEntry;
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
if (this.task_id === null) { if (this.task_id === null) {
logEntry = `[${new Date().toISOString()}] \nPrompt:\n${prompt}\n\nConversation:\n${JSON.stringify(messages, null, 2)}\n\n`; logEntry = `[${timestamp}] \nPrompt:\n${prompt}\n\nConversation:\n${JSON.stringify(messages, null, 2)}\n\n`;
} else { } else {
logEntry = `[${new Date().toISOString()}] Task ID: ${this.agent.task.task_id}\nPrompt:\n${prompt}\n\nConversation:\n${JSON.stringify(messages, null, 2)}\n\n`; logEntry = `[${timestamp}] Task ID: ${this.agent.task.task_id}\nPrompt:\n${prompt}\n\nConversation:\n${JSON.stringify(messages, null, 2)}\n\n`;
} }
const logFile = `coding/${timestamp}.txt`;
const logFile = `coding_${timestamp}.txt`;
await this.saveToFile(logFile, logEntry); await this.saveToFile(logFile, logEntry);
let resp = await this.code_model.sendRequest(messages, prompt); let resp = await this.code_model.sendRequest(messages, prompt);
this.awaiting_coding = false; this.awaiting_coding = false;
@ -427,12 +432,13 @@ export class Prompter {
await this.checkCooldown(); await this.checkCooldown();
let prompt = this.profile.saving_memory; let prompt = this.profile.saving_memory;
let logEntry; let logEntry;
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
if (this.task_id === null) { if (this.task_id === null) {
logEntry = `[${new Date().toISOString()}] \nPrompt:\n${prompt}\n\nTo Summarize:\n${JSON.stringify(messages, null, 2)}\n\n`; logEntry = `[${timestamp}] \nPrompt:\n${prompt}\n\nTo Summarize:\n${JSON.stringify(messages, null, 2)}\n\n`;
} else { } else {
logEntry = `[${new Date().toISOString()}] Task ID: ${this.agent.task.task_id}\nPrompt:\n${prompt}\n\nConversation:\n${JSON.stringify(messages, null, 2)}\n\n`; logEntry = `[${timestamp}] Task ID: ${this.agent.task.task_id}\nPrompt:\n${prompt}\n\nConversation:\n${JSON.stringify(to_summarize, null, 2)}\n\n`;
} }
const logFile = `memSaving/${timestamp}.txt`; const logFile = `memSaving_${timestamp}.txt`;
await this.saveToFile(logFile, logEntry); await this.saveToFile(logFile, logEntry);
prompt = await this.replaceStrings(prompt, null, null, to_summarize); prompt = await this.replaceStrings(prompt, null, null, to_summarize);
return await this.chat_model.sendRequest([], prompt); return await this.chat_model.sendRequest([], prompt);

View file

@ -1,4 +1,15 @@
{ {
"crafting_iron_pickaxe": {
"goal": "Craft an iron pickaxe.",
"initial_inventory": {
"stone_pickaxe": 1
},
"agent_count": 1,
"target": "iron_pickaxe",
"number_of_target": 1,
"type": "techtree",
"timeout": 500
},
"crafting_stick": { "crafting_stick": {
"goal": "Craft sticks.", "goal": "Craft sticks.",
"initial_inventory": {}, "initial_inventory": {},
@ -35,19 +46,6 @@
"type": "techtree", "type": "techtree",
"timeout": 500 "timeout": 500
}, },
"crafting_iron_pickaxe": {
"goal": "Craft an iron pickaxe.",
"initial_inventory": {
"0": {
"stone_pickaxe": 1
}
},
"agent_count": 1,
"target": "iron_pickaxe",
"number_of_target": 1,
"type": "techtree",
"timeout": 500
},
"crafting_shears": { "crafting_shears": {
"goal": "Craft shears.", "goal": "Craft shears.",
"initial_inventory": { "initial_inventory": {
@ -64,9 +62,7 @@
"crafting_redstone": { "crafting_redstone": {
"goal": "Get redstone.", "goal": "Get redstone.",
"initial_inventory": { "initial_inventory": {
"0": { "iron_pickaxe": 1
"iron_pickaxe": 1
}
}, },
"agent_count": 1, "agent_count": 1,
"target": "redstone", "target": "redstone",
@ -77,11 +73,9 @@
"crafting_light_gray_banner": { "crafting_light_gray_banner": {
"goal": "Craft a light gray banner.", "goal": "Craft a light gray banner.",
"initial_inventory": { "initial_inventory": {
"0": {
"shears": 1, "shears": 1,
"light_gray_dye": 7, "light_gray_dye": 7,
"oak_planks": 1 "oak_planks": 1
}
}, },
"agent_count": 1, "agent_count": 1,
"target": "light_gray_banner", "target": "light_gray_banner",
@ -92,10 +86,8 @@
"crafting_brush_missing_copper_ingot_": { "crafting_brush_missing_copper_ingot_": {
"goal": "Craft a brush.", "goal": "Craft a brush.",
"initial_inventory": { "initial_inventory": {
"0": {
"feather": 1, "feather": 1,
"diamond_pickaxe": 1 "diamond_pickaxe": 1
}
}, },
"agent_count": 1, "agent_count": 1,
"target": "brush", "target": "brush",
@ -106,9 +98,7 @@
"crafting_shield_missing_planks": { "crafting_shield_missing_planks": {
"goal": "Craft a shield.", "goal": "Craft a shield.",
"initial_inventory": { "initial_inventory": {
"0": {
"iron_ingot": 6 "iron_ingot": 6
}
}, },
"agent_count": 1, "agent_count": 1,
"target": "shield", "target": "shield",
@ -119,9 +109,7 @@
"crafting_shield_missing_iron_ingot": { "crafting_shield_missing_iron_ingot": {
"goal": "Craft a shield.", "goal": "Craft a shield.",
"initial_inventory": { "initial_inventory": {
"0": {
"oak_planks": 7 "oak_planks": 7
}
}, },
"agent_count": 1, "agent_count": 1,
"target": "shield", "target": "shield",
@ -132,9 +120,7 @@
"crafting_stone_hoe": { "crafting_stone_hoe": {
"goal": "Craft a stone hoe.", "goal": "Craft a stone hoe.",
"initial_inventory": { "initial_inventory": {
"0": {
"wooden_pickaxe": 1 "wooden_pickaxe": 1
}
}, },
"agent_count": 1, "agent_count": 1,
"target": "stone_hoe", "target": "stone_hoe",