Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

Fix commands with same name overwriting (#4226)

k-boikovd06d8a609fd5
diff --git a/autogpt/commands/command.py b/autogpt/commands/command.py
index 22ebace5a6..174a691c5f 100644
--- a/autogpt/commands/command.py
+++ b/autogpt/commands/command.py
@@ -3,6 +3,8 @@ import importlib
import inspect
from typing import Any, Callable, Optional
+from autogpt.logs import logger
+
# Unique identifier for auto-gpt commands
AUTO_GPT_COMMAND_IDENTIFIER = "auto_gpt_command"
@@ -59,6 +61,10 @@ class CommandRegistry:
return importlib.reload(module)
def register(self, cmd: Command) -> None:
+ if cmd.name in self.commands:
+ logger.warn(
+ f"Command '{cmd.name}' already registered and will be overwritten!"
+ )
self.commands[cmd.name] = cmd
def unregister(self, command_name: str):
@@ -133,6 +139,11 @@ def command(
) -> Callable[..., Any]:
"""The command decorator is used to create Command objects from ordinary functions."""
+ if not enabled:
+ if disabled_reason is not None:
+ logger.debug(f"Command '{name}' is disabled: {disabled_reason}")
+ return lambda func: func
+
def decorator(func: Callable[..., Any]) -> Command:
cmd = Command(
name=name,