Skip to content

Commit cdb4799

Browse files
authored
fix(compat): keep an unset v0.3 status message and provider as None (a2aproject#1362)
## Problem `FromProto` turned an unset v0.3 `status.update` and `card.provider` into empty objects instead of `None`. ## Fix Check `HasField` first, as a2aproject#1334 does for `configuration`. ## Tests `test_task_status_without_message` and `test_agent_card_without_provider` fail on main. Six REST transport tests expected the empty message and now expect none. 2289 passed. Fixes a2aproject#1361
1 parent d316d0e commit cdb4799

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

‎src/a2a/compat/v0_3/proto_utils.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,9 @@ def task(cls, task: a2a_pb2.Task) -> types.Task:
696696
def task_status(cls, status: a2a_pb2.TaskStatus) -> types.TaskStatus:
697697
return types.TaskStatus(
698698
state=cls.task_state(status.state),
699-
message=cls.message(status.update),
699+
message=cls.message(status.update)
700+
if status.HasField('update')
701+
else None,
700702
timestamp=status.timestamp.ToJsonString()
701703
if status.HasField('timestamp')
702704
else None,
@@ -874,7 +876,9 @@ def agent_card(
874876
description=card.description,
875877
documentation_url=card.documentation_url,
876878
name=card.name,
877-
provider=cls.provider(card.provider),
879+
provider=cls.provider(card.provider)
880+
if card.HasField('provider')
881+
else None,
878882
security=cls.security(list(card.security)),
879883
security_schemes=cls.security_schemes(dict(card.security_schemes)),
880884
skills=[cls.skill(x) for x in card.skills] if card.skills else [],

‎tests/compat/v0_3/test_proto_utils.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,18 @@ def test_message_send_params_without_configuration(self):
282282
)
283283
assert params.configuration is None
284284

285+
def test_task_status_without_message(self):
286+
"""An unset status message stays None instead of an empty message."""
287+
status = proto_utils.FromProto.task_status(
288+
a2a_pb2.TaskStatus(state=a2a_pb2.TASK_STATE_WORKING)
289+
)
290+
assert status.message is None
291+
292+
def test_agent_card_without_provider(self):
293+
"""An unset provider stays None instead of an empty provider."""
294+
card = proto_utils.FromProto.agent_card(a2a_pb2.AgentCard(name='a'))
295+
assert card.provider is None
296+
285297
def test_none_handling(self):
286298
"""Test that None inputs are handled gracefully."""
287299
assert proto_utils.ToProto.message(None) is None

‎tests/compat/v0_3/test_rest_transport.py‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
SubscribeToTaskRequest,
2626
Task,
2727
TaskPushNotificationConfig,
28+
TaskStatus,
2829
)
2930
from a2a.utils.errors import InvalidParamsError, MethodNotFoundError
3031

@@ -95,8 +96,6 @@ async def mock_send_request(*args, **kwargs):
9596
expected_response = SendMessageResponse(
9697
task=Task(id='task-123', status=Task(id='task-123').status)
9798
)
98-
# The default conversion from 0.3 task generates a TaskStatus with a default empty message with role=ROLE_AGENT
99-
expected_response.task.status.message.role = Role.ROLE_AGENT
10099
assert response == expected_response
101100

102101

@@ -110,8 +109,7 @@ async def mock_send_request(*args, **kwargs):
110109
req = GetTaskRequest(id='task-123')
111110
response = await transport.get_task(req)
112111

113-
expected_response = Task(id='task-123')
114-
expected_response.status.message.role = Role.ROLE_AGENT
112+
expected_response = Task(id='task-123', status=TaskStatus())
115113
assert response == expected_response
116114

117115

@@ -125,8 +123,7 @@ async def mock_send_request(*args, **kwargs):
125123
req = CancelTaskRequest(id='task-123')
126124
response = await transport.cancel_task(req)
127125

128-
expected_response = Task(id='task-123')
129-
expected_response.status.message.role = Role.ROLE_AGENT
126+
expected_response = Task(id='task-123', status=TaskStatus())
130127
assert response == expected_response
131128

132129

@@ -554,8 +551,7 @@ async def mock_execute_request(method, path, context=None, params=None):
554551

555552
req = GetTaskRequest(id='task-123')
556553
response = await transport.get_task(req)
557-
expected_response = Task(id='task-123')
558-
expected_response.status.message.role = Role.ROLE_AGENT
554+
expected_response = Task(id='task-123', status=TaskStatus())
559555
assert response == expected_response
560556

561557

@@ -569,8 +565,7 @@ async def mock_execute_request(method, path, context=None, params=None):
569565

570566
req = GetTaskRequest(id='task-123', history_length=10)
571567
response = await transport.get_task(req)
572-
expected_response = Task(id='task-123')
573-
expected_response.status.message.role = Role.ROLE_AGENT
568+
expected_response = Task(id='task-123', status=TaskStatus())
574569
assert response == expected_response
575570

576571

@@ -653,8 +648,7 @@ async def mock_generator(*args, **kwargs):
653648
]
654649

655650
assert len(events) == 1
656-
expected_task = Task(id='task-123')
657-
expected_task.status.message.role = Role.ROLE_AGENT
651+
expected_task = Task(id='task-123', status=TaskStatus())
658652
assert events[0] == StreamResponse(task=expected_task)
659653

660654
mock_send_http_stream_request.assert_called_once_with(

0 commit comments

Comments
 (0)