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

Allow absolute paths when not restricting to workspace root #4946

Merged

Conversation

antonovmaxim
Copy link
Contributor

@antonovmaxim antonovmaxim commented Jul 11, 2023

Background

I have RESTRICT_TO_WORKSPACE=False and I'm getting error
Attempted to access absolute path '{relative_path}' in workspace '{root}'.

Changes

Only raise an error if restrict_to_root is True.

Documentation

Line 125 and 126

Test Plan

I asked Auto-GPT to add file C://text.txt with text '12345'. (in .env file RESTRICT_TO_WORKSPACE=False)

without my fix I want Auto-GPT to: add file C://text.txt with text '12345' NOTE:All files/directories created by this agent can be found inside its workspace at: C:\Users\max\Desktop\AGI\Auto-GPT\autogpt\workspace\auto_gpt_workspace FileAgentGPT has been created with the following details: Name: FileAgentGPT Role: an autonomous agent that specializes in file management and manipulation, providing efficient and reliable assistance in handling various file-related tasks. Goals: - Receive and process file-related commands to add, modify, or delete files as per your instructions. - Ensure the successful addition of the specified file 'C://text.txt' with the text '12345' as requested. - Verify the accuracy and integrity of the added file by cross-checking the content with the provided text. - Handle any potential errors or exceptions during the file addition process and provide appropriate feedback or solutions. - Maintain a secure and organized file system, adhering to best practices and ensuring the confidentiality and availability of your files. Using memory of type: JSONFileMemory Using Browser: chrome FILEAGENTGPT THOUGHTS: To accomplish the goal of adding the specified file 'C://text.txt' with the text '12345', I will use the 'write_to_file' command. REASONING: The 'write_to_file' command allows me to create a new file or overwrite an existing file with the specified text content. - Use the 'write_to_file' command with the filename 'C://text.txt' and the text '12345'. CRITICISM: I need to ensure that the file 'C://text.txt' does not already exist before using the 'write_to_file' command to avoid overwriting any existing file. SPEAK: I will use the 'write_to_file' command to add the file 'C://text.txt' with the text '12345'.

NEXT ACTION: COMMAND = write_to_file ARGUMENTS = {'filename': 'C://text.txt', 'text': '12345'}
Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for FileAgentGPT...
Asking user via keyboard...
Input:y
-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=
SYSTEM: Command write_to_file returned: Error: Attempted to access absolute path 'C:\text.txt' in workspace 'C:\Users\max\Desktop\AGI\Auto-GPT\autogpt\workspace\auto_gpt_workspace'.

with my fix I want Auto-GPT to: add file C://text.txt with text '12345' NOTE:All files/directories created by this agent can be found inside its workspace at: C:\Users\max\Desktop\AGI\Auto-GPT\autogpt\workspace\auto_gpt_workspace FileAgentGPT has been created with the following details: Name: FileAgentGPT Role: an autonomous agent that specializes in file management and manipulation, providing efficient and reliable assistance in handling various file-related tasks. Goals: - Receive and process file-related commands to add, modify, or delete files as per your instructions. - Ensure the successful addition of the specified file 'C://text.txt' with the text '12345' as requested. - Verify the accuracy and integrity of the added file by cross-checking the content with the provided text. - Handle any potential errors or exceptions during the file addition process and provide appropriate feedback or solutions. - Maintain a secure and organized file system, adhering to best practices and ensuring the confidentiality and availability of your files. Using memory of type: JSONFileMemory Using Browser: chrome FILEAGENTGPT THOUGHTS: To accomplish the goal of adding the specified file 'C://text.txt' with the text '12345', I will use the 'write_to_file' command. REASONING: The 'write_to_file' command allows me to create a new file or overwrite an existing file with the specified text content. - Use the 'write_to_file' command with the filename 'C://text.txt' and the text '12345'. CRITICISM: I need to ensure that the file 'C://text.txt' does not already exist before using the 'write_to_file' command to avoid overwriting any existing file. SPEAK: I will use the 'write_to_file' command to add the file 'C://text.txt' with the text '12345'.

NEXT ACTION: COMMAND = write_to_file ARGUMENTS = {'filename': 'C://text.txt', 'text': '12345'}
Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for FileAgentGPT...
Asking user via keyboard...
Input:y
-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=
SYSTEM: Command write_to_file returned: File written to successfully.

PR Quality Checklist

  • My pull request is atomic and focuses on a single change.
  • I have thoroughly tested my changes with multiple different prompts.
  • I have considered potential risks and mitigations for my changes.
  • I have documented my changes clearly and comprehensively.
  • I have not snuck in any "extra" small tweaks changes.
  • I have run the following commands against my code to ensure it passes our linters:
    black .
    isort .
    mypy
    autoflake --remove-all-unused-imports --recursive --ignore-init-module-imports --ignore-pass-after-docstring autogpt tests --in-place

@netlify
Copy link

netlify bot commented Jul 11, 2023

Deploy Preview for auto-gpt-docs canceled.

Name Link
🔨 Latest commit 4adb33b
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/64b031d63638fe00087fb70f

@codecov
Copy link

codecov bot commented Jul 11, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.08 ⚠️

Comparison is base (a0f5aa9) 51.00% compared to head (7654ffb) 50.92%.

❗ Current head 7654ffb differs from pull request most recent head 4adb33b. Consider uploading reports for the commit 4adb33b to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4946      +/-   ##
==========================================
- Coverage   51.00%   50.92%   -0.08%     
==========================================
  Files         118      119       +1     
  Lines        4884     4895      +11     
  Branches      643      646       +3     
==========================================
+ Hits         2491     2493       +2     
- Misses       2212     2219       +7     
- Partials      181      183       +2     
Impacted Files Coverage Δ
autogpt/workspace/workspace.py 92.85% <100.00%> (ø)

... and 10 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@collijk
Copy link
Contributor

collijk commented Jul 12, 2023

Hi @antonovmaxim. Thanks for your contribution! Could you please add a test for this in your PR. Ideally the test should fail without your fix and pass with your fix. This helps us verify that we've actually solved the problem and also helps us prevent future changes from introducing this bug again.

@antonovmaxim
Copy link
Contributor Author

Hi @collijk. Of course! I have added tests.

@collijk
Copy link
Contributor

collijk commented Jul 12, 2023

Hi @collijk. Of course! I have added tests.

I think you may have forgotten to push them

@antonovmaxim
Copy link
Contributor Author

Hi @collijk. Of course! I have added tests.

I think you may have forgotten to push them

Oh, you mean those tests. Then I'm sorry, pytest doesn't work for me. I added a description of the tests to the description of my PR.

@Pwuts Pwuts added this to the v0.4.5 Release milestone Jul 13, 2023
@Pwuts Pwuts self-assigned this Jul 13, 2023
@Pwuts Pwuts added function: workspace bug Something isn't working labels Jul 13, 2023
@Pwuts Pwuts changed the title restrict_to_root fix Allow absolute paths when not restricted to workspace root Jul 13, 2023
@Pwuts Pwuts changed the title Allow absolute paths when not restricted to workspace root Allow absolute paths when not restricting to workspace root Jul 13, 2023
@Pwuts Pwuts merged commit ed12b2c into Significant-Gravitas:master Jul 13, 2023
14 checks passed
dayofthedave pushed a commit to dayofthedave/Auto-GPT that referenced this pull request Jul 17, 2023
…ant-Gravitas#4946)

* restrict_to_root fix

* Fix formatting

---------

Co-authored-by: Reinier van der Leer <github@pwuts.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants