Skip to content

Commit dd39cdd

Browse files
authored
Fix agent config and command toggles (#203)
1 parent f89aaeb commit dd39cdd

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

Config/Agent.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,20 @@ def get_agent_config(self):
234234
self.add_agent(self.AGENT_NAME, {})
235235
return agent_config
236236

237-
def update_agent_config(self, new_config):
237+
def update_agent_config(self, new_config, config_key):
238238
agent_name = self.AGENT_NAME
239239
agent_config_file = os.path.join("agents", agent_name, "config.json")
240240
if os.path.exists(agent_config_file):
241241
with open(agent_config_file, "r") as f:
242242
current_config = json.load(f)
243243

244-
# Ensure the "settings" key is present in the current configuration
245-
if "settings" not in current_config:
246-
current_config["settings"] = {}
244+
# Ensure the config_key is present in the current configuration
245+
if config_key not in current_config:
246+
current_config[config_key] = {}
247247

248-
# Update the "settings" key with new_config
249-
current_config["settings"].update(new_config)
248+
# Update the specified key with new_config while preserving other keys and values
249+
for key, value in new_config.items():
250+
current_config[config_key][key] = value
250251

251252
# Save the updated configuration back to the file
252253
with open(agent_config_file, "w") as f:

app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ async def rename_agent(agent_name: str, new_name: AgentNewName) -> ResponseMessa
154154
async def update_agent_settings(
155155
agent_name: str, settings: AgentSettings
156156
) -> ResponseMessage:
157-
update_config = Agent(agent_name).update_agent_config(settings.settings)
157+
update_config = Agent(agent_name).update_agent_config(settings.settings, "settings")
158158
return ResponseMessage(message=update_config)
159159

160160

@@ -224,14 +224,14 @@ async def toggle_command(
224224
commands = Commands(agent_name)
225225
for each_command_name in commands.agent_config["commands"]:
226226
commands.agent_config["commands"][each_command_name] = payload.enable
227-
agent.update_agent_config(commands.agent_config)
227+
agent.update_agent_config(commands.agent_config["commands"], "commands")
228228
return ResponseMessage(
229229
message=f"All commands enabled for agent '{agent_name}'."
230230
)
231231
else:
232232
commands = Commands(agent_name)
233233
commands.agent_config["commands"][payload.command_name] = payload.enable
234-
agent.update_agent_config(commands.agent_config)
234+
agent.update_agent_config(commands.agent_config["commands"], "commands")
235235
return ResponseMessage(
236236
message=f"Command '{payload.command_name}' toggled for agent '{agent_name}'."
237237
)

0 commit comments

Comments
 (0)