Skip to content

Commit 6baa059

Browse files
committed
Merge branch 'development' into fix/profile-preservation-bug
Resolved merge conflict by combining development's architectural improvements with the profile preservation fix. Changes: - Accept development's multi-file settings merging (subagents.get_paths) - Accept development's try_parse() for safer JSON parsing - Add profile preservation fix (original_profile save/restore) - Fix extends memory_subdir preservation pattern to profile as well
1 parent f530fb1 commit 6baa059

File tree

1 file changed

+38
-43
lines changed

1 file changed

+38
-43
lines changed
Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,53 @@
11
from initialize import initialize_agent
2-
from python.helpers import dirty_json, files
2+
from python.helpers import dirty_json, files, subagents, projects
33
from python.helpers.extension import Extension
44

55

66
class LoadProfileSettings(Extension):
7-
7+
88
async def execute(self, **kwargs) -> None:
99

1010
if not self.agent or not self.agent.config.profile:
1111
return
1212

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:
3828
self.agent.context.log.log(
39-
type="info",
29+
type="error",
4030
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}"
4333
),
4434
)
45-
else:
46-
raise Exception(
47-
f"Subordinate settings in {settings_path} "
48-
"must be a JSON object."
49-
)
5035

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

Comments
 (0)