Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.
feat: enhance AppNavigator system prompt, expand tool definitions, and increase result logging limit
Rishabh Bajpai5feb92857659
diff --git a/app/src/main/java/com/gotcha/tools/AppNavigatorSession.kt b/app/src/main/java/com/gotcha/tools/AppNavigatorSession.ktindex 2ca90f5..eba7f04 100644--- a/app/src/main/java/com/gotcha/tools/AppNavigatorSession.kt+++ b/app/src/main/java/com/gotcha/tools/AppNavigatorSession.kt@@ -130,9 +130,9 @@ class AppNavigatorSession(for (call in toolCalls) {val result = executeWithRetry(call)val summary = if (result.success) {- result.message.take(100)+ result.message.take(300)} else {- "⚠ ${result.message.take(100)}"+ "⚠ ${result.message.take(300)}"}actionLog.add("Step $step: ${call.function.name} → $summary")onStep(call.function.name, "completed", summary)@@ -192,27 +192,53 @@ class AppNavigatorSession(}private const val NAVIGATOR_SYSTEM_PROMPT = """-You are a mobile app navigation agent. Your job is to operate Android apps step by step.+You are a mobile app navigation agent. Your job is to operate Android apps step by step to complete the given task.++## App Launching+- Use open_app to launch an app directly by name (e.g. "Settings" or "Google Maps"). Do NOT navigate through the home screen or app drawer — that wastes steps.+- After launching an app, call sleep(2-3) to let it load before interacting.+- Use global_action(recents) to switch between running apps.## Rules-- Take ONE action per turn. After acting, a fresh screenshot will show you the result.-- The UI Elements list gives you precise positions. The screenshot gives visual context.-- A coordinate grid is overlaid on the screenshot to help ground coordinates.-- Prefer tap_index over raw coordinates (it's more precise).+- Take ONE action per turn. After acting, a fresh screenshot and element list will show you the result.+- The UI Elements list gives you precise element indices. The screenshot gives visual context with a coordinate grid.+- Prefer tap_index over raw coordinates — it is more precise and survives layout changes.- When using coordinates, values are in [0, 1000] normalized space.-- Never repeat an action that already failed.-- Call ask_final_answer when the task is complete — include a clear summary.+- Never repeat an action that already failed the same way.+- If an action fails, try a different approach on the next turn.++## Error Recovery+- If tap_index fails: the element may not be visible yet. Swipe to scroll, wait with sleep, or check if you need to navigate to a different screen first.+- If the screen looks the same after an action: you may need to wait longer (sleep(2)), or try swiping to reveal content.+- When an element index seems wrong, the screen may have changed since the last scan — the fresh data at the start of this turn is current.+- Use search_skills to look up guidance on how to use an unfamiliar app. Call it once with the app name.+- If you cannot find what you need after several attempts, call ask_final_answer to report what you found (or did not find).++## Text Input+- Use input_text(text, index=N) to type into a specific text field. Always include the index when possible.+- After typing, call press_key(enter) to submit the text (e.g. for search bars, login fields).+- If the field content looks wrong, tap on it first to focus it, then input_text again.++## Swipe / Scroll+- Swipe 'down' to scroll down (reveals lower content further down the page).+- Swipe 'up' to scroll up (reveals content above the current view).+- To scroll a specific element (e.g. a list inside a screen), pass the element's index.+- Pass a small distance value for short scrolls (e.g. to reveal a button just off-screen).## Available Actions+- open_app(name) — launch an app directly (preferred over navigating home screen)- tap_index(index) — tap an element by its number from the UI Elements list-- tap(x, y, normalized=true) — tap at normalized coordinate (0-1000 space)+- tap(x, y, normalized=true) — tap at normalized coordinates- long_press_index(index) — long-press an element by its number-- long_press(x, y, normalized=true) — long-press at normalized coordinate-- swipe(direction) or swipe(x1,y1,x2,y2, normalized=true) — swipe/scroll-- input_text(text) — type into the focused field-- press_key(key) — back, home, enter-- sleep(duration_seconds) — wait briefly (1-3)-- ask_final_answer(answer) — done! Provide the final summary.+- long_press(x, y, normalized=true) — long-press at coordinates+- swipe(direction, distance?, index?) — scroll the screen or a specific element+- input_text(text, index?) — type text, optionally into a specific field+- press_key(key) — press enter, back, or home+- global_action(action) — recents, notifications, quick_settings, lock_screen+- sleep(duration_seconds) — wait for loading or animations (1-30 seconds)+- search_skills(query) — look up how to use an app or perform an action+- list_installed_apps(search?) — find the correct app name or package name+- ask_final_answer(answer) — task is complete. Provide a clear summary of what was done."""}}diff --git a/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt b/app/src/main/java/com/gotcha/tools/ToolDefinitions.ktindex 123dcac..8a0d528 100644--- a/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt+++ b/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt@@ -1485,9 +1485,8 @@ object ToolDefinitions {val navigateApp = tool("navigate_app",- "Open apps and navigate them step by step. Provide a detailed description of " +- "what to do — the App Navigator will look at the screen, tap, swipe, type, " +- "and scroll until the task is done. " ++ "Navigate inside apps step by step — open the app, tap, swipe, type, and scroll " ++ "until the task is done. Provide clear numbered steps as the task description. " +"Only available to Operator mode. Cannot be called from within a sub-agent.",schema {putJsonObject("properties") {@@ -1495,11 +1494,15 @@ object ToolDefinitions {put("type", "string")put("description",- "Detailed step-by-step instructions of what to do in the app. " +- "Include the app name, search terms, what to look for, and what the final " +- "summary should contain. " +- "Example: 'Open Google Maps, search for restaurants near me, scroll through " +- "results, and tell me the top 5 with ratings and distances.'"+ "Step-by-step instructions of what to do. Include the app name, what to tap, " ++ "what to type, and what to report back. Using numbered steps improves accuracy.\n\n" ++ "Example:\n" ++ "1. Open the Google Play Store app\n" ++ "2. Tap on the search bar at the top\n" ++ "3. Type 'Spotify' and press enter\n" ++ "4. Tap on the Spotify result\n" ++ "5. Scroll down to see the rating\n" ++ "6. Report the app rating and number of downloads")}}diff --git a/app/src/main/java/com/gotcha/tools/ToolRegistry.kt b/app/src/main/java/com/gotcha/tools/ToolRegistry.ktindex 24335c8..8ad1b67 100644--- a/app/src/main/java/com/gotcha/tools/ToolRegistry.kt+++ b/app/src/main/java/com/gotcha/tools/ToolRegistry.kt@@ -47,6 +47,7 @@ object ToolRegistry {/** Tools available to the App Navigator sub-agent. */val navigatorTools: Set<String> = setOf("tap", "tap_index", "long_press", "long_press_index", "swipe", "input_text", "press_key",+ "global_action", "open_app", "list_installed_apps", "search_skills","sleep", "ask_final_answer")@@ -153,7 +154,11 @@ object ToolRegistry {}putJsonObject("index") {put("type", "integer")- put("description", "Optional element index to scroll")+ put("description", "Optional element index to scroll within")+ }+ putJsonObject("distance") {+ put("type", "integer")+ put("description", "Optional scroll distance in pixels (smaller = shorter scroll)")}}putJsonArray("required") { add("direction") }@@ -163,7 +168,7 @@ object ToolRegistry {"input_text" to ToolDefinition(function = FunctionDefinition("input_text",- "Type text into a field. Provide 'index' to target it directly.",+ "Type text into a field. Provide 'index' to target it directly. After typing, press_key(enter) may be needed to submit.",buildJsonObject {put("type", "object")putJsonObject("properties") {@@ -173,7 +178,7 @@ object ToolRegistry {}putJsonObject("index") {put("type", "integer")- put("description", "Element index")+ put("description", "Element index to target (optional)")}}putJsonArray("required") { add("text") }@@ -183,13 +188,13 @@ object ToolRegistry {"press_key" to ToolDefinition(function = FunctionDefinition("press_key",- "Press a system key: back, home, enter.",+ "Press enter to submit text input, or press back/home for navigation.",buildJsonObject {put("type", "object")putJsonObject("properties") {putJsonObject("key") {put("type", "string")- put("description", "back, home, enter")+ put("description", "enter, back, or home")}}putJsonArray("required") { add("key") }@@ -199,13 +204,13 @@ object ToolRegistry {"sleep" to ToolDefinition(function = FunctionDefinition("sleep",- "Wait for a short time (max 3s).",+ "Wait for animations or app loading.",buildJsonObject {put("type", "object")putJsonObject("properties") {putJsonObject("duration_seconds") {put("type", "integer")- put("description", "Seconds (1-3)")+ put("description", "Seconds to wait (1-30)")}}putJsonArray("required") { add("duration_seconds") }@@ -227,6 +232,70 @@ object ToolRegistry {putJsonArray("required") { add("answer") }})+ ),+ "open_app" to ToolDefinition(+ function = FunctionDefinition(+ "open_app",+ "Launch an app by its name (e.g. 'Settings', 'Google Maps') or package name.",+ buildJsonObject {+ put("type", "object")+ putJsonObject("properties") {+ putJsonObject("package_name") {+ put("type", "string")+ put("description", "App name or package name (e.g. 'Gmail', 'com.google.android.gm')")+ }+ }+ putJsonArray("required") { add("package_name") }+ }+ )+ ),+ "global_action" to ToolDefinition(+ function = FunctionDefinition(+ "global_action",+ "Perform a system-level action: recents (overview), notifications (shade), " ++ "quick_settings, lock_screen, back, home.",+ buildJsonObject {+ put("type", "object")+ putJsonObject("properties") {+ putJsonObject("action") {+ put("type", "string")+ put("description", "recents, notifications, quick_settings, lock_screen, back, or home")+ }+ }+ putJsonArray("required") { add("action") }+ }+ )+ ),+ "search_skills" to ToolDefinition(+ function = FunctionDefinition(+ "search_skills",+ "Search for guidance on how to interact with a specific app or perform a system operation.",+ buildJsonObject {+ put("type", "object")+ putJsonObject("properties") {+ putJsonObject("query") {+ put("type", "string")+ put("description", "The app name or operation to search for (e.g. 'Gmail', 'Settings search')")+ }+ }+ putJsonArray("required") { add("query") }+ }+ )+ ),+ "list_installed_apps" to ToolDefinition(+ function = FunctionDefinition(+ "list_installed_apps",+ "List installed apps to find the correct name or package name for open_app.",+ buildJsonObject {+ put("type", "object")+ putJsonObject("properties") {+ putJsonObject("search") {+ put("type", "string")+ put("description", "Optional search term to filter apps by name")+ }+ }+ }+ )))