agent.control
InterfaceControl the automation execution flow.
AgentControl Interface
interface AgentControl {
stopCurrentAutomation(): void;
}stopCurrentAutomation
Signature
stopCurrentAutomation(): voidImmediately stops the current automation execution. Use this to gracefully terminate an automation when a condition is met or an error occurs.
Stop on error
try {
await performCriticalAction();
} catch (error) {
console.log("Critical error, stopping automation");
agent.control.stopCurrentAutomation();
}Stop when goal is achieved
const screen = await agent.actions.screenContent();
const successMessage = screen.findTextOne("Order Confirmed");
if (successMessage) {
console.log("Task completed successfully!");
agent.control.stopCurrentAutomation();
}Stop with cleanup
function cleanup() {
// Save state, close resources, etc.
console.log("Cleaning up...");
}
// On critical failure
cleanup();
agent.control.stopCurrentAutomation();When
stopCurrentAutomation() is called, any code after the call will not execute. The automation terminates immediately.