Allow subordinate agents to override settings

linuztx committed Oct 26, 2025 at 14:34 UTC a2a5a4c00cb400215cf3f1bab250a8157524b1cf
3 files changed +62 -1
initialize.py
+3 -1
@@ -4,8 +4,10 @@ from python.helpers import runtime, settings, defer
4 from python.helpers.print_style import PrintStyle
5
6
7 -def initialize_agent():
7 +def initialize_agent(override_settings: dict | None = None):
8 current_settings = settings.get_settings()
9 + if override_settings:
10 + current_settings = settings.merge_settings(current_settings, override_settings)
11
12 def _normalize_model_kwargs(kwargs: dict) -> dict:
13 # convert string values that represent valid Python numbers to numeric types
python/extensions/agent_init/_15_load_profile_settings.py new
+53
@@ -0,0 +1,53 @@
1 +from initialize import initialize_agent
2 +from python.helpers import dirty_json, files
3 +from python.helpers.extension import Extension
4 +
5 +
6 +class LoadProfileSettings(Extension):
7 +
8 + async def execute(self, **kwargs) -> None:
9 +
10 + if not self.agent or not self.agent.config.profile:
11 + return
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 +
23 + new_config = initialize_agent(override_settings=override_settings)
24 +
25 + if (
26 + "agent_memory_subdir" not in override_settings
27 + and current_memory_subdir != "default"
28 + ):
29 + new_config.memory_subdir = current_memory_subdir
30 +
31 + self.agent.config = new_config
32 +
33 + self.agent.context.log.log(
34 + type="info",
35 + content=(
36 + "Loaded custom settings for agent "
37 + f"{self.agent.number} with profile '{self.agent.config.profile}'."
38 + ),
39 + )
40 + else:
41 + raise Exception(
42 + f"Subordinate settings in {settings_path} "
43 + "must be a JSON object."
44 + )
45 +
46 + except Exception as e:
47 + self.agent.context.log.log(
48 + type="error",
49 + content=(
50 + "Error loading subordinate settings for "
51 + f"profile '{self.agent.config.profile}': {e}"
52 + ),
53 + )
python/helpers/settings.py
+6
@@ -1334,6 +1334,12 @@ def set_settings_delta(delta: dict, apply: bool = True):
1334 set_settings(new, apply) # type: ignore
1335
1336
1337 +def merge_settings(original: Settings, delta: dict) -> Settings:
1338 + merged = original.copy()
1339 + merged.update(delta)
1340 + return merged
1341 +
1342 +
1343 def normalize_settings(settings: Settings) -> Settings:
1344 copy = settings.copy()
1345 default = get_default_settings()