Using app lock to restrict execution to a specific app
This example demonstrates how to use the app lock feature to keep automation within a specific app (WhatsApp in this case). The app lock ensures the agent stays in the messaging app even if the user accidentally navigates away.
class MessageResult(BaseModel): messages_sent: int = Field(..., description="Number of messages successfully sent") contacts: List[str] = Field(..., description="List of contacts messaged") success: bool = Field(..., description="Whether all messages were sent successfully")
Clear field descriptions help the LLM extract accurate data.
task = ( agent.new_task("Send 'Happy New Year!' message to Alice, Bob, and Charlie on WhatsApp") .with_name("send_new_year_messages") .with_locked_app_package("com.whatsapp") # Lock to WhatsApp .with_output_format(MessageResult) .with_max_steps(600) .build())
Key points:
with_locked_app_package() activates app lock with the WhatsApp package name
Use the full package name (Android: com.whatsapp or iOS: com.whatsapp)
Consider increasing max_steps for complex tasks with multiple interactions
Sending messages with app lock enabled...The agent will stay in WhatsApp and relaunch if needed.=== Messaging Complete ===Messages sent: 3Contacts: Alice, Bob, CharlieSuccess: True
from minitap.mobile_use.sdk.types import PlatformTaskRequest# The app lock configured on the platform is automatically appliedresult = await agent.run_task( request=PlatformTaskRequest(task="send-whatsapp-message"))
PlatformTaskRequest does not support overriding locked_app_package via SDK. To change the locked app, update the platform task configuration.
contacts = ["Alice", "Bob", "Charlie", "Diana", "Eve"]contact_list = ", ".join(contacts)task = agent.new_task( f"Send 'Happy New Year!' to {contact_list} on WhatsApp").with_locked_app_package("com.whatsapp")
Handle with profile
Copy
# Use a specific profile for better accuracytask = ( agent.new_task("Send messages to Alice, Bob, Charlie") .with_locked_app_package("com.whatsapp") .using_profile("accurate") # Use a more capable model)