agentscope.agents.rpc_agent module

Base class for Rpc Agent

class agentscope.agents.rpc_agent.RpcAgent(*args: tuple, **kwargs: dict)[源代码]

基类:AgentBase

A wrapper to extend an AgentBase into a gRPC Client.

__init__(name: str, host: str = 'localhost', port: int | None = None, agent_class: Type[AgentBase] | None = None, agent_configs: dict | None = None, max_pool_size: int = 8192, max_timeout_seconds: int = 7200, local_mode: bool = True, lazy_launch: bool = False, agent_id: str | None = None, connect_existing: bool = False) None[源代码]

Initialize a RpcAgent instance.

参数:
  • name (str) – the name of the agent.

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

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

  • agent_class (Type[AgentBase]) – the AgentBase subclass of the source agent.

  • agent_configs (dict) – The args used to init configs of the agent, generated by _AgentMeta.

  • max_pool_size (int, defaults to 8192) – Max number of task results that the server can accommodate.

  • max_timeout_seconds (int, defaults to 7200) – Timeout for task results.

  • local_mode (bool, defaults to True) – Whether the started gRPC server only listens to local requests.

  • lazy_launch (bool, defaults to False) – Only launch the server when the agent is called.

  • agent_id (str, defaults to None) – The agent id of this instance. If None, it will be generated randomly.

  • connect_existing (bool, defaults to False) – Set to True, if the agent is already running on the agent server.

reply(x: Sequence[Msg] | Msg | None = None) Msg[源代码]

Define the actions taken by this agent.

参数:

x (Optional[Union[Msg, Sequence[Msg]]], defaults to None) – The input message(s) to the agent, which also can be omitted if the agent doesn’t need any input.

返回:

The output message generated by the agent.

返回类型:

Msg

备注

Given that some agents are in an adversarial environment, their input doesn’t include the thoughts of other agents.

observe(x: Msg | Sequence[Msg]) None[源代码]

Observe the input, store it in memory without response to it.

参数:

x (Union[Msg, Sequence[Msg]]) – The input message to be recorded in memory.

clone_instances(num_instances: int, including_self: bool = True) Sequence[AgentBase][源代码]

Clone a series of this instance with different agent_id and return them as a list.

参数:
  • num_instances (int) – The number of instances in the returned

  • list. (this method in the returned)

  • including_self (bool) – Whether to include the instance calling

  • list.

返回:

A list of agent instances.

返回类型:

Sequence[AgentBase]

stop() None[源代码]

Stop the RpcAgent and the rpc server.