From f9c41246f16924fd46987f755d2c48dccff56d94 Mon Sep 17 00:00:00 2001 From: MaxRobinsonTheGreat Date: Mon, 5 Feb 2024 13:21:32 -0600 Subject: [PATCH] added cancelResume for failed actions --- src/agent/coder.js | 8 ++++++-- src/agent/commands/actions.js | 7 ++++--- src/agent/library/skills.js | 2 +- src/examples.json | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/agent/coder.js b/src/agent/coder.js index 6ef83e9..aca2f5c 100644 --- a/src/agent/coder.js +++ b/src/agent/coder.js @@ -163,7 +163,6 @@ export class Coder { this.resume_func = func; this.resume_name = name; } - await new Promise(resolve => setTimeout(resolve, 500)); if (this.resume_func != null && this.agent.isIdle()) { this.interruptible = true; let res = await this.execute(this.resume_func, timeout); @@ -174,6 +173,11 @@ export class Coder { } } + cancelResume() { + this.resume_func = null; + this.resume_name = null; + } + // returns {success: bool, message: string, interrupted: bool, timedout: false} async execute(func, timeout=10) { if (!this.code_template) return {success: false, message: "Code template not loaded.", interrupted: false, timedout: false}; @@ -200,7 +204,7 @@ export class Coder { } catch (err) { this.executing = false; clearTimeout(TIMEOUT); - + this.cancelResume(); console.error("Code execution triggered catch: " + err); await this.stop(); diff --git a/src/agent/commands/actions.js b/src/agent/commands/actions.js index 78461ff..d9b88cf 100644 --- a/src/agent/commands/actions.js +++ b/src/agent/commands/actions.js @@ -35,8 +35,7 @@ export const actionsList = [ perform: async function (agent) { await agent.coder.stop(); agent.coder.clear(); - agent.coder.resume_func = null; - agent.coder.resume_name = null; + agent.coder.cancelResume(); return 'Agent stopped.'; } }, @@ -126,7 +125,9 @@ export const actionsList = [ 'type': '(string) The block type to collect. Ex: !collectAllBlocks("stone")' }, perform: wrapExecution(async (agent, type) => { - await skills.collectBlock(agent.bot, type, 1); + let success = await skills.collectBlock(agent.bot, type, 1); + if (!success) + agent.coder.cancelResume(); }, 10, 'collectAllBlocks') // 10 minute timeout }, { diff --git a/src/agent/library/skills.js b/src/agent/library/skills.js index 010bc16..5c080c3 100644 --- a/src/agent/library/skills.js +++ b/src/agent/library/skills.js @@ -373,7 +373,7 @@ export async function collectBlock(bot, blockType, num=1) { break; } log(bot, `Collected ${collected} ${blockType}.`); - return true; + return collected > 0; } export async function pickupNearbyItems(bot) { diff --git a/src/examples.json b/src/examples.json index 863a731..07c30be 100644 --- a/src/examples.json +++ b/src/examples.json @@ -54,7 +54,7 @@ ], [ - {"role": "user", "content": "billybob: stop"}, + {"role": "user", "content": "abc: stop"}, {"role": "assistant", "content": "Sure. !stop"} ],