agentscope.manager package

Module contents

Import all manager related classes and functions.

class agentscope.manager.FileManager(*args: Any, **kwargs: Any)[source]

Bases: object

A singleton class for managing the file system for saving files, code and logs.

__init__() None[source]

Initialize the file manager with default values.

initialize(run_dir: str | None, save_log: bool, save_code: bool, save_api_invoke: bool, cache_dir: str) None[source]

Set the directory for saving files.

Parameters:
  • run_dir (Union[str, None]) – The running directory, used to save files, logs and code.

  • save_log (bool) – Whether to save logs locally.

  • save_code (bool) – Whether to save code locally.

  • save_api_invoke (bool) – Whether to save API invocations locally.

  • cache_dir (str) – The directory to save cache files.

property embedding_cache_dir: str

Obtain the embedding cache directory.

property file_dir: str

The directory for saving files, including images, audios and videos.

property code_dir: str

The directory for saving codes.

property invoke_dir: str

The directory for saving api invocations.

classmethod get_instance() FileManager[source]

Get the singleton instance.

save_api_invocation(prefix: str, record: dict) None | str[source]

Save api invocation locally.

save_python_code() None[source]

Save the code locally.

save_image(image: str | ndarray | bytes | Image, filename: str | None = None) str[source]

Save image file locally, and return the local image path.

Parameters:
  • image (Union[str, np.ndarray]) – The image url, or the image array.

  • filename (Optional[str]) – The filename of the image. If not specified, a random filename will be used.

save_file(generator: Generator[bytes, None, None], filename: str) str[source]

Save file locally from a binary generator, and return the local file path.

Note we don’t block this function when self.disable_saving==True, because in distribution mode or calling image generation model with save_local == True, we still have to save files locally. However, we save them in “./” instead.

Parameters:
  • generator (Generator[bytes, None, None]) – The generator of the binary file content.

  • filename (str) – The filename of the file.

Returns:

The local file path.

Return type:

str

save_runtime_information(runtime_info: dict) None[source]

Save the runtime information locally.

cache_text_embedding(text: str, embedding: List[float], embedding_model: str | dict) None[source]

Cache the text embedding locally.

fetch_cached_text_embedding(text: str, embedding_model: str | dict) None | List[float][source]

Fetch the text embedding from the cache.

state_dict() dict[source]

Serialize the configuration into a dict.

load_dict(data: dict) None[source]

Load the configuration from a dict.

classmethod is_initialized() bool[source]

Check if the file manager has been initialized.

flush() None[source]

Flush the file manager.

class agentscope.manager.ModelManager(*args: Any, **kwargs: Any)[source]

Bases: object

The model manager for AgentScope, which is responsible for loading and managing model configurations and models.

classmethod get_instance() ModelManager[source]

Get the instance of the singleton class.

__init__() None[source]

Initialize the model manager with model configs

model_configs: dict[str, dict] = {}

The model configs

initialize(model_configs: dict | str | list | None = None) None[source]

Initialize the model manager with model configs.

clear_model_configs() None[source]

Clear the loaded model configs.

load_model_configs(model_configs: dict | str | list, clear_existing: bool = False) None[source]

read model configs from a path or a list of dicts.

Parameters:
  • model_configs (Union[str, list, dict]) – The path of the model configs | a config dict | a list of model configs.

  • clear_existing (bool, defaults to False) – Whether to clear the loaded model configs before reading.

Returns:

The model configs.

Return type:

dict

get_model_by_config_name(config_name: str) ModelWrapperBase[source]

Load the model by config name, and return the model wrapper.

get_config_by_name(config_name: str) dict | None[source]

Load the model config by name, and return the config dict.

state_dict() dict[source]

Serialize the model manager into a dict.

load_dict(data: dict) None[source]

Load the model manager from a dict.

flush() None[source]

Flush the model manager.

class agentscope.manager.MonitorManager(*args: Any, **kwargs: Any)[source]

Bases: object

The manager of monitor module.

property path_db: str | None

The path to the database

__init__() None[source]

Initialize the monitor manager.

initialize(use_monitor: bool) None[source]

Initialize the monitor manager.

Parameters:

use_monitor (bool) – Whether to use the monitor.

classmethod get_instance() MonitorManager[source]

Get the instance of the singleton class.

update_image_tokens(model_name: str, resolution: str, image_count: int) None[source]

Update the record of the image models.

update_text_and_embedding_tokens(model_name: str, prompt_tokens: int = 0, completion_tokens: int = 0, total_tokens: int | None = None) None[source]

Update the tokens of a given model.

print_llm_usage() dict[source]

Print the usage of all different model APIs.

show_image_tokens() List[dict][source]

Show the tokens of all image models.

show_text_and_embedding_tokens() List[dict][source]

Show the tokens of all models.

rm_database() None[source]

Remove the database.

state_dict() dict[source]

Serialize the monitor manager into a dict.

load_dict(data: dict) None[source]

Load the monitor manager from a dict.

flush() None[source]

Flush the monitor manager.

class agentscope.manager.ASManager(*args: Any, **kwargs: Any)[source]

Bases: object

A manager for AgentScope.

classmethod get_instance() ASManager[source]

Get the instance of the singleton class.

__init__() None[source]

Initialize the manager. Note we initialize the managers by default arguments to avoid unnecessary errors when user doesn’t call agentscope.init function

initialize(model_configs: dict | str | list | None, project: str | None, name: str | None, disable_saving: bool, save_dir: str, save_log: bool, save_code: bool, save_api_invoke: bool, cache_dir: str, use_monitor: bool, logger_level: Literal['TRACE', 'DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'], run_id: str | None, studio_url: str | None) None[source]

Initialize the package.

state_dict() dict[source]

Serialize the runtime information.

load_dict(data: dict) None[source]

Load the runtime information from a dictionary

flush() None[source]

Flush the runtime information.