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[源代码]

A decorator for async function.

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

参数:

func (Callable) – The function to decorate.

agentscope.rpc.rpc_meta.sync_func(func: Callable) Callable[源代码]

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.

参数:

func (Callable) – The function to decorate.

agentscope.rpc.rpc_meta.generate_oid() str[源代码]

Generate a unique id

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

基类:ABCMeta

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

备注

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[源代码]
static get_class(cls_name: str) Any[源代码]

Get the class based on the specific class name.

参数:

cls_name (str) – the name of the class.

抛出:

ValueError – class name not exits.

返回:

the class

返回类型:

Any

static register_class(cls: type) bool[源代码]

Register the class into the registry.

参数:

cls (Type) – the class to be registered.

返回:

whether the registration is successful.

返回类型:

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[源代码]

Convert current object into its distributed version.

参数:
  • 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.

返回:

the wrapped agent instance with distributed functionality

返回类型:

RpcObject