mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-02-04 22:04:35 +01:00
Fix workspace crash
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -129,7 +129,7 @@ def run_auto_gpt(
|
||||
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)
|
||||
Workspace.set_file_logger_path(config, config.workspace_path)
|
||||
|
||||
config.plugins = scan_plugins(config, config.debug_mode)
|
||||
# Create a CommandRegistry instance and scan default folder
|
||||
@@ -192,7 +192,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,7 +144,7 @@ class Workspace:
|
||||
return full_path
|
||||
|
||||
@staticmethod
|
||||
def build_file_logger_path(config: Config, workspace_directory: Path):
|
||||
def set_file_logger_path(config: Config, workspace_directory: Path):
|
||||
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:
|
||||
|
||||
@@ -25,7 +25,7 @@ def bootstrap_agent(task):
|
||||
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)
|
||||
Workspace.set_file_logger_path(config, config.workspace_path)
|
||||
ai_config = AIConfig(
|
||||
ai_name="Auto-GPT",
|
||||
ai_role="a multi-purpose AI assistant.",
|
||||
@@ -38,7 +38,6 @@ def bootstrap_agent(task):
|
||||
ai_config=ai_config,
|
||||
config=config,
|
||||
triggering_prompt=DEFAULT_TRIGGERING_PROMPT,
|
||||
workspace_directory=str(config.workspace_path),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -52,6 +52,8 @@ def config(
|
||||
if not os.environ.get("OPENAI_API_KEY"):
|
||||
os.environ["OPENAI_API_KEY"] = "sk-dummy"
|
||||
|
||||
Workspace.set_workspace_directory(config, workspace.root)
|
||||
|
||||
# HACK: this is necessary to ensure PLAIN_OUTPUT takes effect
|
||||
logger.config = config
|
||||
|
||||
@@ -84,7 +86,7 @@ def api_manager() -> ApiManager:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def agent(config: Config, workspace: Workspace) -> Agent:
|
||||
def agent(config: Config) -> Agent:
|
||||
ai_config = AIConfig(
|
||||
ai_name="Base",
|
||||
ai_role="A base AI",
|
||||
@@ -103,5 +105,4 @@ def agent(config: Config, workspace: Workspace) -> Agent:
|
||||
ai_config=ai_config,
|
||||
config=config,
|
||||
triggering_prompt=DEFAULT_TRIGGERING_PROMPT,
|
||||
workspace_directory=workspace.root,
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ from autogpt.agents import Agent
|
||||
from autogpt.config import AIConfig, Config
|
||||
from autogpt.memory.vector import get_memory
|
||||
from autogpt.models.command_registry import CommandRegistry
|
||||
from autogpt.workspace import Workspace
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -20,7 +19,7 @@ def memory_json_file(config: Config):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dummy_agent(config: Config, memory_json_file, workspace: Workspace):
|
||||
def dummy_agent(config: Config, memory_json_file):
|
||||
command_registry = CommandRegistry()
|
||||
|
||||
ai_config = AIConfig(
|
||||
@@ -38,7 +37,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