Skip to content

Hide specialized Gemini models in the model picker and fix the default - #103

Merged
tony-mak merged 2 commits into
android:mainfrom
borisr-code-ibm:bugfix/model-picker-specialized-models
Nov 25, 2026
Merged

tony-mak merged 2 commits into
android:mainfrom
borisr-code-ibm:bugfix/model-picker-specialized-models

Conversation

@borisr-code-ibm

@borisr-code-ibm borisr-code-ibm commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What I have done and why

Problem

Since #60, the Testing Agent's model picker lists every gemini-* model whose
supportedGenerationMethods include generateContent, in API order. With my key that is 37 models
today, and 18 of them aren't meant for chat with function calling:

  • TTS: gemini-2.5-flash-preview-tts, gemini-3.8-flash-tts, …
  • image generation: gemini-3-pro-image, gemini-nano-banana-2.1, …
  • gemini-omni-*
  • gemini-3.5-transcribe
  • gemini-robotics-er-2-preview
  • gemini-2.5-computer-use-preview-10-2025

The app has had no default model since #60 (before that it was gemini-3.1-flash-lite). The first
thread and "+" without a current thread take the first model of the list, which today is
gemini-2.5-flash-preview-tts.

"+" also copies the current thread's model, so once a thread is on that model, every new thread is
too. Every agent request on it failed with
Gemini API error: 500 - {"error":{"message":"An internal error has occurred. …","code":"api_error"}}
(2/2 runs).

Solution

  1. GeminiProviderImpl.getAvailableModels also hides a model when one of these specialized families
    appears as whole --separated parts of its name: tts, image, nano-banana, transcribe,
    omni, robotics, computer-use, live, audio.
    • models.list has no field for function-calling support, so the name is the only signal.
    • It is a list of families to hide rather than an allow-list of pro/flash/flash-lite, so new
      general models keep appearing without code changes, which was Dynamically fetch available LLM models from providers #60's goal. Today's list includes
      gemini-4-argon/-carbon/-hydrogen/-neon, gemini-4-cobalt-eap and
      gemini-3.1-pro-preview-customtools, which a tier allow-list would hide.
  2. New threads default to gemini-flash-latest while the models list includes it, otherwise to the
    first available model. The picker keeps API order.
    • The default is resolved explicitly, not by list position: LlmProvider.defaultModelName names
      it (gemini-flash-latest for Gemini), and LlmProvider.resolveDefaultModel picks it from the
      available models, with that fallback.
    • AgentDemoViewModel resolves it when the models load and uses it for the first thread.
      AgentUiState.Loaded.defaultModel passes it to the "+" button.
  3. "+" keeps the current thread's model only while the picker lists it; otherwise it uses the default.
main this PR
Models in the picker 37, first gemini-2.5-flash-preview-tts 19, in API order
First thread, and "+" without a thread first listed model (gemini-2.5-flash-preview-tts) gemini-flash-latest
"+" on a thread whose model isn't listed copies it gemini-flash-latest
"+" on a thread whose model is listed copies it copies it

Existing threads keep the model they were created with. A thread on a now-hidden model still shows
it in the header, and the picker switches it to a listed model.

LLM payload

  • Only model changes, and only for new threads: "model":"gemini-2.5-flash-preview-tts" becomes
    "model":"gemini-flash-latest".
  • system_instruction, service_tier and tools are the same. I compared the logged request bodies
    of both runs, which were taken before the review change, with gemini-3.1-flash-lite as the
    default.
  • Tool-result turns are unchanged too, except that gemini-flash-latest gets images in function
    results as image parts (Send granted image results to the model #90), where Gemini 1 and 2 models get a text note.

Evidence

Setup: Pixel_9 emulator (API 37), ChatApp from this repo, progressive tool disclosure on.

main: picker main: "+" copies the TTS model main: request fails
main: the picker starts with gemini-2.5-flash-preview-tts and gemini-2.5-pro-preview-tts main: the new thread is on gemini-2.5-flash-preview-tts main: Gemini API error 500, an internal error has occurred

The "this PR" screenshots are from 61ac3e9, before the review change. The picker then listed
gemini-3.1-flash-lite first, and "+" from the TTS thread gave gemini-3.1-flash-lite. Now the
picker keeps API order (gemini-4-cobalt-eap first), and "+" from the TTS thread gives
gemini-flash-latest.

this PR: picker this PR: "+" from the TTS thread this PR: ChatApp task on a listed model
this PR: the picker starts with gemini-3.1-flash-lite this PR: the new thread is on gemini-3.1-flash-lite this PR: gemini-flash-lite-latest fetched the message details for Alice Smith

The ChatApp task ("Using ChatApp, get the details for sending Alice Smith the message: See you at 6.
Do not send it yet.") ran end to end on gemini-flash-lite-latest, which currently serves
gemini-3.5-flash-lite: expand_tool_description, then expand_function_declarations, then
searchContacts, then fetchSendMessageDetails, then the answer.

On gemini-3.1-flash-lite, the default before the review change, the same request got
503 … "gemini-3.1-flash-lite is currently experiencing high demand" every time I tried between
15:16 and 17:02 UTC on 2026-11-23, on both service tiers.

Testing

  • GeminiProviderImplTest (5 new tests):
    • the 37-model list of 2026-11-23 gives the 19 general models in API order, and
      gemini-flash-latest as the default;
    • without gemini-flash-latest, the default is the first available model, even when a hidden
      TTS model is listed first;
    • new general names are kept and new specialized names are hidden;
    • a family name inside a longer part (olive, imagery) doesn't hide a model.
  • LlmProviderTest (new): resolveDefaultModel when the default is listed, isn't listed, isn't
    named, and when there are no models.
  • AgentUiStateTest (new): newThreadModel for a listed, unlisted and Live current model, with and
    without loaded models, and without a thread. The default isn't the first available model.
  • AgentDemoViewModelTest: the first thread and Loaded.newThreadModel use the provider's default,
    which isn't the first model.
  • ./gradlew spotlessCheck test validateScreenshotTest -PGEMINI_API_KEY=dummy_key:
    • 297 unit tests in each of standardDebug and retailDebug, 0 failures;
    • 28 screenshot tests per variant pass, with unchanged references;
    • spotless is clean.

Targets tested

  • Agent, standard debug, on an API 37 emulator (Pixel_9) with ChatApp from this repo, at 61ac3e9
    (before the review change). The unit tests above cover the review change.

Notes

  • A brand-new specialized family with an unfamiliar name would show up until its name part is added.
    It could only become the default if the models list lacked gemini-flash-latest and listed the
    new family first.
  • The specialized TTS model answers the agent's request with a generic 500, and hiding it is the
    app-side fix.

The picker listed every gemini-* model that supports generateContent, in
API order: 37 models today, 18 of them TTS, image generation, Omni,
transcription, robotics or computer-use models that aren't meant for chat
with function calling. The first thread and "+" without a current thread
take the first model of the list, so new threads defaulted to
gemini-2.5-flash-preview-tts, which fails the agent's requests.

- GeminiProviderImpl hides a model when a specialized family appears as
  whole parts of its name (tts, image, nano-banana, transcribe, omni,
  robotics, computer-use, live, audio), so new general models still
  appear without code changes.
- It lists the default first: gemini-3.1-flash-lite (the default before
  models were fetched from the API), else gemini-flash-lite-latest, else
  gemini-flash-latest.
- "+" keeps the current thread's model only while the picker lists it, so
  a thread on a model that is no longer offered doesn't pass it on. As
  before, a Live thread's model is never copied.
@google-cla

google-cla Bot commented Nov 23, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@borisr-code-ibm
borisr-code-ibm marked this pull request as ready for review November 23, 2026 17:36
@borisr-code-ibm
borisr-code-ibm requested review from a team as code owners November 23, 2026 17:36
@borisr-code-ibm

Copy link
Copy Markdown
Contributor Author

@tony-mak The Agent check failed on a flaky unit test that this PR doesn't touch. Could you re-run the failed job? I don't have permission to re-run it.

  • Failing test: AndroidLiveAudioSessionTest > stopAudio flushes active AudioTrack and discards queued chunks (AssertionError at AndroidLiveAudioSessionTest.kt:259), in testRetailDebugUnitTest only. The same test passed in testStandardDebugUnitTest in the same run: https://github.com/android/appfunctions/actions/runs/45223637148
  • Why it's flaky: the test's latch is released in flush(), but the test then verifies the second play(), which flushActiveTrack() calls right after flush() on the playback thread.

@tony-mak

Copy link
Copy Markdown
Contributor

Please default to gemini-flash-latest explicitly instead of reordering getAvailableModels around gemini-3.1-flash-lite.

  • gemini-3.1-flash-lite is a pinned version that can go stale or hit capacity limits. Check for gemini-flash-latest in the available models list, and fall back to the first available model if it is absent.
  • LlmProvider.getAvailableModels should return available models without encoding the default in list index 0. Resolve the default explicitly (such as via a dedicated property or helper) rather than mutating list order, so picker ordering stays separate from default selection and future providers do not depend on an implicit positional contract.

@tony-mak tony-mak left a comment

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.

LGTM once the default model comment above is addressed. Feel free to fix and merge.

getAvailableModels no longer moves a default to the front, so the picker
shows the models in API order. LlmProvider.defaultModelName names the
provider's default (gemini-flash-latest for Gemini), and
resolveDefaultModel picks it from the available models, or the first
available model when the list doesn't include it.

AgentDemoViewModel resolves the default when it loads the models and
uses it for the first thread. AgentUiState.Loaded.defaultModel passes it
to "+", which uses it when the current thread's model isn't offered.
@borisr-code-ibm

Copy link
Copy Markdown
Contributor Author

@tony-mak Thanks, done in 0bd2472:

  • New threads default to gemini-flash-latest when the models list includes it, and to the first available model otherwise.
  • getAvailableModels no longer reorders the list, so the picker shows API order. The default is resolved explicitly: LlmProvider.defaultModelName names it (gemini-flash-latest for Gemini), and resolveDefaultModel(availableModels) applies the fallback. AgentDemoViewModel resolves it when the models load, uses it for the first thread, and passes it to "+" as AgentUiState.Loaded.defaultModel.
  • Tests: the new LlmProviderTest covers the fallback, and GeminiProviderImplTest checks API order and the gemini-flash-latest default for the 2026-11-23 models list. In AgentDemoViewModelTest and AgentUiStateTest, the default isn't the first model. Locally, spotless, the unit tests (297 per variant) and the screenshot tests pass.

I've updated the description to match. The new commit's workflows are waiting for approval, and I can't merge myself, so this needs a maintainer for both.

@tony-mak
tony-mak merged commit 8340c0c into android:main Nov 25, 2026
12 of 13 checks passed
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