Skip to content

Commit 540cfdf

Browse files
reniowoodcopybara-github
authored andcommitted
fix: populate function name in FunctionResponse parts
Ensures function name is included when converting interaction steps and deltas into FunctionResponse parts. Unit tests have been updated to verify that the name field is correctly populated. PiperOrigin-RevId: 952413239
1 parent fab5347 commit 540cfdf

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/google/adk/models/interactions_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ def _convert_interaction_step_to_parts(step: Step) -> list[types.Part]:
630630
types.Part(
631631
function_response=types.FunctionResponse(
632632
id=step.call_id or '',
633+
name=step.name,
633634
response=_function_result_to_response(step.result),
634635
)
635636
)
@@ -1003,6 +1004,7 @@ def _handle_function_result(
10031004
part = types.Part(
10041005
function_response=types.FunctionResponse(
10051006
id=delta.call_id or '',
1007+
name=delta.name,
10061008
response=_function_result_to_response(delta.result),
10071009
)
10081010
)

tests/unittests/models/test_interactions_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,11 +824,13 @@ def test_function_result_output(self):
824824
output = FunctionResultStep(
825825
type='function_result',
826826
call_id='call_123',
827+
name='get_weather',
827828
result={'weather': 'Sunny'},
828829
)
829830
result_list = interactions_utils._convert_interaction_step_to_parts(output)
830831
result = result_list[0] if result_list else None
831832
assert result.function_response.id == 'call_123'
833+
assert result.function_response.name == 'get_weather'
832834
assert result.function_response.response == {'weather': 'Sunny'}
833835

834836
def test_function_result_output_preserves_none_values(self):
@@ -1468,6 +1470,7 @@ def test_function_result_delta(self):
14681470
delta={
14691471
'type': 'function_result',
14701472
'call_id': 'call_9',
1473+
'name': 'get_temperature',
14711474
'result': {'temp': 72},
14721475
},
14731476
)
@@ -1478,6 +1481,7 @@ def test_function_result_delta(self):
14781481
assert result is not None
14791482
part = result.content.parts[0]
14801483
assert part.function_response.id == 'call_9'
1484+
assert part.function_response.name == 'get_temperature'
14811485
assert part.function_response.response == {'temp': 72}
14821486
assert len(state.parts) == 1
14831487

0 commit comments

Comments
 (0)