diff --git a/lib/crewai/src/crewai/a2a/utils/delegation.py b/lib/crewai/src/crewai/a2a/utils/delegation.py index 856e7ff65..da869c6d0 100644 --- a/lib/crewai/src/crewai/a2a/utils/delegation.py +++ b/lib/crewai/src/crewai/a2a/utils/delegation.py @@ -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", diff --git a/lib/crewai/tests/a2a/utils/test_delegation.py b/lib/crewai/tests/a2a/utils/test_delegation.py index b09c483d1..6079707bb 100644 --- a/lib/crewai/tests/a2a/utils/test_delegation.py +++ b/lib/crewai/tests/a2a/utils/test_delegation.py @@ -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."""