Automation API

Android device automation

AgentControl

Interface

Control automation execution

Access control methods through agent.control. Provides methods to control the automation execution flow.

AgentControl Interface
TypeScript
interface AgentControl {
stopCurrentAutomation(): void;
}

Methods

stopCurrentAutomation()

TypeScript
stopCurrentAutomation(): void

Immediately stops the current automation execution. Use this to gracefully terminate an automation when a condition is met or an error occurs.

Examples

Stop on error
TypeScript
try {
await performCriticalAction();
} catch (error) {
console.log("Critical error, stopping automation");
agent.control.stopCurrentAutomation();
}
Stop when goal is achieved
TypeScript
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
TypeScript
function cleanup() {
// Save state, close resources, etc.
console.log("Cleaning up...");
}
// On critical failure
cleanup();
agent.control.stopCurrentAutomation();

Note

When stopCurrentAutomation() is called, any code after the call will not execute. The automation terminates immediately.