|
1 | 1 | from initialize import initialize_agent |
2 | | -from python.helpers import dirty_json, files |
| 2 | +from python.helpers import dirty_json, files, subagents, projects |
3 | 3 | from python.helpers.extension import Extension |
4 | 4 |
|
5 | 5 |
|
6 | 6 | class LoadProfileSettings(Extension): |
7 | | - |
| 7 | + |
8 | 8 | async def execute(self, **kwargs) -> None: |
9 | 9 |
|
10 | 10 | if not self.agent or not self.agent.config.profile: |
11 | 11 | return |
12 | 12 |
|
13 | | - settings_path = files.get_abs_path("agents", self.agent.config.profile, "settings.json") |
14 | | - if files.exists(settings_path): |
15 | | - try: |
16 | | - override_settings_str = files.read_file(settings_path) |
17 | | - override_settings = dirty_json.parse(override_settings_str) |
18 | | - |
19 | | - if isinstance(override_settings, dict): |
20 | | - # Preserve the original memory_subdir unless it's explicitly overridden |
21 | | - current_memory_subdir = self.agent.config.memory_subdir |
22 | | - # FIX: Also preserve the original profile |
23 | | - original_profile = self.agent.config.profile |
24 | | - |
25 | | - new_config = initialize_agent(override_settings=override_settings) |
26 | | - |
27 | | - if ( |
28 | | - "agent_memory_subdir" not in override_settings |
29 | | - and current_memory_subdir != "default" |
30 | | - ): |
31 | | - new_config.memory_subdir = current_memory_subdir |
32 | | - |
33 | | - # FIX: Restore the original profile |
34 | | - new_config.profile = original_profile |
35 | | - |
36 | | - self.agent.config = new_config |
37 | | - |
| 13 | + config_files = subagents.get_paths(self.agent, "settings.json", include_default=False) |
| 14 | + |
| 15 | + settings_override = {} |
| 16 | + for settings_path in config_files: |
| 17 | + if files.exists(settings_path): |
| 18 | + try: |
| 19 | + override_settings_str = files.read_file(settings_path) |
| 20 | + override_settings = dirty_json.try_parse(override_settings_str) |
| 21 | + if isinstance(override_settings, dict): |
| 22 | + settings_override.update(override_settings) |
| 23 | + else: |
| 24 | + raise Exception( |
| 25 | + f"Subordinate settings in {settings_path} must be a JSON object." |
| 26 | + ) |
| 27 | + except Exception as e: |
38 | 28 | self.agent.context.log.log( |
39 | | - type="info", |
| 29 | + type="error", |
40 | 30 | content=( |
41 | | - "Loaded custom settings for agent " |
42 | | - f"{self.agent.number} with profile '{self.agent.config.profile}'." |
| 31 | + f"Error loading subordinate settings from {settings_path} for " |
| 32 | + f"profile '{self.agent.config.profile}': {e}" |
43 | 33 | ), |
44 | 34 | ) |
45 | | - else: |
46 | | - raise Exception( |
47 | | - f"Subordinate settings in {settings_path} " |
48 | | - "must be a JSON object." |
49 | | - ) |
50 | 35 |
|
51 | | - except Exception as e: |
52 | | - self.agent.context.log.log( |
53 | | - type="error", |
54 | | - content=( |
55 | | - "Error loading subordinate settings for " |
56 | | - f"profile '{self.agent.config.profile}': {e}" |
57 | | - ), |
58 | | - ) |
| 36 | + if settings_override: |
| 37 | + # Preserve the original memory_subdir unless it's explicitly overridden |
| 38 | + current_memory_subdir = self.agent.config.memory_subdir |
| 39 | + # FIX: Also preserve the original profile |
| 40 | + original_profile = self.agent.config.profile |
| 41 | + |
| 42 | + new_config = initialize_agent(override_settings=settings_override) |
| 43 | + |
| 44 | + if ( |
| 45 | + "agent_memory_subdir" not in settings_override |
| 46 | + and current_memory_subdir != "default" |
| 47 | + ): |
| 48 | + new_config.memory_subdir = current_memory_subdir |
| 49 | + |
| 50 | + # FIX: Restore the original profile |
| 51 | + new_config.profile = original_profile |
| 52 | + |
| 53 | + self.agent.config = new_config |
0 commit comments