You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-03-30 10:57:20 -07:00
fix: Recognize function responses as non-empty parts in LiteLLM
The `_part_has_payload` helper now returns False for parts containing a function response, preventing the addition of fallback user content when a user turn consists solely of tool outputs. Close #4249 Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 863319497
This commit is contained in:
committed by
Copybara-Service
parent
63a8eba53f
commit
d0102ecea3
@@ -497,6 +497,8 @@ def _part_has_payload(part: types.Part) -> bool:
|
||||
return True
|
||||
if part.file_data and (part.file_data.file_uri or part.file_data.data):
|
||||
return True
|
||||
if part.function_response:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ from unittest.mock import AsyncMock
|
||||
from unittest.mock import Mock
|
||||
import warnings
|
||||
|
||||
from google.adk.models.lite_llm import _append_fallback_user_content_if_missing
|
||||
from google.adk.models.lite_llm import _content_to_message_param
|
||||
from google.adk.models.lite_llm import _FILE_ID_REQUIRED_PROVIDERS
|
||||
from google.adk.models.lite_llm import _FINISH_REASON_MAPPING
|
||||
@@ -990,6 +991,28 @@ async def test_generate_content_async_adds_fallback_user_message(
|
||||
)
|
||||
|
||||
|
||||
def test_append_fallback_user_content_ignores_function_response_parts():
|
||||
llm_request = LlmRequest(
|
||||
contents=[
|
||||
types.Content(
|
||||
role="user",
|
||||
parts=[
|
||||
types.Part.from_function_response(
|
||||
name="add", response={"result": 6}
|
||||
)
|
||||
],
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
_append_fallback_user_content_if_missing(llm_request)
|
||||
|
||||
assert len(llm_request.contents) == 1
|
||||
assert len(llm_request.contents[0].parts) == 1
|
||||
assert llm_request.contents[0].parts[0].function_response is not None
|
||||
assert llm_request.contents[0].parts[0].text is None
|
||||
|
||||
|
||||
litellm_append_user_content_test_cases = [
|
||||
pytest.param(
|
||||
LlmRequest(
|
||||
|
||||
Reference in New Issue
Block a user