agentscope.server.async_result_pool module

A pool used to store the async result.

class agentscope.server.async_result_pool.AsyncResultPool[source]

Bases: ABC

Interface of Async Result Pool, used to store async results.

abstract prepare() int[source]

Prepare a slot for the async result.

Returns:

The key of the async result.

Return type:

int

abstract set(key: int, value: bytes) None[source]

Set a value to the pool.

Parameters:
  • key (int) – The key of the value.

  • value (bytes) – The value to be set.

abstract get(key: int, timeout: int = 5) bytes[source]

Get a value from the pool.

Parameters:
  • key (int) – The key of the value

  • timeout (int) – The timeout seconds to wait for the value.

Returns:

The value

Return type:

bytes

Raises:

TimeoutError – When the timeout is reached.

class agentscope.server.async_result_pool.LocalPool(max_len: int, max_expire: int)[source]

Bases: AsyncResultPool

Local pool for storing results.

__init__(max_len: int, max_expire: int) None[source]
prepare() int[source]

Prepare a slot for the async result.

Returns:

The key of the async result.

Return type:

int

set(key: int, value: bytes) None[source]

Set a value to the pool.

Parameters:
  • key (int) – The key of the value.

  • value (bytes) – The value to be set.

get(key: int, timeout: int = 5) bytes[source]

Get the value with timeout

class agentscope.server.async_result_pool.RedisPool(url: str, max_expire: int)[source]

Bases: AsyncResultPool

Redis pool for storing results.

INCR_KEY = 'as_obj_id'
TASK_QUEUE_PREFIX = 'as_task_'
__init__(url: str, max_expire: int) None[source]

Init redis pool.

Parameters:
  • url (str) – The url of the redis server.

  • max_expire (int) – The max timeout of the result in the pool,

  • reached (when it is)

  • removed. (the oldest item will be)

prepare() int[source]

Prepare a slot for the async result.

Returns:

The key of the async result.

Return type:

int

set(key: int, value: bytes) None[source]

Set a value to the pool.

Parameters:
  • key (int) – The key of the value.

  • value (bytes) – The value to be set.

get(key: int, timeout: int = 5) bytes[source]

Get a value from the pool.

Parameters:
  • key (int) – The key of the value

  • timeout (int) – The timeout seconds to wait for the value.

Returns:

The value

Return type:

bytes

Raises:

TimeoutError – When the timeout is reached.

agentscope.server.async_result_pool.get_pool(pool_type: str = 'local', max_expire: int = 7200, max_len: int = 8192, redis_url: str = 'redis://localhost:6379') AsyncResultPool[source]

Get the pool according to the type.

Parameters:
  • pool_type (str) – The type of the pool, can be local or redis, default is local.

  • max_expire (int) – The max expire time of the result in the pool, when it is reached, the oldest item will be removed.

  • max_len (int) – The max length of the pool.

  • redis_url (str) – The address of the redis server.