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.
- 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_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
- cache_text_embedding(text: str, embedding: List[float], embedding_model: str | dict) None [source]
Cache the text embedding locally.
- 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.
- 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.
- 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.
- 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
- 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.
- class agentscope.manager.ASManager(*args: Any, **kwargs: Any)[source]
Bases:
object
A manager for AgentScope.
- __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.