agentscope.server.launcher module

Server of distributed agent

class 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)[source]

Bases: object

The launcher of AgentServer.

classmethod generate_server_id(host: str, port: int) str[source]

Generate server id

launch(in_subprocess: bool = True) None[source]

launch an agent server.

Parameters:

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.

shutdown() None[source]

Shutdown the agent server.

wait_until_terminate() None[source]

Wait for server process

as_server() None[source]

Launch an agent server with terminal command.

Note

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
load_agents_from_dir(agent_dir: str) list[source]

Load customized agents from a directory.

Parameters:

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

Returns:

a list of customized agent classes

Return type:

list

load_custom_class_from_file(agent_file: str) list[source]

Load AgentBase sub classes from a python file.

Parameters:

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

Returns:

a list of agent classes

Return type:

list