diff --git a/autogpt/agents/base.py b/autogpt/agents/base.py index c0133ea7..029b07a0 100644 --- a/autogpt/agents/base.py +++ b/autogpt/agents/base.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from autogpt.llm.base import ChatModelResponse, ChatSequence, Message from autogpt.llm.providers.openai import OPEN_AI_CHAT_MODELS, get_openai_command_specs from autogpt.llm.utils import count_message_tokens, create_chat_completion -from autogpt.logs import logger +from autogpt.logs import CURRENT_CONTEXT_FILE_NAME, logger from autogpt.memory.message_history import MessageHistory from autogpt.prompts.prompt import DEFAULT_TRIGGERING_PROMPT @@ -105,7 +105,13 @@ class BaseAgent(metaclass=ABCMeta): prompt: ChatSequence = self.construct_prompt(instruction) prompt = self.on_before_think(prompt, instruction) - + self.log_cycle_handler.log_cycle( + self.ai_config.ai_name, + self.created_at, + self.cycle_count, + prompt.raw(), + CURRENT_CONTEXT_FILE_NAME, + ) raw_response = create_chat_completion( prompt, self.config, diff --git a/autogpt/commands/file_operations.py b/autogpt/commands/file_operations.py index 939b7dc1..715a90ae 100644 --- a/autogpt/commands/file_operations.py +++ b/autogpt/commands/file_operations.py @@ -274,37 +274,6 @@ def append_to_file( return f"Error: {err}" -@command( - "delete_file", - "Deletes a file", - { - "filename": { - "type": "string", - "description": "The name of the file to delete", - "required": True, - } - }, -) -@sanitize_path_arg("filename") -def delete_file(filename: str, agent: Agent) -> str: - """Delete a file - - Args: - filename (str): The name of the file to delete - - Returns: - str: A message indicating success or failure - """ - if is_duplicate_operation("delete", filename, agent): - return "Error: File has already been deleted." - try: - os.remove(filename) - log_operation("delete", filename, agent) - return "File deleted successfully." - except Exception as err: - return f"Error: {err}" - - @command( "list_files", "Lists Files in a Directory", diff --git a/autogpt/core/planning/templates.py b/autogpt/core/planning/templates.py index e28f2ed7..59792f65 100644 --- a/autogpt/core/planning/templates.py +++ b/autogpt/core/planning/templates.py @@ -17,7 +17,6 @@ ABILITIES = ( 'analyze_code: Analyze Code, args: "code": ""', 'execute_python_file: Execute Python File, args: "filename": ""', 'append_to_file: Append to file, args: "filename": "", "text": ""', - 'delete_file: Delete file, args: "filename": ""', 'list_files: List Files in Directory, args: "directory": ""', 'read_file: Read a file, args: "filename": ""', 'write_to_file: Write to file, args: "filename": "", "text": ""', diff --git a/tests/unit/test_file_operations.py b/tests/unit/test_file_operations.py index d7d870a5..b3f1fb8f 100644 --- a/tests/unit/test_file_operations.py +++ b/tests/unit/test_file_operations.py @@ -282,24 +282,6 @@ def test_append_to_file_uses_checksum_from_appended_file( ) -def test_delete_file(test_file_with_content_path: Path, agent: Agent): - result = file_ops.delete_file(str(test_file_with_content_path), agent=agent) - assert result == "File deleted successfully." - assert os.path.exists(test_file_with_content_path) is False - - -def test_delete_missing_file(agent: Agent): - filename = "path/to/file/which/does/not/exist" - # confuse the log - file_ops.log_operation("write", filename, agent=agent, checksum="fake") - try: - os.remove(agent.workspace.get_path(filename)) - except FileNotFoundError as err: - assert str(err) in file_ops.delete_file(filename, agent=agent) - return - assert False, f"Failed to test delete_file; {filename} not expected to exist" - - def test_list_files(workspace: Workspace, test_directory: Path, agent: Agent): # Case 1: Create files A and B, search for A, and ensure we don't return A and B file_a = workspace.get_path("file_a.txt")