Skip to content

Today, langfun's Gemini base class hardcodes toolConfig.functionCallingConfig.mode='NONE',#711

Open
copybara-service[bot] wants to merge 1 commit intomainfrom
test_913068454
Open

Today, langfun's Gemini base class hardcodes toolConfig.functionCallingConfig.mode='NONE',#711
copybara-service[bot] wants to merge 1 commit intomainfrom
test_913068454

Conversation

@copybara-service
Copy link
Copy Markdown

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:

  • 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.

…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
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.

1 participant