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

feat(agent): Abstract file storage access #6931

Conversation

kcze
Copy link
Contributor

@kcze kcze commented Feb 28, 2024

This improvement abstracts file access across whole project, so that AutoGPT app/agents can use different backends (e.g. local, GCS, S3).

Fixes related issue: OPEN-103

Changes

  • ⚠️ BREAKING: Rename WORKSPACE_BACKEND to FILE_STORAGE_BACKEND

  • ⚠️ BREAKING: Rename WORKSPACE_STORAGE_BUCKET to STORAGE_BUCKET

  • Rename FileWorkspace to FileStorage

    • autogpt.file_workspace -> autogpt.file_storage
    • LocalFileWorkspace -> LocalFileStorage
    • S3FileWorkspace -> S3FileStorage
    • GCSFileWorkspace -> GCSFileStorage
  • Add FileStorage method clone_with_subroot

  • Add FileStorage methods exists, make_dir, delete_dir, rename, list_files, list_folders

  • Create AgentFileManagerMixin to replace AgentFileManager, FileWorkspaceMixin, BaseAgent.attach_fs(..)

    • Replace BaseAgentSettings.save_to_json_file(..) method by AgentFileManagerMixin.save_state()
    • Replace BaseAgent.set_id(..) method by AgentFileManagerMixin.change_agent_id(..)
    • Remove BaseAgentSettings.load_from_json_file(..)
    • Remove AgentSettings.agent_data_dir
  • Updates across codebase to adjust for this change, such as replacing direct file access to use FileStorage instead

    • Rewrite AgentManager to use FileStorage rather than direct local file access
      • Rename AgentManager.retrieve_state(..) method to load_agent_state
      • Add docstrings to AgentManager
    • Update AgentProtocolServer to work with the new FileStorage system and AgentFileManagerMixin
    • Update autogpt.commands.file_operations to use FileStorage and AgentFileManagerMixin features
  • Make agent_id and file_storage parameters for creating an Agent:

    • Update autogpt.agent_factory.configurators:
      create_agent(..), configure_agent_with_state(..), _configure_agent(..), create_agent_state(..)
    • Update autogpt.agent_factory.generators:
      generate_agent_for_task(..)
    • Update Agent.__init__(..)
    • Update BaseAgent.__init__(..)
    • Initialize and pass in file_storage in autogpt.app.main.run_auto_gpt(..) and autogpt.app.main.run_auto_gpt_server(..)
  • Update tests for FileStorage implementations and usages

  • Rename workspace fixture to storage

    • Update conftest.py

@kcze kcze requested a review from a team as a code owner February 28, 2024 11:16
Copy link
Contributor

This PR exceeds the recommended size of 500 lines. Please make sure you are NOT addressing multiple issues with one PR.

Copy link

netlify bot commented Feb 28, 2024

Deploy Preview for auto-gpt-docs ready!

Name Link
🔨 Latest commit 480002f
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/65ef7688ac23930008d86074
😎 Deploy Preview https://deploy-preview-6931--auto-gpt-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

This PR exceeds the recommended size of 500 lines. Please make sure you are NOT addressing multiple issues with one PR.

Copy link
Contributor

This PR exceeds the recommended size of 500 lines. Please make sure you are NOT addressing multiple issues with one PR.

Copy link
Member

@Pwuts Pwuts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a first XL pull request this looks very good! I do have a number of comments/requests but don't let that be a discouragement. :)

Questions:

  • Have the added methods on GCSFileStorage and S3FileStorage been tested?
  • How much of this has been end-to-end tested?

autogpts/autogpt/agbenchmark_config/benchmarks.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/agent_manager/agent_manager.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/file_storage/base.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/file_storage/gcs.py Outdated Show resolved Hide resolved
autogpts/autogpt/tests/utils.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/app/main.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/agents/utils/file_manager.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/app/main.py Outdated Show resolved Hide resolved
@Pwuts Pwuts changed the title OPEN-194: Improvement - abstract storage access feat(agent): Abstract storage access Feb 28, 2024
Code cleanup, import order, better naming.
@Significant-Gravitas Significant-Gravitas deleted a comment from github-actions bot Mar 1, 2024
Copy link
Contributor

github-actions bot commented Mar 1, 2024

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

Copy link
Contributor

github-actions bot commented Mar 1, 2024

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

Copy link
Contributor

github-actions bot commented Mar 6, 2024

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@kcze kcze requested a review from Pwuts March 6, 2024 15:42
autogpts/autogpt/tests/conftest.py Show resolved Hide resolved
autogpts/autogpt/tests/unit/test_gcs_file_storage.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/file_storage/gcs.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/file_storage/gcs.py Show resolved Hide resolved
autogpts/autogpt/autogpt/agents/agent.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/agents/base.py Outdated Show resolved Hide resolved
autogpts/autogpt/autogpt/app/agent_protocol_server.py Outdated Show resolved Hide resolved
@Pwuts Pwuts changed the title feat(agent): Abstract storage access feat(agent): Abstract file storage access Mar 7, 2024
Copy link
Contributor

github-actions bot commented Mar 7, 2024

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

Copy link
Contributor

github-actions bot commented Mar 7, 2024

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@kcze kcze requested a review from Pwuts March 7, 2024 22:08
Copy link
Contributor

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

Pwuts
Pwuts previously approved these changes Mar 11, 2024
Copy link
Member

@Pwuts Pwuts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good and tests pass. LGTM!

Copy link
Contributor

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@Pwuts Pwuts merged commit 37904a0 into Significant-Gravitas:master Mar 11, 2024
11 of 14 checks passed
@kcze kcze deleted the kpczerwinski/open-194-abstract-storage-access branch March 11, 2024 21:42
@Pwuts
Copy link
Member

Pwuts commented Mar 12, 2024

Fails to deploy to GCP:

ERROR 2024-03-12T14:47:31.371921Z Traceback (most recent call last): File "<string>", line 1, in <module> File "/venv/agpt-9TtSrW0h-py3.10/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
DEFAULT 2024-03-12T14:47:31.371932Z return self.main(*args, **kwargs)
DEFAULT 2024-03-12T14:47:31.371941Z File "/venv/agpt-9TtSrW0h-py3.10/lib/python3.10/site-packages/click/core.py", line 1078, in main
DEFAULT 2024-03-12T14:47:31.371945Z rv = self.invoke(ctx)
DEFAULT 2024-03-12T14:47:31.371951Z File "/venv/agpt-9TtSrW0h-py3.10/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
DEFAULT 2024-03-12T14:47:31.371955Z return _process_result(sub_ctx.command.invoke(sub_ctx))
DEFAULT 2024-03-12T14:47:31.371959Z File "/venv/agpt-9TtSrW0h-py3.10/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
DEFAULT 2024-03-12T14:47:31.371963Z return ctx.invoke(self.callback, **ctx.params)
DEFAULT 2024-03-12T14:47:31.371968Z File "/venv/agpt-9TtSrW0h-py3.10/lib/python3.10/site-packages/click/core.py", line 783, in invoke
DEFAULT 2024-03-12T14:47:31.371972Z return __callback(*args, **kwargs)
DEFAULT 2024-03-12T14:47:31.371976Z File "/app/autogpt/app/cli.py", line 272, in serve
DEFAULT 2024-03-12T14:47:31.371980Z run_auto_gpt_server(
DEFAULT 2024-03-12T14:47:31.371984Z File "/app/autogpt/core/runner/client_lib/utils.py", line 60, in wrapper
DEFAULT 2024-03-12T14:47:31.371988Z return asyncio.run(f(*args, **kwargs))
DEFAULT 2024-03-12T14:47:31.371992Z File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
DEFAULT 2024-03-12T14:47:31.371995Z return loop.run_until_complete(main)
DEFAULT 2024-03-12T14:47:31.372Z File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
DEFAULT 2024-03-12T14:47:31.372003Z return future.result()
DEFAULT 2024-03-12T14:47:31.372007Z File "/app/autogpt/app/main.py", line 351, in run_auto_gpt_server
DEFAULT 2024-03-12T14:47:31.372011Z file_storage = get_storage(
DEFAULT 2024-03-12T14:47:31.372015Z File "/app/autogpt/file_storage/__init__.py", line 37, in get_storage
DEFAULT 2024-03-12T14:47:31.372019Z return GCSFileStorage(config)
DEFAULT 2024-03-12T14:47:31.372023Z File "/app/autogpt/file_storage/gcs.py", line 36, in __init__
DEFAULT 2024-03-12T14:47:31.372026Z assert self._root.is_absolute()
DEFAULT 2024-03-12T14:47:31.372043Z AssertionError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants