fix: only fall back to polling when streaming is explicitly False

Addresses review: agents that leave streaming unset (None) should get the
default StreamingHandler, not polling. Only agents that explicitly set
streaming=False trigger the polling fallback.
This commit is contained in:
Alex
2026-04-12 16:38:44 -07:00
parent 7169d03b80
commit b626dd5ec9
2 changed files with 22 additions and 2 deletions

View File

@@ -589,8 +589,9 @@ async def _aexecute_a2a_delegation_impl(
# If the user hasn't explicitly configured an updates strategy and the remote
# agent advertises that it does not support streaming, fall back to polling.
if updates is None and not (
agent_card.capabilities and agent_card.capabilities.streaming
if updates is None and (
agent_card.capabilities is not None
and agent_card.capabilities.streaming is False
):
logger.debug(
"Remote agent does not support streaming; falling back to PollingHandler",

View File

@@ -155,6 +155,25 @@ class TestStreamingFallback:
mock_streaming.assert_called_once()
mock_polling.assert_not_called()
@pytest.mark.asyncio
async def test_uses_streaming_when_agent_card_streaming_is_none(self) -> None:
"""When streaming is unset (None) and updates is None, StreamingHandler should be used."""
agent_card = _make_agent_card(streaming=None)
with ExitStack() as stack:
for p in _make_shared_patches(agent_card):
stack.enter_context(p)
mock_polling = stack.enter_context(
patch.object(PollingHandler, "execute", new=AsyncMock(return_value=_TASK_RESULT))
)
mock_streaming = stack.enter_context(
patch.object(StreamingHandler, "execute", new=AsyncMock(return_value=_TASK_RESULT))
)
await _call_impl(agent_card, updates=None)
mock_streaming.assert_called_once()
mock_polling.assert_not_called()
@pytest.mark.asyncio
async def test_explicit_streaming_config_overrides_agent_card(self) -> None:
"""Explicitly passing StreamingConfig keeps StreamingHandler even when agent card says no streaming."""