Add autocomplete menu and app scoping with @AppName prefix#15
Conversation
Implement a temporary bootstrapping method to scope the agent's available tools to a specific app by prefixing the user message with `@AppName`. Add parsing logic in `AgentOrchestrator.kt` to extract `@AppName` and match it against installed apps. Sort installed apps by descending label length to resolve ambiguities (e.g., matching "@google Maps" before "@google"). Filter tools passed to the LLM to only include those from the matched app package. Strip the `@AppName ` prefix from the prompt sent to the LLM. Add unit test `observeAndProcessMessages scopes tools by app name` in `AgentOrchestratorTest.kt` to verify filtering and prefix stripping. This is a temporary solution for b/508130322 and will be replaced by UI-provided metadata in b/521319810. BUG=b/508130322 Change-Id: If7d06388f5023b26f952074d8ab5de62eb23ba01
Transition the app-scoping feature from the temporary text-parsing bootstrap (b/508130322) to a robust, database-driven metadata architecture (b/521319810). This CL implements metadata-backed tool filtering, a keyboard-friendly autocomplete suggestions menu, and rich visual mention styling. Database & Pipeline: - Add a nullable `targetPackageName: String? = null` column to `MessageEntity` to store the scoped package name securely. - Bump database version to 2 and configure Room with `.fallbackToDestructiveMigration()` in `DataModule.kt` to automatically handle schema updates during development. - Update `SendMessageUseCase.kt` to accept and pass `targetPackageName` to the database. - Simplify `AgentOrchestrator.kt` by completely deleting the obsolete prefix-parsing engine. The orchestrator now reads the package scope directly from database metadata and passes the raw user prompt to the LLM unchanged (leaving the `@AppName` mention in the prompt). UI & Autocomplete Menu: - Refactor the chat input state from `String` to `TextFieldValue` to enable explicit cursor management. - Replace the default `DropdownMenu` with a custom floating `Popup` positioned exactly 2.dp above the `OutlinedTextField` using `PopupPositionProvider` to prevent keyboard overlap. - Support multi-word space searching in the autocomplete query (e.g. typing `@AppFunction Testing Agent I` continues searching and refines the list until no match is found, at which point the dropdown disappears). - Snap the active insertion cursor automatically to the very end of the text field (after the trailing space) upon selecting an autocomplete item to allow seamless typing. - Style active mentions inside the `OutlinedTextField` as bold purple text with no background. - Render historical mentions in the `MessageBubble` chat history as premium rounded chips with exactly 4.dp horizontal padding and 6.dp rounded corners using a custom `drawBehind` Canvas modifier. - Reactively reset the active package scope to null if the user deletes a mention in the input field. ViewModel Refinement: - Inject `GetAppFunctionsUseCase` into `AgentDemoViewModel.kt` and reactively filter the autocomplete app list to ONLY display apps that actually have registered AppFunctions (tools), preventing useless app scopes. Tests & Verification: - Remove obsolete prefix-parsing tests in `AgentOrchestratorTest.kt` and replace them with robust metadata-scoping tests. - Update all ViewModel constructor sites in `AgentDemoViewModelTest.kt` with mocked use cases. Change-Id: I0161976d85433e5a672fc2cd2d95595a1cf930c3
There was a problem hiding this comment.
Code Review
This pull request introduces app-scoping functionality to the agent demo, allowing users to target specific apps using '@' mentions. Key changes include database updates to store the target package name, orchestrator refactoring to filter tools, and UI enhancements in AgentDemoScreen to support autocomplete and styled mention chips. The review feedback identifies several critical improvements: fixing a data-loss bug when selecting autocomplete suggestions mid-sentence, replacing fragile custom-drawn mention backgrounds with Jetpack Compose's InlineTextContent to handle multi-line wrapping, refining the autocomplete trigger to avoid activating on email addresses, simplifying mention validation, and offloading blocking binder calls to Dispatchers.IO in the view model to prevent UI stutter.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Change-Id: Iabacf439b9bb753325399289792f2a5138c4cd72
What I have done and why
This PR adds an autocomplete suggestions menu and app-scoped tool filtering to the agent demo. When a user types
@in the chat input, they can select an installed app to restrict the agent's available tools exclusively to that application.Feature Highlights:
Smart App Filtering: Dynamically filters the
@dropdown to only suggest installed apps that actually have registeredAppFunctionson the device.Floating Popup: Renders an autocomplete card positioned above the chat input, supporting multi-word search queries containing spaces.
Seamless Typing: Automatically snaps the cursor to the end of the inserted app mention so the user can immediately continue typing their prompt without tapping.
Native Chip Styling: Draws historical
@AppNamementions inside chat bubbles as rounded purple chips.Process-Death Safe: Stores the scoped
targetPackageNamesafely in the Room database (MessageEntity).