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 AutoGPT saving and resuming
Reinier van der Leer65a7e2b2573b
diff --git a/autogpts/autogpt/autogpt/agents/base.py b/autogpts/autogpt/autogpt/agents/base.pyindex 1061ee99c2..547f7d5fde 100644--- a/autogpts/autogpt/autogpt/agents/base.py+++ b/autogpts/autogpt/autogpt/agents/base.py@@ -1,15 +1,14 @@from __future__ import annotations-import jsonimport loggingfrom abc import ABC, abstractmethod+from pathlib import Pathfrom typing import TYPE_CHECKING, Any, Optionalfrom auto_gpt_plugin_template import AutoGPTPluginTemplatefrom pydantic import Field, validatorif TYPE_CHECKING:- from pathlib import Pathfrom autogpt.config import Configfrom autogpt.core.prompting.base import PromptStrategy@@ -122,6 +121,7 @@ class BaseAgentConfiguration(SystemConfiguration):f"Model {smart_llm} does not support OpenAI Functions. ""Please disable OPENAI_FUNCTIONS or choose a suitable model.")+ return vclass BaseAgentSettings(SystemSettings):@@ -149,14 +149,11 @@ class BaseAgentSettings(SystemSettings):def save_to_json_file(self, file_path: Path) -> None:with file_path.open("w") as f:- json.dump(self.dict(), f)+ f.write(self.json())@classmethoddef load_from_json_file(cls, file_path: Path):- with file_path.open("r") as f:- agent_settings = json.load(f)-- return cls.parse_obj(agent_settings)+ return cls.parse_file(file_path)class BaseAgent(Configurable[BaseAgentSettings], ABC):diff --git a/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py b/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.pyindex 25381c0f85..30e35a404e 100644--- a/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py+++ b/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py@@ -117,9 +117,9 @@ class OneShotAgentPromptConfiguration(SystemConfiguration):########## State ##########- progress_summaries: dict[tuple[int, int], str] = Field(- default_factory=lambda: {(0, 0): ""}- )+ # progress_summaries: dict[tuple[int, int], str] = Field(+ # default_factory=lambda: {(0, 0): ""}+ # )class OneShotAgentPromptStrategy(PromptStrategy):diff --git a/autogpts/autogpt/autogpt/app/agent_protocol_server.py b/autogpts/autogpt/autogpt/app/agent_protocol_server.pyindex 4ba5d45f98..ca0cb3be81 100644--- a/autogpts/autogpt/autogpt/app/agent_protocol_server.py+++ b/autogpts/autogpt/autogpt/app/agent_protocol_server.py@@ -117,6 +117,7 @@ class AgentProtocolServer:)agent_id = task_agent.state.agent_id = task_agent_id(task.task_id)task_agent.attach_fs(self.app_config.app_data_dir / "agents" / agent_id)+ task_agent.state.save_to_json_file(task_agent.file_manager.state_file_path)return taskasync def list_tasks(self, page: int = 1, pageSize: int = 10) -> TaskListResponse:diff --git a/autogpts/autogpt/autogpt/models/action_history.py b/autogpts/autogpt/autogpt/models/action_history.pyindex 5fc52db007..fc19cf12a6 100644--- a/autogpts/autogpt/autogpt/models/action_history.py+++ b/autogpts/autogpt/autogpt/models/action_history.py@@ -2,7 +2,7 @@ from __future__ import annotationsfrom typing import Any, Iterator, Literal, Optional-from pydantic import BaseModel+from pydantic import BaseModel, Fieldfrom autogpt.prompts.utils import format_numbered_list, indent@@ -60,14 +60,8 @@ class Episode(BaseModel):class EpisodicActionHistory(BaseModel):"""Utility container for an action history"""- cursor: int- episodes: list[Episode]-- def __init__(self, episodes: list[Episode] = []):- super().__init__(- episodes=episodes,- cursor=len(episodes),- )+ episodes: list[Episode] = Field(default_factory=list)+ cursor: int = 0@propertydef current_episode(self) -> Episode | None: