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

Bases: 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[source]

Init a launcher of agent server.

Parameters:
  • 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[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.

wait_until_terminate() None[source]

Wait for server process

shutdown() None[source]

Shutdown the agent server.

class agentscope.server.AgentServerServicer(stop_event: Event, host: str = 'localhost', port: int | None = None, server_id: str | None = None, studio_url: str | None = None, max_pool_size: int = 8192, max_timeout_seconds: int = 7200)[source]

Bases: RpcAgentServicer

A Servicer for RPC Agent Server (formerly RpcServerSideWrapper)

__init__(stop_event: Event, host: str = 'localhost', port: int | None = None, server_id: str | None = None, studio_url: str | None = None, max_pool_size: int = 8192, max_timeout_seconds: int = 7200)[source]

Init the AgentServerServicer.

Parameters:
  • stop_event (Event) – Event to stop the server.

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

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

  • server_id (str, defaults to None) – Server id of the rpc agent server.

  • studio_url (str, defaults to None) – URL of the AgentScope Studio.

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

get_task_id() int[source]

Get the auto-increment task id. Each reply call will get a unique task id.

agent_exists(agent_id: str) bool[source]

Check whether the agent exists.

Parameters:

agent_id (str) – the agent id.

Returns:

whether the agent exists.

Return type:

bool

get_agent(agent_id: str) AgentBase[source]

Get the agent by agent id.

Parameters:

agent_id (str) – the agent id.

Returns:

the agent.

Return type:

AgentBase

is_alive(request: Empty, context: ServicerContext) GeneralResponse[source]

Check whether the server is alive.

stop(request: Empty, context: ServicerContext) GeneralResponse[source]

Stop the server.

create_agent(request: CreateAgentRequest, context: ServicerContext) GeneralResponse[source]

Create a new agent on the server.

delete_agent(request: StringMsg, context: ServicerContext) GeneralResponse[source]

Delete agents from the server.

Parameters:
  • request (StringMsg) – The value field is the agent_id of the

  • deleted. (agents to be)

clone_agent(request: StringMsg, context: ServicerContext) GeneralResponse[source]

Clone a new agent instance from the origin instance.

Parameters:
  • request (StringMsg) – The value field is the agent_id of the

  • cloned. (agent to be)

Returns:

The agent_id of generated agent. Empty if clone failed.

Return type:

GeneralResponse

delete_all_agents(request: Empty, context: ServicerContext) GeneralResponse[source]

clear all agent on the server

call_agent_func(request: RpcMsg, context: ServicerContext) GeneralResponse[source]

Call the specific servicer function.

update_placeholder(request: UpdatePlaceholderRequest, context: ServicerContext) GeneralResponse[source]

Update the value of a placeholder.

get_agent_list(request: Empty, context: ServicerContext) GeneralResponse[source]

Get id of all agents on the server as a list.

get_server_info(request: Empty, context: ServicerContext) GeneralResponse[source]

Get the agent server resource usage information.

set_model_configs(request: StringMsg, context: ServicerContext) GeneralResponse[source]

Set the model configs of the agent server.

get_agent_memory(request: StringMsg, context: ServicerContext) StringMsg[source]

Get the memory of a specific agent.

download_file(request: StringMsg, context: ServicerContext) Any[source]

Download file from local path.

agentscope.server.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.

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