Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: additions to utc patch (#1176) (#1177)
Charles Packer542d78c10243
diff --git a/memgpt/functions/function_sets/base.py b/memgpt/functions/function_sets/base.pyindex 72037b01c..99e3ac426 100644--- a/memgpt/functions/function_sets/base.py+++ b/memgpt/functions/function_sets/base.py@@ -42,7 +42,7 @@ def pause_heartbeats(self: Agent, minutes: int) -> Optional[str]:minutes = min(MAX_PAUSE_HEARTBEATS, minutes)# Record the current time- self.pause_heartbeats_start = datetime.datetime.now(datetime.UTC)+ self.pause_heartbeats_start = datetime.datetime.now(datetime.timezone.utc)# And record how long the pause should go forself.pause_heartbeats_minutes = int(minutes)diff --git a/memgpt/models/pydantic_models.py b/memgpt/models/pydantic_models.pyindex bb582b7ce..4b3956bca 100644--- a/memgpt/models/pydantic_models.py+++ b/memgpt/models/pydantic_models.py@@ -8,7 +8,7 @@ from sqlmodel import Field, SQLModelfrom sqlalchemy import JSON, Column, BINARY, TypeDecoratorfrom memgpt.constants import DEFAULT_HUMAN, DEFAULT_MEMGPT_MODEL, DEFAULT_PERSONA, DEFAULT_PRESET, LLM_MAX_TOKENS, MAX_EMBEDDING_DIM-from memgpt.utils import get_human_text, get_persona_text, printd+from memgpt.utils import get_human_text, get_persona_text, printd, get_utc_timeclass LLMConfigModel(BaseModel):@@ -35,7 +35,7 @@ class PresetModel(BaseModel):id: uuid.UUID = Field(default_factory=uuid.uuid4, description="The unique identifier of the preset.")user_id: Optional[uuid.UUID] = Field(None, description="The unique identifier of the user who created the preset.")description: Optional[str] = Field(None, description="The description of the preset.")- created_at: datetime = Field(default_factory=datetime.now, description="The unix timestamp of when the preset was created.")+ created_at: datetime = Field(default_factory=get_utc_time, description="The unix timestamp of when the preset was created.")system: str = Field(..., description="The system prompt of the preset.")persona: str = Field(default=get_persona_text(DEFAULT_PERSONA), description="The persona of the preset.")persona_name: Optional[str] = Field(None, description="The name of the persona of the preset.")@@ -60,7 +60,7 @@ class AgentStateModel(BaseModel):user_id: uuid.UUID = Field(..., description="The unique identifier of the user associated with the agent.")# timestamps- # created_at: datetime = Field(default_factory=datetime.now, description="The unix timestamp of when the agent was created.")+ # created_at: datetime = Field(default_factory=get_utc_time, description="The unix timestamp of when the agent was created.")created_at: int = Field(..., description="The unix timestamp of when the agent was created.")# preset information@@ -100,7 +100,7 @@ class SourceModel(SQLModel, table=True):name: str = Field(..., description="The name of the source.")description: Optional[str] = Field(None, description="The description of the source.")user_id: uuid.UUID = Field(..., description="The unique identifier of the user associated with the source.")- created_at: datetime = Field(default_factory=datetime.now, description="The unix timestamp of when the source was created.")+ created_at: datetime = Field(default_factory=get_utc_time, description="The unix timestamp of when the source was created.")id: uuid.UUID = Field(default_factory=uuid.uuid4, description="The unique identifier of the source.", primary_key=True)# embedding info# embedding_config: EmbeddingConfigModel = Field(..., description="The embedding configuration used by the source.")diff --git a/memgpt/server/rest_api/presets/index.py b/memgpt/server/rest_api/presets/index.pyindex b5c005549..3a573003f 100644--- a/memgpt/server/rest_api/presets/index.py+++ b/memgpt/server/rest_api/presets/index.py@@ -35,7 +35,7 @@ class CreatePresetsRequest(BaseModel):id: Optional[Union[uuid.UUID, str]] = Field(default_factory=uuid.uuid4, description="The unique identifier of the preset.")# user_id: uuid.UUID = Field(..., description="The unique identifier of the user who created the preset.")description: Optional[str] = Field(None, description="The description of the preset.")- # created_at: datetime = Field(default_factory=datetime.now, description="The unix timestamp of when the preset was created.")+ # created_at: datetime = Field(default_factory=get_utc_time, description="The unix timestamp of when the preset was created.")system: str = Field(..., description="The system prompt of the preset.")persona: str = Field(default=get_persona_text(DEFAULT_PERSONA), description="The persona of the preset.")human: str = Field(default=get_human_text(DEFAULT_HUMAN), description="The human of the preset.")diff --git a/memgpt/utils.py b/memgpt/utils.pyindex 2ca89e9d7..d4c9aa00a 100644--- a/memgpt/utils.py+++ b/memgpt/utils.py@@ -1,4 +1,4 @@-from datetime import datetime, UTC+from datetime import datetime, timezoneimport copyimport reimport json@@ -841,7 +841,7 @@ def get_local_time(timezone=None):def get_utc_time() -> datetime:"""Get the current UTC time"""# return datetime.now(pytz.utc)- return datetime.now(UTC)+ return datetime.now(timezone.utc)def format_datetime(dt):diff --git a/tests/utils.py b/tests/utils.pyindex 00088acd4..413f72b29 100644--- a/tests/utils.py+++ b/tests/utils.py@@ -53,7 +53,7 @@ def wipe_memgpt_home():"""Wipes ~/.memgpt (moves to a backup), and initializes a new ~/.memgpt dir"""# Get the current timestamp in a readable format (e.g., YYYYMMDD_HHMMSS)- timestamp = datetime.datetime.now(datetime.UTC).strftime("%Y%m%d_%H%M%S")+ timestamp = datetime.datetime.now(datetime.timezone.utc).strftime("%Y%m%d_%H%M%S")# Construct the new backup directory name with the timestampbackup_dir = f"~/.memgpt_test_backup_{timestamp}"