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.

feat(agent): Allow boolean values for `available` param on `@command`

Reinier van der Leer1262b72f5cab
diff --git a/autogpts/autogpt/autogpt/command_decorator.py b/autogpts/autogpt/autogpt/command_decorator.py
index 70a519a42c..f53c1ad85e 100644
--- a/autogpts/autogpt/autogpt/command_decorator.py
+++ b/autogpts/autogpt/autogpt/command_decorator.py
@@ -25,7 +25,7 @@ def command(
enabled: Literal[True] | Callable[[Config], bool] = True,
disabled_reason: Optional[str] = None,
aliases: list[str] = [],
- available: Literal[True] | Callable[[BaseAgent], bool] = True,
+ available: bool | Callable[[BaseAgent], bool] = True,
) -> Callable[[Callable[P, CO]], Callable[P, CO]]:
"""
The command decorator is used to create Command objects from ordinary functions.
diff --git a/autogpts/autogpt/autogpt/models/command.py b/autogpts/autogpt/autogpt/models/command.py
index 90aa266cc9..5472dc4aa4 100644
--- a/autogpts/autogpt/autogpt/models/command.py
+++ b/autogpts/autogpt/autogpt/models/command.py
@@ -32,7 +32,7 @@ class Command:
enabled: Literal[True] | Callable[[Config], bool] = True,
disabled_reason: Optional[str] = None,
aliases: list[str] = [],
- available: Literal[True] | Callable[[BaseAgent], bool] = True,
+ available: bool | Callable[[BaseAgent], bool] = True,
):
self.name = name
self.description = description
@@ -55,7 +55,7 @@ class Command:
)
raise RuntimeError(f"Command '{self.name}' is disabled")
- if callable(self.available) and not self.available(agent):
+ if not self.available or callable(self.available) and not self.available(agent):
raise RuntimeError(f"Command '{self.name}' is not available")
return self.method(*args, **kwargs, agent=agent)