Conditional Grounding Pattern
Inject Google Search grounding only when the model and modality support it.
Capability Set
Supported models:
gemini-3-flash-previewgemini-3-pro-previewgemini-3-pro-image-preview
Not supported in this pipeline:
- audio modality requests
- TTS models (
gemini-2.5-*-tts)
Helper Function
const config = withGoogleSearchGrounding(modelId, existingConfig);
Behavior:
- Returns original config if unsupported.
- Appends
{ googleSearch: {} }totoolsif supported. - Avoids duplicate
googleSearchtool entries.
Why Centralize
- Prevents per-call drift.
- Keeps capabilities explicit.
- Makes grounding behavior testable.