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.
Add exec_shell command
Bernhard Mueller66eb1dcfc5d5
diff --git a/scripts/commands.py b/scripts/commands.pyindex fc10d1d052..187ad6c4b3 100644--- a/scripts/commands.py+++ b/scripts/commands.py@@ -7,7 +7,7 @@ import speakfrom config import Configimport ai_functions as aifrom file_operations import read_file, write_to_file, append_to_file, delete_file, search_files-from execute_code import execute_python_file+from execute_code import execute_python_file, exec_shellfrom json_parser import fix_and_parse_jsonfrom duckduckgo_search import ddgfrom googleapiclient.discovery import build@@ -102,6 +102,8 @@ def execute_command(command_name, arguments):return ai.write_tests(arguments["code"], arguments.get("focus"))elif command_name == "execute_python_file": # Add this commandreturn execute_python_file(arguments["file"])+ elif command_name == "exec_shell": # Add this command+ return exec_shell(arguments["command_line"])elif command_name == "task_complete":shutdown()else:diff --git a/scripts/data/prompt.txt b/scripts/data/prompt.txtindex 28797d9e24..e7d0cd824a 100644--- a/scripts/data/prompt.txt+++ b/scripts/data/prompt.txt@@ -22,7 +22,8 @@ COMMANDS:16. Get Improved Code: "improve_code", args: "suggestions": "<list_of_suggestions>", "code": "<full_code_string>"17. Write Tests: "write_tests", args: "code": "<full_code_string>", "focus": "<list_of_focus_areas>"18. Execute Python File: "execute_python_file", args: "file": "<file>"-19. Task Complete (Shutdown): "task_complete", args: "reason": "<reason>"+19. Execute Shell Command: "exec_shell", args: "command_line": "<command_line>"+20. Task Complete (Shutdown): "task_complete", args: "reason": "<reason>"RESOURCES:diff --git a/scripts/execute_code.py b/scripts/execute_code.pyindex 614ef6fc3d..5d4f7236a9 100644--- a/scripts/execute_code.py+++ b/scripts/execute_code.py@@ -1,5 +1,6 @@import dockerimport os+import subprocessdef execute_python_file(file):@@ -45,3 +46,17 @@ def execute_python_file(file):except Exception as e:return f"Error: {str(e)}"++++def exec_shell(command_line):++ args = command_line.split()++ result = subprocess.run(args, capture_output=True)++ output = f"STDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}";++ # print(f"Shell execution complete. Output: {output}")++ return output