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,
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__":

View file

@ -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) {

View file

@ -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);

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": {
"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",