agentscope.rpc.rpc_meta module

Meta class for all classes that can run on rpc server.

agentscope.rpc.rpc_meta.async_func(func: Callable) Callable[source]

A decorator for async function.

In distributed mode, async functions will return a AsyncResult immediately.

Parameters:

func (Callable) – The function to decorate.

agentscope.rpc.rpc_meta.sync_func(func: Callable) Callable[source]

A decorator for sync function.

In distributed mode, sync functions will block the current thread until the result is ready.

In most cases, you don’t need to use this decorator. RpcMeta will treat all public functions without async_func as sync_func. However, for magic methods (e.g. __str__ and __getitem__, which are started with __), you can use sync_func to mark them as sync.

Parameters:

func (Callable) – The function to decorate.

agentscope.rpc.rpc_meta.generate_oid() str[source]

Generate a unique id

class agentscope.rpc.rpc_meta.RpcMeta(name: Any, bases: Any, attrs: Any)[source]

Bases: ABCMeta

The metaclass for all classes that can use to_dist and other distributed related functionality.

Note

The RpcMeta will automatically add the to_dist method and initialization parameter to its subclasses. And it will also detect all public functions and register them into the _info attribute of the class.

__init__(name: Any, bases: Any, attrs: Any) None[source]
static get_class(cls_name: str) Any[source]

Get the class based on the specific class name.

Parameters:

cls_name (str) – the name of the class.

Raises:

ValueError – class name not exits.

Returns:

the class

Return type:

Any

static register_class(cls: type) bool[source]

Register the class into the registry.

Parameters:

cls (Type) – the class to be registered.

Returns:

whether the registration is successful.

Return type:

bool

static to_dist(self: ~typing.Any, host: str = 'localhost', port: int | None = None, max_pool_size: int = 8192, max_expire_time: int = 7200, max_timeout_seconds: int = 5, local_mode: bool = True, retry_strategy: ~agentscope.rpc.retry_strategy.RetryBase = <agentscope.rpc.retry_strategy.RetryFixedTimes object>) Any[source]

Convert current object into its distributed version.

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

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

  • max_pool_size (int, defaults to 8192) – Only takes effect when host and port are not filled in. The max number of agent reply messages that the started agent server can accommodate. Note that the oldest message will be deleted after exceeding the pool size.

  • max_expire_time (int, defaults to 7200) – Only takes effect when host and port are not filled in. Maximum time for reply messages to be cached in the launched agent server. Note that expired messages will be deleted.

  • max_timeout_seconds (int, defaults to 5) – Max timeout seconds for the rpc call.

  • local_mode (bool, defaults to True) – Only takes effect when host and port are not filled in. Whether the started agent server only listens to local requests.

  • retry_strategy (RetryBase, defaults to _DEAFULT_RETRY_STRATEGY) – The retry strategy for the async rpc call.

Returns:

the wrapped agent instance with distributed functionality

Return type:

RpcObject