mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-31 11:54:30 +01:00
Fix workspace crashing (#5041)
Signed-off-by: Merwane Hamadi <merwanehamadi@gmail.com>
This commit is contained in:
@@ -27,8 +27,8 @@ def bootstrap_agent(task, continuous_mode) -> Agent:
|
||||
config.plain_output = True
|
||||
command_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),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ from __future__ import annotations
|
||||
import json
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Optional
|
||||
|
||||
if 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")
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@staticmethod
|
||||
def 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)
|
||||
|
||||
@@ -59,7 +59,6 @@ def kubernetes_agent(
|
||||
config=ai_config,
|
||||
next_action_count=0,
|
||||
triggering_prompt=DEFAULT_TRIGGERING_PROMPT,
|
||||
workspace_directory=workspace.root,
|
||||
)
|
||||
|
||||
return agent
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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 agent
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user