agentscope.rpc package

Submodules

Module contents

Import all rpc related modules in the package.

class agentscope.rpc.RpcAgentClient(host: str, port: int, agent_id: str | None = None)[source]

Bases: object

A client of Rpc agent server

__init__(host: str, port: int, agent_id: str | None = None) None[source]

Init a rpc agent client

Parameters:
  • host (str) – The hostname of the rpc agent server which the

  • connected. (is)

  • port (int) – The port of the rpc agent server which the client

  • connected.

  • agent_id (str) – The agent id of the agent being called.

  • None. (Defaults to)

call_agent_func(func_name: str, value: str | None = None, timeout: int = 300) str[source]

Call the specific function of an agent running on the server.

Parameters:
  • func_name (str) – The name of the function being called.

  • value (str, optional) – The serialized function input value.

  • None. (Defaults to)

  • timeout (int, optional) – The timeout for the RPC call in seconds.

  • 300. (Defaults to)

Returns:

serialized return data.

Return type:

str

is_alive() bool[source]

Check if the agent server is alive.

Returns:

Indicate whether the server is alive.

Return type:

bool

stop() None[source]

Stop the agent server.

create_agent(agent_configs: dict, agent_id: str | None = None) bool[source]

Create a new agent for this client.

Parameters:
  • agent_configs (dict) – Init configs of the agent, generated by

  • _AgentMeta.

  • agent_id (str) – agent_id of the created agent.

Returns:

Indicate whether the creation is successful

Return type:

bool

delete_agent(agent_id: str | None = None) bool[source]

Delete agents with the specific agent_id.

Parameters:

agent_id (str) – id of the agent to be deleted.

Returns:

Indicate whether the deletion is successful

Return type:

bool

delete_all_agent() bool[source]

Delete all agents on the server.

clone_agent(agent_id: str) str | None[source]

Clone a new agent instance from the origin instance.

Parameters:

agent_id (str) – The agent_id of the agent to be cloned.

Returns:

The agent_id of the generated agent.

Return type:

str

update_placeholder(task_id: int) str[source]

Update the placeholder value.

Parameters:

task_id (int) – task_id of the PlaceholderMessage.

Returns:

Whether the update is successful. str: Serialized message value.

Return type:

bool

get_agent_list() Sequence[dict][source]

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

Returns:

list of agent summary information.

Return type:

Sequence[str]

get_server_info() dict[source]

Get the agent server resource usage information.

set_model_configs(model_configs: dict | list[dict]) bool[source]

Set the model configs of the server.

get_agent_memory(agent_id: str) list[Msg] | Msg[source]

Get the memory usage of the specific agent.

download_file(path: str) str[source]

Download a file from a remote server to the local machine.

Args: path (str): The path of the file to be downloaded. Note that

it is the path on the remote server.

Returns:

The path of the downloaded file. Note that it is the path on the local machine.

Return type:

str

class agentscope.rpc.ResponseStub[source]

Bases: object

A stub used to save the response of a rpc call in a sub-thread.

__init__() None[source]
set_response(response: str) None[source]

Set the message.

get_response() str[source]

Get the message.

class agentscope.rpc.RpcMsg

Bases: Message, Message

DESCRIPTOR = <google._upb._message.Descriptor object>
class agentscope.rpc.RpcAgentServicer[source]

Bases: object

Servicer for rpc agent server

is_alive(request, context)[source]

check server is alive

stop(request, context)[source]

stop the server

create_agent(request, context)[source]

create a new agent on the server

delete_agent(request, context)[source]

delete agent from the server

delete_all_agents(request, context)[source]

clear all agent on the server

clone_agent(request, context)[source]

clone an agent with specific agent_id

get_agent_list(request, context)[source]

get id of all agents on the server as a list

get_server_info(request, context)[source]

get the resource utilization information of the server

set_model_configs(request, context)[source]

update the model configs in the server

get_agent_memory(request, context)[source]

get memory of a specific agent

call_agent_func(request, context)[source]

call funcs of agent running on the server

update_placeholder(request, context)[source]

update value of PlaceholderMessage

download_file(request, context)[source]

file transfer

class agentscope.rpc.RpcAgentStub(channel)[source]

Bases: object

Servicer for rpc agent server

__init__(channel)[source]

Constructor.

Parameters:

channel – A grpc.Channel.

agentscope.rpc.call_in_thread(client: RpcAgentClient, value: str, func_name: str) ResponseStub[source]

Call rpc function in a sub-thread.

Parameters:
  • client (RpcAgentClient) – The rpc client.

  • value (str) – The value of the request.

  • func_name (str) – The name of the function being called.

Returns:

A stub to get the response.

Return type:

ResponseStub

agentscope.rpc.add_RpcAgentServicer_to_server(servicer, server)[source]