Skip to content

Commit

Permalink
added cancelResume for failed actions
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxRobinsonTheGreat committed Feb 5, 2024
1 parent 7e80efb commit f9c4124
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/agent/coder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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};
Expand All @@ -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();

Expand Down
7 changes: 4 additions & 3 deletions src/agent/commands/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
}
},
Expand Down Expand Up @@ -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
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/agent/library/skills.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
],

[
{"role": "user", "content": "billybob: stop"},
{"role": "user", "content": "abc: stop"},
{"role": "assistant", "content": "Sure. !stop"}
],

Expand Down

0 comments on commit f9c4124

Please sign in to comment.