Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMMAND = write_to_file fails if file exists #3514

Closed
1 task done
ram-sh opened this issue Apr 29, 2023 · 11 comments
Closed
1 task done

COMMAND = write_to_file fails if file exists #3514

ram-sh opened this issue Apr 29, 2023 · 11 comments
Labels
bug Something isn't working Stale

Comments

@ram-sh
Copy link

ram-sh commented Apr 29, 2023

⚠️ Search for existing issues first ⚠️

  • I have searched the existing issues, and there is no existing issue for my problem

Which Operating System are you using?

Windows

Which version of Auto-GPT are you using?

Stable (branch)

GPT-3 or GPT-4?

GPT-3.5

Steps to reproduce 🕹

Auto-GPT fails to write_to_file if file already exists and returns Command write_to_file returned: Error: File has already been updated. and can loop over again and again trying to write to that file

to bypass this behavior, i had to remove the line manually write: hello.py from the file_logger.txt each loop for Auto-GPT keeps on working on the file.

Current behavior 😯

No response

Expected behavior 🤔

No response

Your prompt 📝

# Paste your prompt here

Your Logs 📒

THOUGHTS:  I think I will start by writing a file named hello.py and changing its content.
REASONING:  The goal is to write a file named hello.py, so I will use the 'write_to_file' command to create the file and add content to it.
PLAN: 
-  Use the 'write_to_file' command to create a file named hello.py and add content to it.
CRITICISM:  I need to ensure that the file is created successfully and that the content is added correctly.
NEXT ACTION:  COMMAND = write_to_file ARGUMENTS = {'file': 'hello.py', 'text': "print('Hello, World!')"}
Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for ...
Input:y
-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-= 
SYSTEM:  Command write_to_file returned: Error: File has already been updated.
 THOUGHTS:  Since the file already exists, I will use the 'read_file' command to check its content.
REASONING:  The 'read_file' command will allow me to check the content of the file named hello.py and ensure that it contains the correct code.
PLAN: 
-  Use the 'read_file' command to check the content of the file named hello.py.
CRITICISM:  I need to ensure that the file is read successfully and that the content is correct.
NEXT ACTION:  COMMAND = read_file ARGUMENTS = {'file': 'hello.py'}
Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for ...
Input:y
-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-= 
SYSTEM:  Command read_file returned: Hello, world!This is another line of text.
 THOUGHTS:  I will use the 'write_to_file' command again to change the content of the file named hello.py.
REASONING:  The 'write_to_file' command will allow me to change the content of the file named hello.py to the correct code.
PLAN: 
-  Use the 'write_to_file' command to change the content of the file named hello.py to the correct code.
CRITICISM:  I need to ensure that the file is updated successfully and that the content is correct.
NEXT ACTION:  COMMAND = write_to_file ARGUMENTS = {'file': 'hello.py', 'text': "print('Hello, World!')\n"}
Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for ...
Input:y
-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-= 
SYSTEM:  Command write_to_file returned: Error: File has already been updated.
 THOUGHTS:  I will use the 'append_to_file' command to add a new line of text to the file named hello.py.
REASONING:  The 'append_to_file' command will allow me to add a new line of text to the file named hello.py without overwriting the existing content.
PLAN: 
-  Use the 'append_to_file' command to add a new line of text to the file named hello.py.
CRITICISM:  I need to ensure that the file is updated successfully and that the new line of text is added correctly.
NEXT ACTION:  COMMAND = append_to_file ARGUMENTS = {'file': 'hello.py', 'text': 'This is another line of text.\n'}
Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for ...
Input:
@ram-sh
Copy link
Author

ram-sh commented Apr 29, 2023

to bypass the issue I've commented out the following lines from the function write_to_file in /workspaces/Auto-GPT-0.2.2/autogpt/commands/file_operations.py:

# if check_duplicate_operation("write", filename):
# return "Error: File has already been updated."

@k-boikov k-boikov added the bug Something isn't working label Apr 29, 2023
@bobisme
Copy link
Contributor

bobisme commented Apr 29, 2023

I've got a PR open to fix this #3489

@stephane303
Copy link

If this has been merged to master, the issue is still here
Testing with 4767fe6, which is the last commit in master at the time of writing

@bfalans
Copy link
Contributor

bfalans commented May 3, 2023

Opened PR #3643 for fixing this issue

@Boostrix
Copy link
Contributor

Boostrix commented May 5, 2023

can confirm that I can still reproduce the issue.
Regarding duplicate operation checking: I suppose, IF the file exists, it might make more sense to take a hash and compare its contents with the new contents

@bobisme
Copy link
Contributor

bobisme commented May 5, 2023

@Boostrix so you're talking about a situation where the operation is in the log, but someone has manually deleted the file?

@Boostrix
Copy link
Contributor

Boostrix commented May 5, 2023

well, not sure if that's generally the case, I believe I was seeing this because I was re-running the same agent (ai_settings.yaml) file giving it variations of the same objectives, so it would obviously have some leftover state (in the form files but apparently also log data?)

Regarding my comment, the idea was not that someone might actually delete the file, but that it may be there and may need to be updated by an agent (because it was created by another run/instance, not sure if that makes sense).

Also, checking for duplicate ops is obviously meaningful, but should probably yield a response that affects the plan/planning process, so that it knows something went haywire. The errors I've been seeing related to this, didn't impress the planner much - it would simply re-loop, not even changing its approach (aka, same command/same params).

This is why I elsewhere suggest to hash action [command] + params and use that as the key into a dict to be able to increment a counter - if that is also done for the response, we can at least use some plausible heuristics to tell if the agent is doing something kinda retarded.

Likewise, the command registry/list offered to the LLM to pick the next step would probably benefit from being augmented with a success/fail history (number of invocations and percentage of successes/fails of a certain command) - that would enable the LLM to quickly notice that something isn't quite right with the provided command (in conjunction with a corresponding constraint/performance evaluation) - as it would enable the LLM to favor actions that worked "recently" (I believe I described that somewhere using the "MRU" acronym)

@bobisme
Copy link
Contributor

bobisme commented May 5, 2023

don't know about all that, but this makes me realize that the file operations log is not a reliable source of truth as it's duplicating the state of the filesystem and it's trivial for those to go out of sync...

@Boostrix
Copy link
Contributor

Boostrix commented May 5, 2023

right, you don't need to do anything fancy to make these heuristics go haywire - it's sufficient to resume/re-run an agent or refer to the same file several times via the same list of objectives, sooner or later you'll end up crippling the whole workflow that way. The only way to work around this issue is to intervene and tell the agent to use an alternate solution like a CLI editor

To literally detect a dupe command execution attempt, the underlying heuristics would need to hash the old contents and new contents to be written. Then again, maybe it's just trying to be too clever here ? I mean, it's called "write_to_file" after all, not "check_if_necessary_to_write_to_file".

Dupe detection is necessary due to deeper issues in the agent system - but writing/updating a file always entailed opening/writing and closing it, and at the very least that means changing its timestamp - thus, trying to be too clever by showing an error for a file operation that is perfectly valid - and which has side effects that are not covered by the heuristics (different contents / timestamp changed), is begging for problems like these.

For now, I'd probably just disable the check or make it a "soft" error (aka warning), saying that an existing file seems to be overwritten - but the whole log approach to look at file system state that may not even be current is also problematik IMO

@github-actions
Copy link
Contributor

github-actions bot commented Sep 6, 2023

This issue has automatically been marked as stale because it has not had any activity in the last 50 days. You can unstale it by commenting or removing the label. Otherwise, this issue will be closed in 10 days.

@github-actions github-actions bot added the Stale label Sep 6, 2023
@github-actions
Copy link
Contributor

This issue was closed automatically because it has been stale for 10 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
Development

No branches or pull requests

6 participants