From f3e4001f80bc2c53ae054ca010f640d231641dcf Mon Sep 17 00:00:00 2001 From: CI-DEV <154627941+IlumCI@users.noreply.github.com> Date: Fri, 3 Oct 2025 19:06:51 +0300 Subject: [PATCH 1/6] Update pyproject.toml --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 0f872451..3b73ee5d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,6 +78,7 @@ aiohttp = "*" orjson = "*" schedule = "*" uvloop = {version = "*", markers = "sys_platform != 'win32'"} +winloop = {version = "*", markers = "sys_platform == 'win32'"} [tool.poetry.scripts] swarms = "swarms.cli.main:main" From 569aa2dce46938410112b556dab80de1f3ba942a Mon Sep 17 00:00:00 2001 From: CI-DEV <154627941+IlumCI@users.noreply.github.com> Date: Fri, 3 Oct 2025 19:08:27 +0300 Subject: [PATCH 2/6] Update pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3b73ee5d..8d633ce4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,7 +77,7 @@ mcp = "*" aiohttp = "*" orjson = "*" schedule = "*" -uvloop = {version = "*", markers = "sys_platform != 'win32'"} +uvloop = {version = "*", markers = "sys_platform == 'linux' or sys_platform == 'darwin'"} winloop = {version = "*", markers = "sys_platform == 'win32'"} [tool.poetry.scripts] From 8194b0fb63dbc41cb55f28595c400c4a037d7a1a Mon Sep 17 00:00:00 2001 From: CI-DEV <154627941+IlumCI@users.noreply.github.com> Date: Fri, 3 Oct 2025 19:12:41 +0300 Subject: [PATCH 3/6] Update multi_agent_exec.py --- swarms/structs/multi_agent_exec.py | 110 +++++++++++++++++++---------- 1 file changed, 74 insertions(+), 36 deletions(-) diff --git a/swarms/structs/multi_agent_exec.py b/swarms/structs/multi_agent_exec.py index 437cd79c..3675b0f8 100644 --- a/swarms/structs/multi_agent_exec.py +++ b/swarms/structs/multi_agent_exec.py @@ -7,6 +7,7 @@ from concurrent.futures import ( from typing import Any, Callable, List, Optional, Union import uvloop +import sys from loguru import logger from swarms.structs.agent import Agent @@ -210,17 +211,16 @@ def run_agents_with_different_tasks( return results -def run_agents_concurrently_uvloop( +def run_agents_concurrently_optimized( agents: List[AgentType], task: str, max_workers: Optional[int] = None, ) -> List[Any]: """ - Run multiple agents concurrently using uvloop for optimized async performance. + Run multiple agents concurrently using optimized async performance. - uvloop is a fast, drop-in replacement for asyncio's event loop, implemented in Cython. - It's designed to be significantly faster than the standard asyncio event loop, - especially beneficial for I/O-bound tasks and concurrent operations. + Uses uvloop on Linux/macOS and winloop on Windows for enhanced performance. + Falls back to standard asyncio if optimized event loops are not available. Args: agents: List of Agent instances to run concurrently @@ -231,21 +231,40 @@ def run_agents_concurrently_uvloop( List of outputs from each agent Raises: - ImportError: If uvloop is not installed - RuntimeError: If uvloop cannot be set as the event loop policy + ImportError: If neither uvloop nor winloop is available + RuntimeError: If event loop policy cannot be set """ - try: - # Set uvloop as the default event loop policy for better performance - asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) - except ImportError: - logger.warning( - "uvloop not available, falling back to standard asyncio. " - "Install uvloop with: pip install uvloop" - ) - except RuntimeError as e: - logger.warning( - f"Could not set uvloop policy: {e}. Using default asyncio." - ) + # Platform-specific event loop policy setup + if sys.platform in ('win32', 'cygwin'): + # Windows: Try to use winloop + try: + import winloop + asyncio.set_event_loop_policy(winloop.EventLoopPolicy()) + logger.info("Using winloop for enhanced Windows performance") + except ImportError: + logger.warning( + "winloop not available, falling back to standard asyncio. " + "Install winloop with: pip install winloop" + ) + except RuntimeError as e: + logger.warning( + f"Could not set winloop policy: {e}. Using default asyncio." + ) + else: + # Linux/macOS: Try to use uvloop + try: + import uvloop + asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) + logger.info("Using uvloop for enhanced Unix performance") + except ImportError: + logger.warning( + "uvloop not available, falling back to standard asyncio. " + "Install uvloop with: pip install uvloop" + ) + except RuntimeError as e: + logger.warning( + f"Could not set uvloop policy: {e}. Using default asyncio." + ) if max_workers is None: # Use 95% of available CPU cores for optimal performance @@ -305,16 +324,16 @@ def run_agents_concurrently_uvloop( raise -def run_agents_with_tasks_uvloop( +def run_agents_with_tasks_optimized( agents: List[AgentType], tasks: List[str], max_workers: Optional[int] = None, ) -> List[Any]: """ - Run multiple agents with different tasks concurrently using uvloop. + Run multiple agents with different tasks concurrently using optimized performance. This function pairs each agent with a specific task and runs them concurrently - using uvloop for optimized performance. + using uvloop on Linux/macOS and winloop on Windows for optimized performance. Args: agents: List of Agent instances to run @@ -332,25 +351,44 @@ def run_agents_with_tasks_uvloop( f"Number of agents ({len(agents)}) must match number of tasks ({len(tasks)})" ) - try: - # Set uvloop as the default event loop policy - asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) - except ImportError: - logger.warning( - "uvloop not available, falling back to standard asyncio. " - "Install uvloop with: pip install uvloop" - ) - except RuntimeError as e: - logger.warning( - f"Could not set uvloop policy: {e}. Using default asyncio." - ) + # Platform-specific event loop policy setup + if sys.platform in ('win32', 'cygwin'): + # Windows: Try to use winloop + try: + import winloop + asyncio.set_event_loop_policy(winloop.EventLoopPolicy()) + logger.info("Using winloop for enhanced Windows performance") + except ImportError: + logger.warning( + "winloop not available, falling back to standard asyncio. " + "Install winloop with: pip install winloop" + ) + except RuntimeError as e: + logger.warning( + f"Could not set winloop policy: {e}. Using default asyncio." + ) + else: + # Linux/macOS: Try to use uvloop + try: + import uvloop + asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) + logger.info("Using uvloop for enhanced Unix performance") + except ImportError: + logger.warning( + "uvloop not available, falling back to standard asyncio. " + "Install uvloop with: pip install uvloop" + ) + except RuntimeError as e: + logger.warning( + f"Could not set uvloop policy: {e}. Using default asyncio." + ) if max_workers is None: num_cores = os.cpu_count() max_workers = int(num_cores * 0.95) if num_cores else 1 - logger.inufo( - f"Running {len(agents)} agents with {len(tasks)} tasks using uvloop (max_workers: {max_workers})" + logger.info( + f"Running {len(agents)} agents with {len(tasks)} tasks using optimized event loop (max_workers: {max_workers})" ) async def run_agents_with_tasks_async(): From 1027735fe61c3d798a754a7818497cf4005f1583 Mon Sep 17 00:00:00 2001 From: CI-DEV <154627941+IlumCI@users.noreply.github.com> Date: Fri, 3 Oct 2025 19:16:27 +0300 Subject: [PATCH 4/6] Update __init__.py --- swarms/structs/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/swarms/structs/__init__.py b/swarms/structs/__init__.py index 145a736c..9a00072f 100644 --- a/swarms/structs/__init__.py +++ b/swarms/structs/__init__.py @@ -55,9 +55,9 @@ from swarms.structs.multi_agent_exec import ( run_agents_concurrently, run_agents_concurrently_async, run_agents_concurrently_multiprocess, - run_agents_concurrently_uvloop, + run_agents_concurrently_optimized, run_agents_with_different_tasks, - run_agents_with_tasks_uvloop, + run_agents_with_tasks_optimized, run_single_agent, ) from swarms.structs.multi_agent_router import MultiAgentRouter @@ -101,6 +101,7 @@ from swarms.structs.swarming_architectures import ( staircase_swarm, star_swarm, ) +from swarms.structs.aop import AOP __all__ = [ "Agent", @@ -146,9 +147,9 @@ __all__ = [ "run_agents_concurrently", "run_agents_concurrently_async", "run_agents_concurrently_multiprocess", - "run_agents_concurrently_uvloop", + "run_agents_concurrently_optimized", "run_agents_with_different_tasks", - "run_agents_with_tasks_uvloop", + "run_agents_with_tasks_optimized", "run_single_agent", "GroupChat", "expertise_based", From 9c39126fc99aee92600da27c5a57cd6f3650d5f5 Mon Sep 17 00:00:00 2001 From: CI-DEV <154627941+IlumCI@users.noreply.github.com> Date: Fri, 3 Oct 2025 20:08:22 +0300 Subject: [PATCH 5/6] Update __init__.py --- swarms/structs/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/swarms/structs/__init__.py b/swarms/structs/__init__.py index 9a00072f..29b92dcd 100644 --- a/swarms/structs/__init__.py +++ b/swarms/structs/__init__.py @@ -55,9 +55,9 @@ from swarms.structs.multi_agent_exec import ( run_agents_concurrently, run_agents_concurrently_async, run_agents_concurrently_multiprocess, - run_agents_concurrently_optimized, + run_agents_concurrently_uvloop, run_agents_with_different_tasks, - run_agents_with_tasks_optimized, + run_agents_with_tasks_uvloop, run_single_agent, ) from swarms.structs.multi_agent_router import MultiAgentRouter @@ -147,9 +147,9 @@ __all__ = [ "run_agents_concurrently", "run_agents_concurrently_async", "run_agents_concurrently_multiprocess", - "run_agents_concurrently_optimized", + "run_agents_concurrently_uvloop", "run_agents_with_different_tasks", - "run_agents_with_tasks_optimized", + "run_agents_with_tasks_uvloop", "run_single_agent", "GroupChat", "expertise_based", From 052669954ad82d454953472f83d5c76bfc04dbd1 Mon Sep 17 00:00:00 2001 From: CI-DEV <154627941+IlumCI@users.noreply.github.com> Date: Fri, 3 Oct 2025 20:08:49 +0300 Subject: [PATCH 6/6] Update multi_agent_exec.py --- swarms/structs/multi_agent_exec.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swarms/structs/multi_agent_exec.py b/swarms/structs/multi_agent_exec.py index 3675b0f8..0b41478c 100644 --- a/swarms/structs/multi_agent_exec.py +++ b/swarms/structs/multi_agent_exec.py @@ -211,7 +211,7 @@ def run_agents_with_different_tasks( return results -def run_agents_concurrently_optimized( +def run_agents_concurrently_uvloop( agents: List[AgentType], task: str, max_workers: Optional[int] = None, @@ -324,7 +324,7 @@ def run_agents_concurrently_optimized( raise -def run_agents_with_tasks_optimized( +def run_agents_with_tasks_uvloop( agents: List[AgentType], tasks: List[str], max_workers: Optional[int] = None,