Registry Module¶
This module provides a centralized registration center for agents and environment modules, supporting lazy loading.
ModuleRegistry¶
- class agentsociety2.registry.ModuleRegistry[source]¶
Bases:
objectCentralized registry (singleton) for agent and environment modules.
Two types of sources are supported:
Built-in modules: from
agentsociety2.contribwith built-in agents (e.g. PersonAgent)Custom module:
custom/directory from workspace
Lazy loading is enabled by default: discovery and registration are only triggered when registry content is accessed for the first time.
- property env_modules: Dict[str, Type[EnvBase]]¶
Returns the registered environment module mapping and triggers lazy loading on access.
- property agent_modules: Dict[str, Type[AgentBase]]¶
Returns the registered agent mapping and triggers lazy loading on access.
- register_env_module(module_type, module_class, is_custom=False)[source]¶
Register environment module.
- get_env_module(module_type)[source]¶
Get the environment module class by type (will trigger lazy loading).
- list_env_modules()[source]¶
Returns the list of registered environment modules and triggers lazy loading on access.
- list_agent_modules()[source]¶
Returns the list of registered agents and triggers lazy loading on access.
- set_workspace(workspace_path)[source]¶
Set workspace path (for custom module discovery).
- Parameters:
workspace_path (Path) – workspace directory.
Utility function¶
- agentsociety2.registry.get_registry()[source]¶
- Returns:
Global
ModuleRegistrySingleton.- Return type:
Register function¶
- agentsociety2.registry.get_env_module_class(module_type)[source]¶
Get the environment module class by type.
- agentsociety2.registry.list_all_modules()[source]¶
List all registered modules (including description and custom flag).
- agentsociety2.registry.reload_modules(workspace_path=None)[source]¶
Empty and rediscover modules (load on demand).
- Parameters:
workspace_path (Path | None) – Optional workspace path (for custom modules).
- agentsociety2.registry.scan_and_register_custom_modules(workspace_path, registry=None)[source]¶
Scan and register custom modules under custom/.
- Parameters:
workspace_path (Path) – workspace path.
registry (ModuleRegistry | None) – Optional registry; empty to use the global registry.
- Returns:
scan results (including envs/agents/errors).
- Return type:
- agentsociety2.registry.discover_and_register_builtin_modules(registry=None)[source]¶
Discover and register all built-in modules (contrib + built-in agent).
- Parameters:
registry (ModuleRegistry | None) – Optional registry; empty to use the global registry.
request/response model¶
- class agentsociety2.registry.EnvModuleInitConfig(*, module_type, args=<factory>)[source]¶
Environment module initialization configuration.
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agentsociety2.registry.AgentInitConfig(*, agent_type, agent_id, args=<factory>)[source]¶
agent initialization configuration.
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agentsociety2.registry.CreateInstanceRequest(*, instance_id, env_modules, agents, start_t, tick=1)[source]¶
Create the request body of the AgentSociety instance.
- env_modules: List[EnvModuleInitConfig]¶
- agents: List[AgentInitConfig]¶
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].