agentscope.manager package

Module contents

Import all manager related classes and functions.

class agentscope.manager.FileManager(*args: Any, **kwargs: Any)[源代码]

基类:object

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

__init__() None[源代码]

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

Set the directory for saving files.

参数:
  • 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[源代码]

Get the singleton instance.

save_api_invocation(prefix: str, record: dict) None | str[源代码]

Save api invocation locally.

save_python_code() None[源代码]

Save the code locally.

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

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

参数:
  • 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[源代码]

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.

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

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

返回:

The local file path.

返回类型:

str

save_runtime_information(runtime_info: dict) None[源代码]

Save the runtime information locally.

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

Cache the text embedding locally.

fetch_cached_text_embedding(text: str, embedding_model: str | dict) None | List[float][源代码]

Fetch the text embedding from the cache.

state_dict() dict[源代码]

Serialize the configuration into a dict.

load_dict(data: dict) None[源代码]

Load the configuration from a dict.

classmethod is_initialized() bool[源代码]

Check if the file manager has been initialized.

flush() None[源代码]

Flush the file manager.

class agentscope.manager.ModelManager(*args: Any, **kwargs: Any)[源代码]

基类:object

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

classmethod get_instance() ModelManager[源代码]

Get the instance of the singleton class.

__init__() None[源代码]

Initialize the model manager with model configs

model_configs: dict[str, dict] = {}

The model configs

initialize(model_configs: dict | str | list | None = None) None[源代码]

Initialize the model manager with model configs.

clear_model_configs() None[源代码]

Clear the loaded model configs.

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

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

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

返回:

The model configs.

返回类型:

dict

get_model_by_config_name(config_name: str) ModelWrapperBase[源代码]

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

get_config_by_name(config_name: str) dict | None[源代码]

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

state_dict() dict[源代码]

Serialize the model manager into a dict.

load_dict(data: dict) None[源代码]

Load the model manager from a dict.

flush() None[源代码]

Flush the model manager.

class agentscope.manager.MonitorManager(*args: Any, **kwargs: Any)[源代码]

基类:object

The manager of monitor module.

property path_db: str | None

The path to the database

__init__() None[源代码]

Initialize the monitor manager.

initialize(use_monitor: bool) None[源代码]

Initialize the monitor manager.

参数:

use_monitor (bool) – Whether to use the monitor.

classmethod get_instance() MonitorManager[源代码]

Get the instance of the singleton class.

update_image_tokens(model_name: str, resolution: str, image_count: int) None[源代码]

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

Update the tokens of a given model.

print_llm_usage() dict[源代码]

Print the usage of all different model APIs.

show_image_tokens() List[dict][源代码]

Show the tokens of all image models.

show_text_and_embedding_tokens() List[dict][源代码]

Show the tokens of all models.

rm_database() None[源代码]

Remove the database.

state_dict() dict[源代码]

Serialize the monitor manager into a dict.

load_dict(data: dict) None[源代码]

Load the monitor manager from a dict.

flush() None[源代码]

Flush the monitor manager.

class agentscope.manager.ASManager(*args: Any, **kwargs: Any)[源代码]

基类:object

A manager for AgentScope.

classmethod get_instance() ASManager[源代码]

Get the instance of the singleton class.

__init__() None[源代码]

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

Initialize the package.

state_dict() dict[源代码]

Serialize the runtime information.

load_dict(data: dict) None[源代码]

Load the runtime information from a dictionary

flush() None[源代码]

Flush the runtime information.