agentscope.server.launcher module

Server of distributed agent

agentscope.server.launcher.load_agents_from_file(agent_file: str) list[源代码]

Load AgentBase sub classes from a python file.

参数:

agent_file (str) – the path to the python file.

返回:

a list of agent classes

返回类型:

list

agentscope.server.launcher.load_agents_from_dir(agent_dir: str) list[源代码]

Load customized agents from a directory.

参数:

agent_dir (str) – a directory contains customized agent python files.

返回:

a list of customized agent classes

返回类型:

list

class agentscope.server.launcher.RpcAgentServerLauncher(host: str = 'localhost', port: int | None = None, max_pool_size: int = 8192, max_timeout_seconds: int = 7200, local_mode: bool = False, agent_dir: str | None = None, custom_agent_classes: list | None = None, server_id: str | None = None, studio_url: str | None = None)[源代码]

基类:object

The launcher of AgentServer.

__init__(host: str = 'localhost', port: int | None = None, max_pool_size: int = 8192, max_timeout_seconds: int = 7200, local_mode: bool = False, agent_dir: str | None = None, custom_agent_classes: list | None = None, server_id: str | None = None, studio_url: str | None = None) None[源代码]

Init a launcher of agent server.

参数:
  • host (str, defaults to “localhost”) – Hostname of the agent server.

  • port (int, defaults to None) – Socket port of the agent server.

  • max_pool_size (int, defaults to 8192) – The max number of agent reply messages that the server can accommodate. Note that the oldest message will be deleted after exceeding the pool size.

  • max_timeout_seconds (int, defaults to 7200) – Maximum time for reply messages to be cached in the server. Note that expired messages will be deleted.

  • local_mode (bool, defaults to False) – If True, only listen to requests from “localhost”, otherwise, listen to requests from all hosts.

  • agent_dir (str, defaults to None) – The directory containing customized agent python files.

  • custom_agent_classes (list, defaults to None) – A list of customized agent classes that are not in agentscope.agents.

  • server_id (str, defaults to None) – The id of the agent server. If not specified, a random id will be generated.

  • studio_url (Optional[str], defaults to None) – The url of the agentscope studio.

classmethod generate_server_id(host: str, port: int) str[源代码]

Generate server id

launch(in_subprocess: bool = True) None[源代码]

launch an agent server.

参数:

in_subprocess (bool, optional) – launch the server in subprocess. Defaults to True. For agents that need to obtain command line input, such as UserAgent, please set this value to False.

wait_until_terminate() None[源代码]

Wait for server process

shutdown() None[源代码]

Shutdown the agent server.

agentscope.server.launcher.as_server() None[源代码]

Launch an agent server with terminal command.

备注

The arguments of as_server are listed as follows:

  • –host: the hostname of the server.

  • –port: the socket port of the server.

  • –max-pool-size: max number of agent reply messages that the server can accommodate. Note that the oldest message will be deleted after exceeding the pool size.

  • –max-timeout-seconds: max time for reply messages to be cached in the server. Note that expired messages will be deleted.

  • –local-mode: whether the started agent server only listens to local requests.

  • –model-config-path: the path to the model config json file

  • –agent-dir: the directory containing your customized agent python files

  • –studio-url: the url of agentscope studio

In most cases, you only need to specify the –host, –port and –model-config-path, and –agent-dir.

as_server --host localhost                 --port 12345                 --model-config-path config.json                 --agent-dir ./my_agents