Load agent configurations with version history from JSON. Loads basic configuration only (instance is not saved, must be created via build()). Only the latest version will be instantiated by default if auto_initialize=True. Args: file_path: File
(
self, file_path: Optional[str] = None, auto_initialize: bool = True
)
| 885 | return str(file_path) |
| 886 | |
| 887 | async def load_from_json( |
| 888 | self, file_path: Optional[str] = None, auto_initialize: bool = True |
| 889 | ) -> bool: |
| 890 | """Load agent configurations with version history from JSON. |
| 891 | |
| 892 | Loads basic configuration only (instance is not saved, must be created via build()). |
| 893 | Only the latest version will be instantiated by default if auto_initialize=True. |
| 894 | |
| 895 | Args: |
| 896 | file_path: File path to load from |
| 897 | auto_initialize: Whether to automatically create instance via build() after loading |
| 898 | |
| 899 | Returns: |
| 900 | True if loaded successfully, False otherwise |
| 901 | """ |
| 902 | |
| 903 | file_path = file_path if file_path is not None else self.save_path |
| 904 | |
| 905 | async with file_lock(file_path): |
| 906 | if not os.path.exists(file_path): |
| 907 | logger.warning(f"| ⚠️ Agent file not found: {file_path}") |
| 908 | return False |
| 909 | |
| 910 | try: |
| 911 | with open(file_path, "r", encoding="utf-8") as f: |
| 912 | load_data = json.load(f) |
| 913 | |
| 914 | agents_data = load_data.get("agents", {}) |
| 915 | loaded_count = 0 |
| 916 | |
| 917 | for agent_name, agent_data in agents_data.items(): |
| 918 | try: |
| 919 | # Expected format: multiple versions stored as a dict {version_str: config_dict} |
| 920 | versions_data = agent_data.get("versions") |
| 921 | if not isinstance(versions_data, dict): |
| 922 | logger.warning(f"| ⚠️ Agent {agent_name} has invalid format for 'versions' (expected dict), skipping") |
| 923 | continue |
| 924 | |
| 925 | current_version_str = agent_data.get("current_version") |
| 926 | |
| 927 | # Load all versions |
| 928 | version_configs = [] |
| 929 | latest_config = None |
| 930 | latest_version = None |
| 931 | |
| 932 | for version_str, config_dict in versions_data.items(): |
| 933 | # Ensure version field is present |
| 934 | if "version" not in config_dict: |
| 935 | config_dict["version"] = version_str |
| 936 | |
| 937 | try: |
| 938 | agent_config = AgentConfig.model_validate(config_dict) |
| 939 | version_configs.append(agent_config) |
| 940 | except Exception as e: |
| 941 | logger.warning(f"| ⚠️ Failed to load agent config for {agent_name}@{version_str}: {e}") |
| 942 | continue |
| 943 | |
| 944 | # Track latest version |
nothing calls this directly
no test coverage detected