Repository navigation
refactor(agent): unify AppFunction discovery, input conversion, and execution - #65
Merged
mingweiliao merged 2 commits intoOct 29, 2026
Conversation
…xecution Extract shared tool discovery, input conversion, and execution logic out of AgentOrchestrator into the core AppFunction use cases so chat, debugging, and future live voice orchestration share a single pipeline: - Evolve GetAppFunctionsUseCase with GetAppFunctionsParams (targetPackageNames, isEnabled, isConnected, includeInternalTools) and expose shared internal package metadata in AgentInternalTools. - Evolve ConvertInputToAppFunctionDataUseCase to resolve remote HTTP/HTTPS file reference URLs into local FileProvider content:// URIs during conversion to AppFunctionData. - Evolve ExecuteAppFunctionUseCase to dispatch internal agent tools directly from AppFunctionData and recursively grant content:// read URI permissions to target packages before executing external AppFunctions. - Update AgentOrchestrator and existing external-app-only callers (GetConnectedAppsUseCase, TroubleshootAppUseCase, AgentDemoViewModel, DebuggingViewModel) and expand unit/instrumented test coverage.
Closed
mingweiliao
requested changes
Oct 28, 2026
… PR review - Extract ResolveRemoteFileToLocalUriUseCase and FileDownloadHelper / FileDownloadHelperImpl out of ConvertInputToAppFunctionDataUseCase, chaining them in AgentOrchestrator. - Move executeInternalTool into AgentInternalTools so internal tool mapping stays encapsulated. - Extract GrantAppFunctionUriPermissionsUseCase out of ExecuteAppFunctionUseCase, removing runCatching around AppFunctionData getters, replacing .let with explicit locals, and using try/catch for grantUriPermission. - Refactor GetAppFunctionsUseCase into Flow operators (observeExternalFunctions, filterByConnection, filterByEnabledState) merging getInternalFunctions at the end. - Move nonNullArguments and extractMessageAttachment into AgentOrchestrator and update AgentOrchestratorTest to mock GetAppFunctionsUseCase directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors AppFunction tool discovery, remote file resolution, URI permission granting, and execution out of
AgentOrchestratorinto shared use cases so chat orchestration, debugging, and upcoming live voice orchestration share a unified pipeline.Key Changes
Unified AppFunction observation with filter parameters (
GetAppFunctionsUseCase&GetAppFunctionsParams):GetAppFunctionsUseCase.invoke(params: GetAppFunctionsParams)to accept nullable/optional filters (targetPackageNames,isEnabled,isConnected,includeInternalTools) composed via Flow operators (observeExternalFunctions,filterByConnection,filterByEnabledState) and merged withgetInternalFunctions.GetConnectedAppsUseCase,TroubleshootAppUseCase,AgentDemoViewModel,DebuggingViewModel) to passincludeInternalTools = false.Remote file reference download use case (
ResolveRemoteFileToLocalUriUseCase&FileDownloadHelper):FileDownloadHelper(FileDownloadHelperImplbound inDataModule) andResolveRemoteFileToLocalUriUseCaseso callers (AgentOrchestrator) can chain remotehttp:///https://file reference resolution before callingConvertInputToAppFunctionDataUseCase.Recursive URI permission granting & internal tool execution (
GrantAppFunctionUriPermissionsUseCase,AgentInternalTools, &ExecuteAppFunctionUseCase):GrantAppFunctionUriPermissionsUseCaseto recursively traverseAppFunctionDataparameters and grantFLAG_GRANT_READ_URI_PERMISSIONoncontent://URIs to the target package.AgentInternalTools.executeInternalTool(function, parameters)to encapsulate internal tool dispatch and result mapping.ExecuteAppFunctionUseCase(function, parameters, threadId)to delegate internal tools toAgentInternalTools.executeInternalTooland invokeGrantAppFunctionUriPermissionsUseCasebefore executing external AppFunctions.Simplified
AgentOrchestrator& Expanded Tests:AgentOrchestrator.GetAppFunctionsUseCaseTest(unit &androidTest),ResolveRemoteFileToLocalUriUseCaseTest,ConvertInputToAppFunctionDataUseCaseTest,GrantAppFunctionUriPermissionsUseCaseTest,ExecuteAppFunctionUseCaseTest,AgentInternalToolsTest,AgentOrchestratorTest,GetConnectedAppsUseCaseTest,AgentDemoViewModelTest, andDebuggingViewModelTest.Verification
./gradlew spotlessCheck./gradlew testStandardDebugUnitTest testRetailDebugUnitTest./gradlew compileStandardDebugAndroidTestKotlin compileStandardDebugScreenshotTestKotlin assembleStandardDebug