Skip to content

Commit 04b0c4b

Browse files
GWealecopybara-github
authored andcommitted
chore: adk changes
Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 932659890
1 parent 70b314b commit 04b0c4b

3 files changed

Lines changed: 0 additions & 116 deletions

File tree

src/google/adk/errors/malformed_function_call_error.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/google/adk/models/google_llm.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from google.genai.errors import ClientError
3434
from typing_extensions import override
3535

36-
from ..errors.malformed_function_call_error import MalformedFunctionCallError
3736
from ..utils._google_client_headers import get_tracking_headers
3837
from ..utils._google_client_headers import merge_tracking_headers
3938
from ..utils.context_utils import Aclosing
@@ -63,27 +62,6 @@
6362
"""
6463

6564

66-
def _raise_for_malformed_function_call(llm_response: LlmResponse) -> None:
67-
"""Raises when the model returned a malformed function call with no content.
68-
69-
A ``MALFORMED_FUNCTION_CALL`` finish reason yields a response that carries an
70-
error code but nothing the agent can act on. Left alone it builds a
71-
content-free event with no function call, which silently ends the invocation.
72-
Raising routes it through the on_model_error callbacks so they can recover,
73-
mirroring the LiteLlm malformed-arguments path. The error subclasses
74-
``ValueError`` so callbacks can match this case specifically without breaking
75-
existing handlers.
76-
"""
77-
if (
78-
llm_response.finish_reason == types.FinishReason.MALFORMED_FUNCTION_CALL
79-
and not (llm_response.content and llm_response.content.parts)
80-
):
81-
raise MalformedFunctionCallError(
82-
llm_response.error_message
83-
or 'Model returned a malformed function call.'
84-
)
85-
86-
8765
class _ResourceExhaustedError(ClientError):
8866
"""Represents a resources exhausted error received from the Model."""
8967

@@ -280,7 +258,6 @@ async def generate_content_async(
280258
aggregator.process_response(response)
281259
) as aggregator_gen:
282260
async for llm_response in aggregator_gen:
283-
_raise_for_malformed_function_call(llm_response)
284261
yield llm_response
285262
if (close_result := aggregator.close()) is not None:
286263
# Populate cache metadata in the final aggregated response for
@@ -289,7 +266,6 @@ async def generate_content_async(
289266
cache_manager.populate_cache_metadata_in_response(
290267
close_result, cache_metadata
291268
)
292-
_raise_for_malformed_function_call(close_result)
293269
yield close_result
294270

295271
else:
@@ -307,7 +283,6 @@ async def generate_content_async(
307283
cache_manager.populate_cache_metadata_in_response(
308284
llm_response, cache_metadata
309285
)
310-
_raise_for_malformed_function_call(llm_response)
311286
yield llm_response
312287
except ClientError as ce:
313288
if ce.code == 429:

tests/unittests/models/test_google_llm.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
from google.adk import version as adk_version
2323
from google.adk.agents.context_cache_config import ContextCacheConfig
24-
from google.adk.errors.malformed_function_call_error import MalformedFunctionCallError
2524
from google.adk.models.cache_metadata import CacheMetadata
2625
from google.adk.models.gemini_llm_connection import GeminiLlmConnection
2726
from google.adk.models.google_llm import _build_function_declaration_log
@@ -323,70 +322,6 @@ async def mock_coro():
323322
mock_client.aio.models.generate_content.assert_called_once()
324323

325324

326-
@pytest.mark.asyncio
327-
async def test_generate_content_async_malformed_function_call_raises(
328-
gemini_llm, llm_request
329-
):
330-
malformed_response = types.GenerateContentResponse(
331-
candidates=[
332-
types.Candidate(
333-
content=None,
334-
finish_reason=types.FinishReason.MALFORMED_FUNCTION_CALL,
335-
finish_message="Malformed function call: print(default_api.f(x=",
336-
)
337-
]
338-
)
339-
with mock.patch.object(gemini_llm, "api_client") as mock_client:
340-
341-
async def mock_coro():
342-
return malformed_response
343-
344-
mock_client.aio.models.generate_content.return_value = mock_coro()
345-
346-
with pytest.raises(
347-
MalformedFunctionCallError, match="alformed function call"
348-
):
349-
_ = [
350-
resp
351-
async for resp in gemini_llm.generate_content_async(
352-
llm_request, stream=False
353-
)
354-
]
355-
356-
357-
@pytest.mark.asyncio
358-
async def test_generate_content_async_stream_malformed_function_call_raises(
359-
gemini_llm, llm_request
360-
):
361-
mock_responses = [
362-
types.GenerateContentResponse(
363-
candidates=[
364-
types.Candidate(
365-
content=None,
366-
finish_reason=types.FinishReason.MALFORMED_FUNCTION_CALL,
367-
finish_message="Malformed function call",
368-
)
369-
]
370-
),
371-
]
372-
with mock.patch.object(gemini_llm, "api_client") as mock_client:
373-
374-
async def mock_coro():
375-
return MockAsyncIterator(mock_responses)
376-
377-
mock_client.aio.models.generate_content_stream.return_value = mock_coro()
378-
379-
with pytest.raises(
380-
MalformedFunctionCallError, match="alformed function call"
381-
):
382-
_ = [
383-
resp
384-
async for resp in gemini_llm.generate_content_async(
385-
llm_request, stream=True
386-
)
387-
]
388-
389-
390325
@pytest.mark.asyncio
391326
async def test_generate_content_async_stream(gemini_llm, llm_request):
392327
with mock.patch.object(gemini_llm, "api_client") as mock_client:

0 commit comments

Comments
 (0)