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.

Only add execute shell scripts to prompt if AI is allowed to do it. (#1551)

Richard Beales5f4e3173213e
diff --git a/autogpt/prompt.py b/autogpt/prompt.py
index 20492978eb..5924ce0ca1 100644
--- a/autogpt/prompt.py
+++ b/autogpt/prompt.py
@@ -3,6 +3,7 @@ from autogpt.config.ai_config import AIConfig
from autogpt.config.config import Config
from autogpt.logs import logger
from autogpt.promptgenerator import PromptGenerator
+from autogpt.config import Config
from autogpt.setup import prompt_user
from autogpt.utils import clean_input
@@ -18,6 +19,9 @@ def get_prompt() -> str:
str: The generated prompt string.
"""
+ # Initialize the Config object
+ cfg = Config()
+
# Initialize the PromptGenerator object
prompt_generator = PromptGenerator()
@@ -73,16 +77,27 @@ def get_prompt() -> str:
{"code": "<full_code_string>", "focus": "<list_of_focus_areas>"},
),
("Execute Python File", "execute_python_file", {"file": "<file>"}),
- (
- "Execute Shell Command, non-interactive commands only",
- "execute_shell",
- {"command_line": "<command_line>"},
- ),
- ("Task Complete (Shutdown)", "task_complete", {"reason": "<reason>"}),
("Generate Image", "generate_image", {"prompt": "<prompt>"}),
- ("Do Nothing", "do_nothing", {}),
]
+ # Only add shell command to the prompt if the AI is allowed to execute it
+ if cfg.execute_local_commands:
+ commands.append(
+ (
+ "Execute Shell Command, non-interactive commands only",
+ "execute_shell",
+ {"command_line": "<command_line>"},
+ ),
+ )
+
+ # Add these command last.
+ commands.append(
+ ("Do Nothing", "do_nothing", {}),
+ )
+ commands.append(
+ ("Task Complete (Shutdown)", "task_complete", {"reason": "<reason>"}),
+ )
+
# Add commands to the PromptGenerator object
for command_label, command_name, args in commands:
prompt_generator.add_command(command_label, command_name, args)