From 2f80b65d420d1aa4664de5f2d38c167caebdea58 Mon Sep 17 00:00:00 2001 From: Isadora White Date: Sun, 9 Mar 2025 13:01:54 -0700 Subject: [PATCH] fixing small bugs related to single agent support --- evaluation_script.py | 7 +++-- src/agent/tasks.js | 9 ++++-- src/models/prompter.js | 22 +++++++++------ tasks/single_agent/crafting_train.json | 38 ++++++++------------------ 4 files changed, 37 insertions(+), 39 deletions(-) diff --git a/evaluation_script.py b/evaluation_script.py index 661e526..0802cfc 100644 --- a/evaluation_script.py +++ b/evaluation_script.py @@ -146,7 +146,8 @@ def launch_parallel_experiments(task_path, template_profile=template_profile, model=model, api=api, - insecure_coding=insecure_coding) + insecure_coding=insecure_coding, + num_agents=num_agents) time.sleep(5) def launch_server_experiment(task_path, @@ -408,6 +409,7 @@ def main(): 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_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_parallel', default=1, type=int, help='Number of parallel servers to run') parser.add_argument('--exp_name', default="exp", help='Name of the experiment') @@ -442,7 +444,8 @@ def main(): model=args.model, api=args.api, world_name=args.world_name, - insecure_coding=args.insecure_coding) + insecure_coding=args.insecure_coding, + num_agents=args.num_agents) cmd = "aws s3" if __name__ == "__main__": diff --git a/src/agent/tasks.js b/src/agent/tasks.js index 0abfa34..e6a0955 100644 --- a/src/agent/tasks.js +++ b/src/agent/tasks.js @@ -149,6 +149,7 @@ export class Task { this.reset_function = null; this.blocked_actions = []; this.task_id = task_id; + console.log('Task ID:', task_id); if (task_path && task_id) { this.data = this.loadTask(task_path, task_id); this.task_type = this.data.type; @@ -219,12 +220,14 @@ export class Task { const tasksFile = readFileSync(task_path, 'utf8'); const tasks = JSON.parse(tasksFile); let task = tasks[task_id]; + console.log(task); + console.log(this.agent.count_id); if (!task) { throw new Error(`Task ${task_id} not found`); } - if ((!task.agent_count || task.agent_count <= 1) && this.agent.count_id > 0) { - task = null; - } + // if ((!task.agent_count || task.agent_count <= 1) && this.agent.count_id > 0) { + // task = null; + // } return task; } catch (error) { diff --git a/src/models/prompter.js b/src/models/prompter.js index 6efa2ec..d172208 100644 --- a/src/models/prompter.js +++ b/src/models/prompter.js @@ -331,7 +331,8 @@ export class Prompter { // } async saveToFile(logFile, logEntry) { - task_id = this.task_id; + let task_id = this.agent.task.task_id; + console.log(task_id) let logDir; if (this.task_id === null) { logDir = path.join(__dirname, `../../bots/${this.agent.name}/logs`); @@ -340,6 +341,8 @@ export class Prompter { } await fs.mkdir(logDir, { recursive: true }); + + logFile = path.join(logDir, logFile); await fs.appendFile(logFile, String(logEntry), 'utf-8'); } @@ -375,7 +378,7 @@ export class Prompter { } else { 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); } catch (error) { @@ -411,12 +414,14 @@ export class Prompter { prompt = await this.replaceStrings(prompt, messages, this.coding_examples); let logEntry; + const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); 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 { - 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); let resp = await this.code_model.sendRequest(messages, prompt); this.awaiting_coding = false; @@ -427,12 +432,13 @@ export class Prompter { await this.checkCooldown(); let prompt = this.profile.saving_memory; let logEntry; + const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); 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 { - 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); prompt = await this.replaceStrings(prompt, null, null, to_summarize); return await this.chat_model.sendRequest([], prompt); diff --git a/tasks/single_agent/crafting_train.json b/tasks/single_agent/crafting_train.json index 0da1b89..e950f35 100644 --- a/tasks/single_agent/crafting_train.json +++ b/tasks/single_agent/crafting_train.json @@ -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": { "goal": "Craft sticks.", "initial_inventory": {}, @@ -35,19 +46,6 @@ "type": "techtree", "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": { "goal": "Craft shears.", "initial_inventory": { @@ -64,9 +62,7 @@ "crafting_redstone": { "goal": "Get redstone.", "initial_inventory": { - "0": { - "iron_pickaxe": 1 - } + "iron_pickaxe": 1 }, "agent_count": 1, "target": "redstone", @@ -77,11 +73,9 @@ "crafting_light_gray_banner": { "goal": "Craft a light gray banner.", "initial_inventory": { - "0": { "shears": 1, "light_gray_dye": 7, "oak_planks": 1 - } }, "agent_count": 1, "target": "light_gray_banner", @@ -92,10 +86,8 @@ "crafting_brush_missing_copper_ingot_": { "goal": "Craft a brush.", "initial_inventory": { - "0": { "feather": 1, "diamond_pickaxe": 1 - } }, "agent_count": 1, "target": "brush", @@ -106,9 +98,7 @@ "crafting_shield_missing_planks": { "goal": "Craft a shield.", "initial_inventory": { - "0": { "iron_ingot": 6 - } }, "agent_count": 1, "target": "shield", @@ -119,9 +109,7 @@ "crafting_shield_missing_iron_ingot": { "goal": "Craft a shield.", "initial_inventory": { - "0": { "oak_planks": 7 - } }, "agent_count": 1, "target": "shield", @@ -132,9 +120,7 @@ "crafting_stone_hoe": { "goal": "Craft a stone hoe.", "initial_inventory": { - "0": { "wooden_pickaxe": 1 - } }, "agent_count": 1, "target": "stone_hoe",