From 955bca67cee1a74c91fb5963533beeba8125018d Mon Sep 17 00:00:00 2001 From: Amy Wu Date: Mon, 11 May 2026 10:51:05 -0700 Subject: [PATCH] feat: support Blocking FunctionCall in Live API in AgentPlatform (Vertex) PiperOrigin-RevId: 913778808 --- google/genai/_live_converters.py | 45 +-------------------------- google/genai/caches.py | 45 +-------------------------- google/genai/models.py | 46 +--------------------------- google/genai/tests/live/test_live.py | 9 ++---- google/genai/types.py | 11 ++++--- 5 files changed, 12 insertions(+), 144 deletions(-) diff --git a/google/genai/_live_converters.py b/google/genai/_live_converters.py index 3fd9d6a17..ff367ee5c 100644 --- a/google/genai/_live_converters.py +++ b/google/genai/_live_converters.py @@ -167,46 +167,6 @@ def _FunctionCall_to_mldev( return to_object -def _FunctionDeclaration_to_vertex( - from_object: Union[dict[str, Any], object], - parent_object: Optional[dict[str, Any]] = None, -) -> dict[str, Any]: - to_object: dict[str, Any] = {} - if getv(from_object, ['description']) is not None: - setv(to_object, ['description'], getv(from_object, ['description'])) - - if getv(from_object, ['name']) is not None: - setv(to_object, ['name'], getv(from_object, ['name'])) - - if getv(from_object, ['parameters']) is not None: - setv(to_object, ['parameters'], getv(from_object, ['parameters'])) - - if getv(from_object, ['parameters_json_schema']) is not None: - setv( - to_object, - ['parametersJsonSchema'], - getv(from_object, ['parameters_json_schema']), - ) - - if getv(from_object, ['response']) is not None: - setv(to_object, ['response'], getv(from_object, ['response'])) - - if getv(from_object, ['response_json_schema']) is not None: - setv( - to_object, - ['responseJsonSchema'], - getv(from_object, ['response_json_schema']), - ) - - if getv(from_object, ['behavior']) is not None: - raise ValueError( - 'behavior parameter is not supported in Gemini Enterprise Agent' - ' Platform.' - ) - - return to_object - - def _GenerationConfig_to_vertex( from_object: Union[dict[str, Any], object], parent_object: Optional[dict[str, Any]] = None, @@ -1854,10 +1814,7 @@ def _Tool_to_vertex( setv( to_object, ['functionDeclarations'], - [ - _FunctionDeclaration_to_vertex(item, to_object) - for item in getv(from_object, ['function_declarations']) - ], + [item for item in getv(from_object, ['function_declarations'])], ) if getv(from_object, ['google_search_retrieval']) is not None: diff --git a/google/genai/caches.py b/google/genai/caches.py index be85c95ea..6655617e1 100644 --- a/google/genai/caches.py +++ b/google/genai/caches.py @@ -407,46 +407,6 @@ def _FunctionCallingConfig_to_mldev( return to_object -def _FunctionDeclaration_to_vertex( - from_object: Union[dict[str, Any], object], - parent_object: Optional[dict[str, Any]] = None, -) -> dict[str, Any]: - to_object: dict[str, Any] = {} - if getv(from_object, ['description']) is not None: - setv(to_object, ['description'], getv(from_object, ['description'])) - - if getv(from_object, ['name']) is not None: - setv(to_object, ['name'], getv(from_object, ['name'])) - - if getv(from_object, ['parameters']) is not None: - setv(to_object, ['parameters'], getv(from_object, ['parameters'])) - - if getv(from_object, ['parameters_json_schema']) is not None: - setv( - to_object, - ['parametersJsonSchema'], - getv(from_object, ['parameters_json_schema']), - ) - - if getv(from_object, ['response']) is not None: - setv(to_object, ['response'], getv(from_object, ['response'])) - - if getv(from_object, ['response_json_schema']) is not None: - setv( - to_object, - ['responseJsonSchema'], - getv(from_object, ['response_json_schema']), - ) - - if getv(from_object, ['behavior']) is not None: - raise ValueError( - 'behavior parameter is not supported in Gemini Enterprise Agent' - ' Platform.' - ) - - return to_object - - def _GetCachedContentParameters_to_mldev( api_client: BaseApiClient, from_object: Union[dict[str, Any], object], @@ -944,10 +904,7 @@ def _Tool_to_vertex( setv( to_object, ['functionDeclarations'], - [ - _FunctionDeclaration_to_vertex(item, to_object) - for item in getv(from_object, ['function_declarations']) - ], + [item for item in getv(from_object, ['function_declarations'])], ) if getv(from_object, ['google_search_retrieval']) is not None: diff --git a/google/genai/models.py b/google/genai/models.py index 339248d0c..2439e7b77 100644 --- a/google/genai/models.py +++ b/google/genai/models.py @@ -1135,47 +1135,6 @@ def _FunctionCallingConfig_to_mldev( return to_object -def _FunctionDeclaration_to_vertex( - from_object: Union[dict[str, Any], object], - parent_object: Optional[dict[str, Any]] = None, - root_object: Optional[Union[dict[str, Any], object]] = None, -) -> dict[str, Any]: - to_object: dict[str, Any] = {} - if getv(from_object, ['description']) is not None: - setv(to_object, ['description'], getv(from_object, ['description'])) - - if getv(from_object, ['name']) is not None: - setv(to_object, ['name'], getv(from_object, ['name'])) - - if getv(from_object, ['parameters']) is not None: - setv(to_object, ['parameters'], getv(from_object, ['parameters'])) - - if getv(from_object, ['parameters_json_schema']) is not None: - setv( - to_object, - ['parametersJsonSchema'], - getv(from_object, ['parameters_json_schema']), - ) - - if getv(from_object, ['response']) is not None: - setv(to_object, ['response'], getv(from_object, ['response'])) - - if getv(from_object, ['response_json_schema']) is not None: - setv( - to_object, - ['responseJsonSchema'], - getv(from_object, ['response_json_schema']), - ) - - if getv(from_object, ['behavior']) is not None: - raise ValueError( - 'behavior parameter is not supported in Gemini Enterprise Agent' - ' Platform.' - ) - - return to_object - - def _GenerateContentConfig_to_mldev( api_client: BaseApiClient, from_object: Union[dict[str, Any], object], @@ -4252,10 +4211,7 @@ def _Tool_to_vertex( setv( to_object, ['functionDeclarations'], - [ - _FunctionDeclaration_to_vertex(item, to_object, root_object) - for item in getv(from_object, ['function_declarations']) - ], + [item for item in getv(from_object, ['function_declarations'])], ) if getv(from_object, ['google_search_retrieval']) is not None: diff --git a/google/genai/tests/live/test_live.py b/google/genai/tests/live/test_live.py index 513a90a3f..726caff3b 100644 --- a/google/genai/tests/live/test_live.py +++ b/google/genai/tests/live/test_live.py @@ -1193,12 +1193,9 @@ async def test_bidi_setup_to_api_with_tools_function_behavior(vertexai): } config = types.LiveConnectConfig(**config_dict) - with pytest_helper.exception_if_vertex(api_client, ValueError): - result = await get_connect_message( - mock_api_client(vertexai=vertexai), model='test_model', config=config - ) - if vertexai: - return + result = await get_connect_message( + mock_api_client(vertexai=vertexai), model='test_model', config=config + ) assert ( result['setup']['tools'][0]['functionDeclarations'][0]['behavior'] diff --git a/google/genai/types.py b/google/genai/types.py index fb567516f..e28a5a4a6 100644 --- a/google/genai/types.py +++ b/google/genai/types.py @@ -277,12 +277,13 @@ class PhishBlockThreshold(_common.CaseInSensitiveEnum): class Behavior(_common.CaseInSensitiveEnum): """Specifies the function Behavior. - Currently only supported by the BidiGenerateContent method. This enum is not - supported in Vertex AI. + Currently only non-blocking functions are supported. If not specified, the + system keeps the current function call behavior. This field is currently only + supported by the BidiGenerateContent method. """ UNSPECIFIED = 'UNSPECIFIED' - """This value is unused.""" + """This value is unspecified.""" BLOCKING = 'BLOCKING' """If set, the system will wait to receive the function response before continuing the conversation.""" NON_BLOCKING = 'NON_BLOCKING' @@ -4392,7 +4393,7 @@ class FunctionDeclaration(_common.BaseModel): ) behavior: Optional[Behavior] = Field( default=None, - description="""Optional. Specifies the function Behavior. Currently only supported by the BidiGenerateContent method. This field is not supported in Vertex AI.""", + description="""Optional. Specifies the function Behavior. Currently only non-blocking functions are supported. If not specified, the system keeps the current function call behavior. This field is currently only supported by the BidiGenerateContent method.""", ) @classmethod @@ -4615,7 +4616,7 @@ class FunctionDeclarationDict(TypedDict, total=False): """Optional. Describes the output from this function in JSON Schema format. The value specified by the schema is the response value of the function. This field is mutually exclusive with `response`.""" behavior: Optional[Behavior] - """Optional. Specifies the function Behavior. Currently only supported by the BidiGenerateContent method. This field is not supported in Vertex AI.""" + """Optional. Specifies the function Behavior. Currently only non-blocking functions are supported. If not specified, the system keeps the current function call behavior. This field is currently only supported by the BidiGenerateContent method.""" FunctionDeclarationOrDict = Union[FunctionDeclaration, FunctionDeclarationDict]