mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-09 09:14:19 +01:00
Fix AutoGPT saving and resuming
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Optional
|
||||
|
||||
from auto_gpt_plugin_template import AutoGPTPluginTemplate
|
||||
from pydantic import Field, validator
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
from autogpt.config import Config
|
||||
from 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 v
|
||||
|
||||
|
||||
class 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())
|
||||
|
||||
@classmethod
|
||||
def 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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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 task
|
||||
|
||||
async def list_tasks(self, page: int = 1, pageSize: int = 10) -> TaskListResponse:
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Iterator, Literal, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from 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
|
||||
|
||||
@property
|
||||
def current_episode(self) -> Episode | None:
|
||||
|
||||
Reference in New Issue
Block a user