From c025132c8416946e219bb7ccd6de7a8460af1ac4 Mon Sep 17 00:00:00 2001 From: "Luke K (pr-0f3t)" <2609441+lc0rp@users.noreply.github.com> Date: Tue, 27 Jun 2023 14:16:58 -0400 Subject: [PATCH] Unregister commands incompatible with current config. (#4815) --- autogpt/main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/autogpt/main.py b/autogpt/main.py index 3c1f722dfb6..0217507a357 100644 --- a/autogpt/main.py +++ b/autogpt/main.py @@ -139,6 +139,20 @@ def run_auto_gpt( for command_category in enabled_command_categories: command_registry.import_commands(command_category) + # Unregister commands that are incompatible with the current config + incompatible_commands = [] + for command in command_registry.commands.values(): + if callable(command.enabled) and not command.enabled(config): + command.enabled = False + incompatible_commands.append(command) + + for command in incompatible_commands: + command_registry.unregister(command.name) + logger.debug( + f"Unregistering incompatible command: {command.name}, " + f"reason - {command.disabled_reason or 'Disabled by current config.'}" + ) + ai_name = "" ai_config = construct_main_ai_config(config) ai_config.command_registry = command_registry