Today, langfun's Gemini base class hardcodes toolConfig.functionCallingConfig.mode='NONE',#711
Open
copybara-service[bot] wants to merge 1 commit intomainfrom
Open
Today, langfun's Gemini base class hardcodes toolConfig.functionCallingConfig.mode='NONE',#711copybara-service[bot] wants to merge 1 commit intomainfrom
copybara-service[bot] wants to merge 1 commit intomainfrom
Conversation
…ngConfig.mode='NONE',
unconditionally disabling function calling for ALL Gemini subclasses including
gemini-3.1-pro-preview (both Vertex AI and Google GenAI backends). Callers who want
function calling must pass BOTH extras['tools'] AND extras['toolConfig'] — easy to
forget, and inconsistent with langfun's other 'just-works' Gemini features
(e.g. implicit prompt caching).
This CL: in Gemini.request(), if sampling_options.extras['tools'] is non-empty,
default mode to 'AUTO' instead of 'NONE'. Callers can still override by passing
extras['toolConfig'] explicitly (the existing extras-merge runs after this default).
When no tools are passed, today's wire payload is preserved bit-for-bit (mode='NONE').
Design notes:
- No new API surface (no new LMSamplingOptions field, no new kwarg, no new method).
Reuses the existing `extras: dict[str, Any]` escape hatch.
- Implicit / default-on, mirroring the implicit prompt caching precedent.
- Backward compatible: text-only callers (no tools in extras) see identical wire
payload to today.
Tests:
- gemini_test.py: 8 new/updated unit tests covering legacy preservation, AUTO
flip on tools, empty-list adversarial, caller override via extras['toolConfig'],
zero-parameter tool, deeply nested schema, oversized (128) tool list,
prompt-injection-style request integrity.
- vertexai_test.py: VertexAIGemini31ProPreview subclass smoke test.
- google_genai_test.py: Gemini31ProPreview subclass smoke test.
RED→GREEN evidence:
RED pre-change failure summary:
- gemini_test.py: FAILED (failures=5)
- google_genai_test.py: FAILED (failures=1)
- vertexai_test.py: FAILED (failures=1)
All failed with: AssertionError: {'functionCallingConfig': {'mode': 'NONE'}} != {'functionCallingConfig': {'mode': 'AUTO'}}
GREEN post-change pass summary:
- gemini_test.py: PASSED
- google_genai_test.py: PASSED
- vertexai_test.py: PASSED
Live integration testing (deferred to follow-up CL): no live-test infrastructure
currently exists under //third_party/py/langfun/core/llms/ (no *_live_test.py,
no GCP project ID convention, no BUILD gating tags). Establishing that pattern
requires owner input on the project ID and OSS-mirror posture for
langfun.core.google.auth.gcp_corp_access (LINT.IfChange/copy.bara.sky).
Tracked separately.
PiperOrigin-RevId: 913068454
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.
Today, langfun's Gemini base class hardcodes toolConfig.functionCallingConfig.mode='NONE',
unconditionally disabling function calling for ALL Gemini subclasses including
gemini-3.1-pro-preview (both Vertex AI and Google GenAI backends). Callers who want
function calling must pass BOTH extras['tools'] AND extras['toolConfig'] — easy to
forget, and inconsistent with langfun's other 'just-works' Gemini features
(e.g. implicit prompt caching).
This CL: in Gemini.request(), if sampling_options.extras['tools'] is non-empty,
default mode to 'AUTO' instead of 'NONE'. Callers can still override by passing
extras['toolConfig'] explicitly (the existing extras-merge runs after this default).
When no tools are passed, today's wire payload is preserved bit-for-bit (mode='NONE').
Design notes:
Reuses the existing
extras: dict[str, Any]escape hatch.payload to today.
Tests:
flip on tools, empty-list adversarial, caller override via extras['toolConfig'],
zero-parameter tool, deeply nested schema, oversized (128) tool list,
prompt-injection-style request integrity.
RED→GREEN evidence:
RED pre-change failure summary:
All failed with: AssertionError: {'functionCallingConfig': {'mode': 'NONE'}} != {'functionCallingConfig': {'mode': 'AUTO'}}
GREEN post-change pass summary:
Live integration testing (deferred to follow-up CL): no live-test infrastructure
currently exists under //third_party/py/langfun/core/llms/ (no *_live_test.py,
no GCP project ID convention, no BUILD gating tags). Establishing that pattern
requires owner input on the project ID and OSS-mirror posture for
langfun.core.google.auth.gcp_corp_access (LINT.IfChange/copy.bara.sky).
Tracked separately.