diff --git a/docs/sphinx_doc/en/source/tutorial/208-distribute.md b/docs/sphinx_doc/en/source/tutorial/208-distribute.md index 714f2e05f..5574276c4 100644 --- a/docs/sphinx_doc/en/source/tutorial/208-distribute.md +++ b/docs/sphinx_doc/en/source/tutorial/208-distribute.md @@ -69,7 +69,7 @@ agentscope.init( ... ) # Create an agent service process -server = RpcAgentServerLauncher( +server = AgentServerLauncher( host="ip_a", port=12001, # choose an available port ) @@ -88,7 +88,7 @@ agentscope.init( ... ) # Create an agent service process -server = RpcAgentServerLauncher( +server = AgentServerLauncher( host="ip_b", port=12002, # choose an available port ) diff --git a/docs/sphinx_doc/zh_CN/source/tutorial/208-distribute.md b/docs/sphinx_doc/zh_CN/source/tutorial/208-distribute.md index ef50f123f..3506e6641 100644 --- a/docs/sphinx_doc/zh_CN/source/tutorial/208-distribute.md +++ b/docs/sphinx_doc/zh_CN/source/tutorial/208-distribute.md @@ -68,7 +68,7 @@ agentscope.init( ... ) # Create an agent service process -server = RpcAgentServerLauncher( +server = AgentServerLauncher( host="ip_a", port=12001, # choose an available port ) @@ -87,7 +87,7 @@ agentscope.init( ... ) # Create an agent service process -server = RpcAgentServerLauncher( +server = AgentServerLauncher( host="ip_b", port=12002, # choose an available port ) diff --git a/examples/distributed_basic/distributed_dialog.py b/examples/distributed_basic/distributed_dialog.py index ab0de4235..c101fd2f6 100644 --- a/examples/distributed_basic/distributed_dialog.py +++ b/examples/distributed_basic/distributed_dialog.py @@ -7,7 +7,7 @@ import agentscope from agentscope.agents.user_agent import UserAgent from agentscope.agents.dialog_agent import DialogAgent -from agentscope.server import RpcAgentServerLauncher +from agentscope.server import AgentServerLauncher def parse_args() -> argparse.Namespace: @@ -36,7 +36,7 @@ def setup_assistant_server(assistant_host: str, assistant_port: int) -> None: agentscope.init( model_configs="configs/model_configs.json", ) - assistant_server_launcher = RpcAgentServerLauncher( + assistant_server_launcher = AgentServerLauncher( host=assistant_host, port=assistant_port, ) diff --git a/examples/distributed_debate/distributed_debate.py b/examples/distributed_debate/distributed_debate.py index a4e0a4287..7fc84024b 100644 --- a/examples/distributed_debate/distributed_debate.py +++ b/examples/distributed_debate/distributed_debate.py @@ -8,7 +8,7 @@ import agentscope from agentscope.agents import DialogAgent from agentscope.msghub import msghub -from agentscope.server import RpcAgentServerLauncher +from agentscope.server import AgentServerLauncher from agentscope.message import Msg from agentscope.utils.logging_utils import logger @@ -75,7 +75,7 @@ def setup_server(parsed_args: argparse.Namespace) -> None: ) host = getattr(parsed_args, f"{parsed_args.role}_host") port = getattr(parsed_args, f"{parsed_args.role}_port") - server_launcher = RpcAgentServerLauncher( + server_launcher = AgentServerLauncher( host=host, port=port, custom_agents=[UserProxyAgent, DialogAgent], diff --git a/examples/distributed_simulation/main.py b/examples/distributed_simulation/main.py index bb26fe533..130527d78 100644 --- a/examples/distributed_simulation/main.py +++ b/examples/distributed_simulation/main.py @@ -11,7 +11,7 @@ import agentscope from agentscope.agents import AgentBase -from agentscope.server import RpcAgentServerLauncher +from agentscope.server import AgentServerLauncher from agentscope.message import Msg @@ -58,7 +58,7 @@ def setup_participant_agent_server(host: str, port: int) -> None: model_configs="configs/model_configs.json", use_monitor=False, ) - assistant_server_launcher = RpcAgentServerLauncher( + assistant_server_launcher = AgentServerLauncher( host=host, port=port, max_pool_size=16384, diff --git a/src/agentscope/agents/agent.py b/src/agentscope/agents/agent.py index bdf657df2..91f45527a 100644 --- a/src/agentscope/agents/agent.py +++ b/src/agentscope/agents/agent.py @@ -24,7 +24,7 @@ class _AgentMeta(ABCMeta): """ def __init__(cls, name: Any, bases: Any, attrs: Any) -> None: - if not hasattr(cls, "registry"): + if not hasattr(cls, "_registry"): cls._registry = {} else: if name in cls._registry: @@ -245,7 +245,7 @@ def register_agent_class(cls, agent_class: Type[AgentBase]) -> None: """ agent_class_name = agent_class.__name__ if agent_class_name in cls._registry: - logger.warning( + logger.info( f"Agent class with name [{agent_class_name}] already exists.", ) else: diff --git a/src/agentscope/agents/rpc_agent.py b/src/agentscope/agents/rpc_agent.py index e4274f700..3332b00d2 100644 --- a/src/agentscope/agents/rpc_agent.py +++ b/src/agentscope/agents/rpc_agent.py @@ -9,7 +9,7 @@ serialize, ) from agentscope.rpc import RpcAgentClient -from agentscope.server.launcher import RpcAgentServerLauncher +from agentscope.server.launcher import AgentServerLauncher def rpc_servicer_method( # type: ignore[no-untyped-def] @@ -89,7 +89,7 @@ def __init__( launch_server = port is None if launch_server: self.host = "localhost" - self.server_launcher = RpcAgentServerLauncher( + self.server_launcher = AgentServerLauncher( host=self.host, port=port, max_pool_size=max_pool_size, diff --git a/src/agentscope/server/__init__.py b/src/agentscope/server/__init__.py index 18b2ad790..0ce9e8d3d 100644 --- a/src/agentscope/server/__init__.py +++ b/src/agentscope/server/__init__.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- """Import all server related modules in the package.""" -from .launcher import RpcAgentServerLauncher +from .launcher import AgentServerLauncher from .servicer import AgentPlatform __all__ = [ - "RpcAgentServerLauncher", + "AgentServerLauncher", "AgentPlatform", ] diff --git a/src/agentscope/server/launcher.py b/src/agentscope/server/launcher.py index 387552115..78afb4f0f 100644 --- a/src/agentscope/server/launcher.py +++ b/src/agentscope/server/launcher.py @@ -24,7 +24,7 @@ add_RpcAgentServicer_to_server = Any -def setup_rpc_agent_server( +def setup_agent_server( host: str, port: int, init_settings: dict = None, @@ -36,7 +36,7 @@ def setup_rpc_agent_server( max_timeout_seconds: int = 1800, custom_agents: list = None, ) -> None: - """Setup gRPC server rpc agent. + """Setup agent server. Args: host (`str`, defaults to `"localhost"`): @@ -63,7 +63,7 @@ def setup_rpc_agent_server( A list of custom agent classes that are not in `agentscope.agents`. """ asyncio.run( - setup_rpc_agent_server_async( + setup_agent_server_async( host=host, port=port, init_settings=init_settings, @@ -78,7 +78,7 @@ def setup_rpc_agent_server( ) -async def setup_rpc_agent_server_async( +async def setup_agent_server_async( host: str, port: int, init_settings: dict = None, @@ -90,7 +90,7 @@ async def setup_rpc_agent_server_async( max_timeout_seconds: int = 1800, custom_agents: list = None, ) -> None: - """Setup gRPC server rpc agent in an async way. + """Setup agent server in an async way. Args: host (`str`, defaults to `"localhost"`): @@ -207,7 +207,7 @@ def check_port(port: Optional[int] = None) -> int: return port -class RpcAgentServerLauncher: +class AgentServerLauncher: """The launcher of AgentPlatform (formerly RpcAgentServer).""" def __init__( @@ -222,7 +222,7 @@ def __init__( agent_args: tuple = (), agent_kwargs: dict = None, ) -> None: - """Init a rpc agent server launcher. + """Init a launcher of agent server. Args: host (`str`, defaults to `"localhost"`): @@ -262,7 +262,7 @@ def __init__( ): logger.warning( "`agent_class`, `agent_args` and `agent_kwargs` is deprecated" - " in `RpcAgentServerLauncher`", + " in `AgentServerLauncher`", ) def _launch_in_main(self) -> None: @@ -271,7 +271,7 @@ def _launch_in_main(self) -> None: f"Launching agent server at [{self.host}:{self.port}]...", ) asyncio.run( - setup_rpc_agent_server_async( + setup_agent_server_async( host=self.host, port=self.port, max_pool_size=self.max_pool_size, @@ -289,7 +289,7 @@ def _launch_in_sub(self) -> None: self.parent_con, child_con = Pipe() start_event = Event() server_process = Process( - target=setup_rpc_agent_server, + target=setup_agent_server, kwargs={ "host": self.host, "port": self.port, diff --git a/tests/rpc_agent_test.py b/tests/rpc_agent_test.py index d70613268..bc861824f 100644 --- a/tests/rpc_agent_test.py +++ b/tests/rpc_agent_test.py @@ -9,7 +9,7 @@ import agentscope from agentscope.agents import AgentBase, DistConf -from agentscope.server import RpcAgentServerLauncher +from agentscope.server import AgentServerLauncher from agentscope.message import Msg from agentscope.message import PlaceholderMessage from agentscope.message import deserialize @@ -220,7 +220,7 @@ def test_single_rpc_agent_server(self) -> None: def test_connect_to_an_existing_rpc_server(self) -> None: """test connecting to an existing server""" - launcher = RpcAgentServerLauncher( + launcher = AgentServerLauncher( # choose port automatically host="127.0.0.1", port=12010, @@ -420,7 +420,7 @@ def test_standalone_multiprocess_init(self) -> None: def test_multi_agent_in_same_server(self) -> None: """test agent server with multi agent""" - launcher = RpcAgentServerLauncher( + launcher = AgentServerLauncher( host="127.0.0.1", port=12010, local_mode=False, @@ -548,14 +548,14 @@ def test_error_handling(self) -> None: def test_agent_nesting(self) -> None: """Test agent nesting""" host = "localhost" - launcher1 = RpcAgentServerLauncher( + launcher1 = AgentServerLauncher( # choose port automatically host=host, port=12010, local_mode=False, custom_agents=[DemoGatherAgent, DemoGeneratorAgent], ) - launcher2 = RpcAgentServerLauncher( + launcher2 = AgentServerLauncher( # choose port automatically host=host, port=12011,