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.
Fix workspace crashing (#5041)
merwanehamadi60d0f5edace0
diff --git a/agbenchmark/benchmarks.py b/agbenchmark/benchmarks.pyindex e8675f92a2..ea884b3aa5 100644--- a/agbenchmark/benchmarks.py+++ b/agbenchmark/benchmarks.py@@ -27,8 +27,8 @@ def bootstrap_agent(task, continuous_mode) -> Agent:config.plain_output = Truecommand_registry = get_command_registry(config)config.memory_backend = "no_memory"- Workspace.set_workspace_directory(config)- Workspace.build_file_logger_path(config, config.workspace_path)+ config.workspace_path = Workspace.set_workspace_directory(config)+ config.file_logger_path = Workspace.build_file_logger_path(config.workspace_path)ai_config = AIConfig(ai_name="Auto-GPT",ai_role="a multi-purpose AI assistant.",@@ -41,7 +41,6 @@ def bootstrap_agent(task, continuous_mode) -> Agent:ai_config=ai_config,config=config,triggering_prompt=DEFAULT_TRIGGERING_PROMPT,- workspace_directory=str(config.workspace_path),)diff --git a/autogpt/agents/agent.py b/autogpt/agents/agent.pyindex f3fee609ca..93d3de8657 100644--- a/autogpt/agents/agent.py+++ b/autogpt/agents/agent.py@@ -3,7 +3,6 @@ from __future__ import annotationsimport jsonimport timefrom datetime import datetime-from pathlib import Pathfrom typing import TYPE_CHECKING, Any, Optionalif TYPE_CHECKING:@@ -37,7 +36,6 @@ class Agent(BaseAgent):command_registry: CommandRegistry,memory: VectorMemory,triggering_prompt: str,- workspace_directory: str | Path,config: Config,cycle_budget: Optional[int] = None,):@@ -52,7 +50,7 @@ class Agent(BaseAgent):self.memory = memory"""VectorMemoryProvider used to manage the agent's context (TODO)"""- self.workspace = Workspace(workspace_directory, config.restrict_to_workspace)+ self.workspace = Workspace(config.workspace_path, config.restrict_to_workspace)"""Workspace that the agent has access to, e.g. for reading/writing files."""self.created_at = datetime.now().strftime("%Y%m%d_%H%M%S")diff --git a/autogpt/app/main.py b/autogpt/app/main.pyindex a3c7d1d8f6..fa61eeaf71 100644--- a/autogpt/app/main.py+++ b/autogpt/app/main.py@@ -126,10 +126,12 @@ def run_auto_gpt(# TODO: have this directory live outside the repository (e.g. in a user's# home directory) and have it come in as a command line argument or part of# the env file.- Workspace.set_workspace_directory(config, workspace_directory)+ config.workspace_path = Workspace.set_workspace_directory(+ config, workspace_directory+ )# HACK: doing this here to collect some globals that depend on the workspace.- Workspace.build_file_logger_path(config, config.workspace_path)+ config.file_logger_path = Workspace.build_file_logger_path(config.workspace_path)config.plugins = scan_plugins(config, config.debug_mode)# Create a CommandRegistry instance and scan default folder@@ -192,7 +194,6 @@ def run_auto_gpt(memory=memory,command_registry=command_registry,triggering_prompt=DEFAULT_TRIGGERING_PROMPT,- workspace_directory=workspace_directory,ai_config=ai_config,config=config,)diff --git a/autogpt/workspace/workspace.py b/autogpt/workspace/workspace.pyindex e580d4c4c8..510d18a4f7 100644--- a/autogpt/workspace/workspace.py+++ b/autogpt/workspace/workspace.py@@ -144,21 +144,21 @@ class Workspace:return full_path@staticmethod- def build_file_logger_path(config: Config, workspace_directory: Path):+ def build_file_logger_path(workspace_directory: Path) -> str:file_logger_path = workspace_directory / "file_logger.txt"if not file_logger_path.exists():with file_logger_path.open(mode="w", encoding="utf-8") as f:f.write("File Operation Logger ")- config.file_logger_path = str(file_logger_path)+ return str(file_logger_path)@staticmethoddef set_workspace_directory(config: Config, workspace_directory: Optional[str | Path] = None- ) -> None:+ ) -> Path:if workspace_directory is None:workspace_directory = config.workdir / "auto_gpt_workspace"elif type(workspace_directory) == str:workspace_directory = Path(workspace_directory)# TODO: pass in the ai_settings file and the env file and have them cloned into# the workspace directory so we can bind them to the agent.- config.workspace_path = Workspace.make_workspace(workspace_directory)+ return Workspace.make_workspace(workspace_directory)diff --git a/docs/challenges/building_challenges.md b/docs/challenges/building_challenges.mdindex a4d0fa0827..9caf5cdd27 100644--- a/docs/challenges/building_challenges.md+++ b/docs/challenges/building_challenges.md@@ -59,7 +59,6 @@ def kubernetes_agent(config=ai_config,next_action_count=0,triggering_prompt=DEFAULT_TRIGGERING_PROMPT,- workspace_directory=workspace.root,)return agentdiff --git a/tests/conftest.py b/tests/conftest.pyindex 2becc8bf44..1efd620475 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -103,5 +103,4 @@ def agent(config: Config, workspace: Workspace) -> Agent:ai_config=ai_config,config=config,triggering_prompt=DEFAULT_TRIGGERING_PROMPT,- workspace_directory=workspace.root,)diff --git a/tests/integration/agent_factory.py b/tests/integration/agent_factory.pyindex 89e3b763db..45d195e318 100644--- a/tests/integration/agent_factory.py+++ b/tests/integration/agent_factory.py@@ -38,7 +38,6 @@ def dummy_agent(config: Config, memory_json_file, workspace: Workspace):ai_config=ai_config,config=config,triggering_prompt="dummy triggering prompt",- workspace_directory=workspace.root,)return agentdiff --git a/tests/unit/test_message_history.py b/tests/unit/test_message_history.pyindex e434f9d5d0..08a3a24bd3 100644--- a/tests/unit/test_message_history.py+++ b/tests/unit/test_message_history.py@@ -19,7 +19,6 @@ def agent(config: Config):command_registry = MagicMock()ai_config = AIConfig(ai_name="Test AI")triggering_prompt = "Triggering prompt"- workspace_directory = "workspace_directory"agent = Agent(memory=memory,@@ -27,7 +26,6 @@ def agent(config: Config):ai_config=ai_config,config=config,triggering_prompt=triggering_prompt,- workspace_directory=workspace_directory,)return agent