agentscope.agents.rpc_agent module
Base class for Rpc Agent
- class agentscope.agents.rpc_agent.RpcAgent(*args: tuple, **kwargs: dict)[source]
Bases:
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 [source]
Initialize a RpcAgent instance.
- Parameters:
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: Msg | Sequence[Msg] | None = None) Msg [source]
Define the actions taken by this agent.
- Parameters:
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.
- Returns:
The output message generated by the agent.
- Return type:
Msg
Note
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 [source]
Observe the input, store it in memory without response to it.
- Parameters:
x (Union[Msg, Sequence[Msg]]) – The input message to be recorded in memory.
- clone_instances(num_instances: int, including_self: bool = True) Sequence[AgentBase] [source]
Clone a series of this instance with different agent_id and return them as a list.
- Parameters:
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.
- Returns:
A list of agent instances.
- Return type:
Sequence[AgentBase]