Skip to content

Commit ec17e99

Browse files
committed
fix(a2a): read long-running function name from data, not metadata
_mark_long_running_function_call read the function name from the A2A DataPart's metadata, but for a function-call part the name lives in data (the FunctionCall dump); metadata only holds the adk_type / adk_is_long_running keys. metadata.get("name") was therefore always None, so an End-User-Credential request was mislabeled input_required instead of auth_required. Read it from data, matching the equivalent check in event_converter.py.
1 parent e6df097 commit ec17e99

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

src/google/adk/a2a/converters/long_running_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def _mark_long_running_function_call(self, a2a_part: A2APart) -> None:
160160
# If the function is a request for EUC, set the task state to
161161
# auth_required. Otherwise, set it to input_required. Save the state of
162162
# the last function call, as it will be the state of the task.
163-
if a2a_part.root.metadata.get("name") == REQUEST_EUC_FUNCTION_CALL_NAME:
163+
if a2a_part.root.data.get("name") == REQUEST_EUC_FUNCTION_CALL_NAME:
164164
self._task_state = TaskState.auth_required
165165
else:
166166
self._task_state = TaskState.input_required
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from a2a.types import TaskState
16+
from google.adk.a2a.converters.long_running_functions import LongRunningFunctions
17+
from google.adk.a2a.converters.part_converter import convert_genai_part_to_a2a_part
18+
from google.adk.flows.llm_flows.functions import REQUEST_EUC_FUNCTION_CALL_NAME
19+
from google.genai import types as genai_types
20+
21+
22+
def _long_running_call_part(function_name: str):
23+
"""Builds the A2A DataPart produced for a long-running function call."""
24+
genai_part = genai_types.Part(
25+
function_call=genai_types.FunctionCall(
26+
id="call-1", name=function_name, args={}
27+
)
28+
)
29+
return convert_genai_part_to_a2a_part(genai_part)
30+
31+
32+
class TestMarkLongRunningFunctionCall:
33+
"""Test cases for LongRunningFunctions._mark_long_running_function_call."""
34+
35+
def test_euc_request_maps_to_auth_required(self):
36+
"""An EUC (credential) request must produce the auth_required state.
37+
38+
The function name lives in the DataPart's ``data`` (the FunctionCall
39+
dump), not in ``metadata`` -- reading it from ``metadata`` always
40+
yielded ``None`` and mislabeled the task as input_required.
41+
"""
42+
lrf = LongRunningFunctions()
43+
44+
lrf._mark_long_running_function_call(
45+
_long_running_call_part(REQUEST_EUC_FUNCTION_CALL_NAME)
46+
)
47+
48+
assert lrf._task_state == TaskState.auth_required
49+
50+
def test_regular_function_maps_to_input_required(self):
51+
"""A non-EUC long-running function stays in the input_required state."""
52+
lrf = LongRunningFunctions()
53+
54+
lrf._mark_long_running_function_call(_long_running_call_part("do_thing"))
55+
56+
assert lrf._task_state == TaskState.input_required

0 commit comments

Comments
 (0)