Skip to content

Dynamically fetch available LLM models from providers - #60

Open
mingweiliao wants to merge 1 commit into
android:mainfrom
mingweiliao:update-gemini-llm-model-config
Open

mingweiliao wants to merge 1 commit into
android:mainfrom
mingweiliao:update-gemini-llm-model-config

Conversation

@mingweiliao

Copy link
Copy Markdown
Contributor

Summary

Replaces the hardcoded LlmModel enum in the sample agent with dynamic model discovery from configured LLM providers, so newly released models are available automatically without requiring code changes.

Key Changes

  • Dynamic LlmModel representation:
    • Converted LlmModel from a hardcoded enum class to a @Serializable data class LlmModel(val providerName: LlmProviderName, val modelName: String).
  • Provider model discovery (LlmProvider.getAvailableModels):
    • Added suspend fun getAvailableModels(apiKey: String?): List<LlmModel> to LlmProvider.
    • Implemented GeminiProviderImpl.getAvailableModels to query GET https://generativelanguage.googleapis.com/v1beta/models?pageSize=100 and filter for gemini-* models supporting generateContent.
  • UI & ViewModel updates:
    • Updated AgentDemoViewModel to fetch available models across providers when API keys change and automatically create an initial thread once models are available.
    • Made AgentUiState.Loaded.currentThread nullable so the app loads cleanly instead of staying on the loading spinner when no API key or thread exists yet.
    • Updated ModelDropdown in AgentDemoScreen to group models by LlmProviderName and handle empty model/thread states gracefully.
  • Screenshot & unit/integration tests:
    • Fixed screenshot test reference directory paths (com/example/appfunctionsstudio -> com/example/appfunctions/agent) and added/updated previews for loading and no-thread states.
    • Added unit and integration tests for getAvailableModels and updated existing test suites.

Test

  • ./gradlew spotlessCheck test validateScreenshotTest
  • ./gradlew connectedStandardDebugAndroidTest

@mingweiliao
mingweiliao requested a review from a team as a code owner October 23, 2026 13:53
@mingweiliao
mingweiliao force-pushed the update-gemini-llm-model-config branch from ae4fe83 to bd4f213 Compare October 23, 2026 14:50

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right screenshot? I think all screenshots have an error state now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is broken from last PR. Updated the screen shot test to supply state (previously it is included in metadata, we need to change it to read it from separate API)


private var observationJob: Job? = null

init {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has no error handling, so any exception thrown by getAvailableModels kills the coroutine in viewModelScope.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is expected. getAvailableModel is not supposed to crash but if it does, it should crash the app

- Replace hardcoded LlmModel enum with a serializable data class and Room TypeConverter
- Query the Gemini models API for gemini-* models supporting generateContent
- Group models by provider in the UI dropdown and handle empty model/thread states when no API key is configured
- Fix screenshot test reference image paths and update previews for the no-thread state
@mingweiliao
mingweiliao force-pushed the update-gemini-llm-model-config branch from bd4f213 to 88454af Compare October 27, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants