agentscope.server package

Submodules

Module contents

Import all server related modules in the package.

class agentscope.server.RpcAgentServerLauncher(host: str = 'localhost', port: int | None = None, capacity: int = 32, pool_type: str = 'local', redis_url: str = 'redis://localhost:6379', max_pool_size: int = 8192, max_expire_time: int = 7200, max_timeout_seconds: int = 5, 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, capacity: int = 32, pool_type: str = 'local', redis_url: str = 'redis://localhost:6379', max_pool_size: int = 8192, max_expire_time: int = 7200, max_timeout_seconds: int = 5, 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.

  • capacity (int, default to 32) – The number of concurrent agents in the server.

  • pool_type (str, defaults to “local”) – The type of the async message pool, which can be local or redis. If redis is specified, you need to start a redis server before launching the server.

  • redis_url (str) – The address of the redis server. Defaults to redis://localhost:6379.

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

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

  • max_timeout_seconds (int, defaults to 5) – Max timeout seconds for rpc calls.

  • 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.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.

  • –capacity: the number of concurrent agents in the server.

  • –pool-type: the type of the async message pool, which can be local or redis. If redis is specified, you need to start a redis server before launching the server. Defaults to local.

  • –redis-url: the url of the redis server, defaults to redis://localhost:6379.

  • –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-expire: max expire time for async function result.

  • –max-timeout-seconds: max timeout for rpc call.

  • –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 start --host localhost \
    --port 12345 \
    --model-config-path config.json \
    --agent-dir ./my_agents