diff --git a/autogpts/autogpt/autogpt/agents/base.py b/autogpts/autogpt/autogpt/agents/base.py index 1061ee99..547f7d5f 100644 --- a/autogpts/autogpt/autogpt/agents/base.py +++ b/autogpts/autogpt/autogpt/agents/base.py @@ -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): diff --git a/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py b/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py index 25381c0f..30e35a40 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.py index 4ba5d45f..ca0cb3be 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 task async 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.py index 5fc52db0..fc19cf12 100644 --- a/autogpts/autogpt/autogpt/models/action_history.py +++ b/autogpts/autogpt/autogpt/models/action_history.py @@ -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: