Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: patch .utcnow warning (#1702)
Charles Packerff22d576ad68
diff --git a/examples/personal_assistant_demo/google_calendar_test_setup.py b/examples/personal_assistant_demo/google_calendar_test_setup.pyindex a24f2b6dd..820feaa4c 100644--- a/examples/personal_assistant_demo/google_calendar_test_setup.py+++ b/examples/personal_assistant_demo/google_calendar_test_setup.py@@ -40,7 +40,7 @@ def main():service = build("calendar", "v3", credentials=creds)# Call the Calendar API- now = datetime.datetime.utcnow().isoformat() + "Z" # 'Z' indicates UTC time+ now = datetime.datetime.now(datetime.timezone.utc).isoformat() + "Z" # 'Z' indicates UTC timeprint("Getting the upcoming 10 events")events_result = (service.events()diff --git a/letta/groups/sleeptime_multi_agent.py b/letta/groups/sleeptime_multi_agent.pyindex 336591f11..0a6546c50 100644--- a/letta/groups/sleeptime_multi_agent.py+++ b/letta/groups/sleeptime_multi_agent.py@@ -1,6 +1,6 @@import asyncioimport threading-from datetime import datetime+from datetime import datetime, timezonefrom typing import List, Optionalfrom letta.agent import Agent, AgentState@@ -154,7 +154,7 @@ class SleeptimeMultiAgent(Agent):)job_update = JobUpdate(status=JobStatus.completed,- completed_at=datetime.utcnow(),+ completed_at=datetime.now(timezone.utc),metadata={"result": result.model_dump(mode="json"),"agent_id": participant_agent.agent_state.id,@@ -165,7 +165,7 @@ class SleeptimeMultiAgent(Agent):except Exception as e:job_update = JobUpdate(status=JobStatus.failed,- completed_at=datetime.utcnow(),+ completed_at=datetime.now(timezone.utc),metadata={"error": str(e)},)self.job_manager.update_job_by_id(job_id=run_id, job_update=job_update, actor=self.user)diff --git a/letta/orm/base.py b/letta/orm/base.pyindex 7f9823995..bf24707d9 100644--- a/letta/orm/base.py+++ b/letta/orm/base.py@@ -1,4 +1,4 @@-from datetime import datetime+from datetime import datetime, timezonefrom typing import Optionalfrom sqlalchemy import Boolean, DateTime, String, func, text@@ -25,7 +25,7 @@ class CommonSqlalchemyMetaMixins(Base):timestamp (Optional[datetime]): The timestamp to set.If None, uses the current UTC time."""- self.updated_at = timestamp or datetime.utcnow()+ self.updated_at = timestamp or datetime.now(timezone.utc)def _set_created_and_updated_by_fields(self, actor_id: str) -> None:"""Populate created_by_id and last_updated_by_id based on actor."""diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.pyindex c0acdccf1..35dcd703b 100644--- a/letta/server/rest_api/routers/v1/agents.py+++ b/letta/server/rest_api/routers/v1/agents.py@@ -1,6 +1,6 @@import jsonimport traceback-from datetime import datetime+from datetime import datetime, timezonefrom typing import Annotated, Any, List, Optionalfrom fastapi import APIRouter, BackgroundTasks, Body, Depends, File, Header, HTTPException, Query, UploadFile, status@@ -729,7 +729,7 @@ async def process_message_background(# Update job status to completedjob_update = JobUpdate(status=JobStatus.completed,- completed_at=datetime.utcnow(),+ completed_at=datetime.now(timezone.utc),metadata={"result": result.model_dump(mode="json")}, # Store the result in metadata)server.job_manager.update_job_by_id(job_id=job_id, job_update=job_update, actor=actor)@@ -738,7 +738,7 @@ async def process_message_background(# Update job status to failedjob_update = JobUpdate(status=JobStatus.failed,- completed_at=datetime.utcnow(),+ completed_at=datetime.now(timezone.utc),metadata={"error": str(e)},)server.job_manager.update_job_by_id(job_id=job_id, job_update=job_update, actor=actor)diff --git a/letta/services/passage_manager.py b/letta/services/passage_manager.pyindex 8c02655bc..6dc25e1a2 100644--- a/letta/services/passage_manager.py+++ b/letta/services/passage_manager.py@@ -1,4 +1,4 @@-from datetime import datetime+from datetime import datetime, timezonefrom typing import List, Optionalfrom openai import OpenAI@@ -49,7 +49,7 @@ class PassageManager:"organization_id": data["organization_id"],"metadata_": data.get("metadata", {}),"is_deleted": data.get("is_deleted", False),- "created_at": data.get("created_at", datetime.utcnow()),+ "created_at": data.get("created_at", datetime.now(timezone.utc)),}if "agent_id" in data and data["agent_id"]:diff --git a/tests/integration_test_summarizer.py b/tests/integration_test_summarizer.pyindex 00e927332..43a51e160 100644--- a/tests/integration_test_summarizer.py+++ b/tests/integration_test_summarizer.py@@ -1,7 +1,7 @@import jsonimport osimport uuid-from datetime import datetime+from datetime import datetime, timezonefrom typing import Listimport pytest@@ -55,7 +55,7 @@ def generate_message(role: str, text: str = None, tool_calls: List = None) -> Meid="message-" + str(uuid.uuid4()),role=MessageRole(role),content=[TextContent(text=text or f"{role} message text")],- created_at=datetime.utcnow(),+ created_at=datetime.now(timezone.utc),tool_calls=tool_calls or [],)diff --git a/tests/test_llm_clients.py b/tests/test_llm_clients.pyindex b5987b15c..c33468dfc 100644--- a/tests/test_llm_clients.py+++ b/tests/test_llm_clients.py@@ -1,4 +1,4 @@-from datetime import datetime+from datetime import datetime, timezonefrom unittest.mock import AsyncMock, patchimport pytest@@ -35,10 +35,12 @@ def mock_agent_messages():return {"agent-1": [PydanticMessage(- role=MessageRole.system, content=[{"type": "text", "text": "You are a helpful assistant."}], created_at=datetime.utcnow()+ role=MessageRole.system,+ content=[{"type": "text", "text": "You are a helpful assistant."}],+ created_at=datetime.now(timezone.utc),),PydanticMessage(- role=MessageRole.user, content=[{"type": "text", "text": "What's the weather like?"}], created_at=datetime.utcnow()+ role=MessageRole.user, content=[{"type": "text", "text": "What's the weather like?"}], created_at=datetime.now(timezone.utc)),]}diff --git a/tests/test_managers.py b/tests/test_managers.pyindex 0133bad23..1734a1e92 100644--- a/tests/test_managers.py+++ b/tests/test_managers.py@@ -1768,7 +1768,7 @@ def test_agent_list_passages_filtering(server, default_user, sarah_agent, defaulassert len(source_filtered) == 3# Test date filtering- now = datetime.utcnow()+ now = datetime.now(timezone.utc)future_date = now + timedelta(days=1)past_date = now - timedelta(days=1)@@ -4302,7 +4302,7 @@ def test_job_messages_pagination(server: SyncServer, default_run, default_user,def test_job_messages_ordering(server: SyncServer, default_run, default_user, sarah_agent):"""Test that messages are ordered by created_at."""# Create messages with different timestamps- base_time = datetime.utcnow()+ base_time = datetime.now(timezone.utc)message_times = [base_time - timedelta(minutes=2),base_time - timedelta(minutes=1),diff --git a/tests/test_static_buffer_summarize.py b/tests/test_static_buffer_summarize.pyindex 9feb41370..d50c46993 100644--- a/tests/test_static_buffer_summarize.py+++ b/tests/test_static_buffer_summarize.py@@ -1,5 +1,5 @@import json-from datetime import datetime+from datetime import datetime, timezonefrom unittest.mock import AsyncMockimport pytest@@ -31,7 +31,7 @@ def messages():Message(role=MessageRole.user if i % 2 == 0 else MessageRole.assistant,content=[TextContent(type="text", text=json.dumps({"message": f"Test message {i}"}))],- created_at=datetime.utcnow(),+ created_at=datetime.now(timezone.utc),)for i in range(15)]diff --git a/tests/test_v1_routes.py b/tests/test_v1_routes.pyindex 819c0683c..d79741a27 100644--- a/tests/test_v1_routes.py+++ b/tests/test_v1_routes.py@@ -1,4 +1,4 @@-from datetime import datetime+from datetime import datetime, timezonefrom unittest.mock import MagicMock, Mockimport pytest@@ -209,7 +209,7 @@ def test_upsert_base_tools(client, mock_sync_server, add_integers_tool):def test_get_run_messages(client, mock_sync_server):"""Test getting messages for a run."""# Create properly formatted mock messages- current_time = datetime.utcnow()+ current_time = datetime.now(timezone.utc)mock_messages = [UserMessage(id=f"message-{i:08x}",diff --git a/tests/utils.py b/tests/utils.pyindex 6b27d804b..7ca72d5b5 100644--- a/tests/utils.py+++ b/tests/utils.py@@ -1,7 +1,6 @@-import datetimeimport osimport time-from datetime import datetime+from datetime import datetime, timezonefrom importlib import utilfrom typing import Dict, Iterator, List, Tuple@@ -34,7 +33,7 @@ class DummyDataConnector(DataConnector):file_size=0, # Set to 0 as a placeholderfile_creation_date="1970-01-01", # Placeholder datefile_last_modified_date="1970-01-01", # Placeholder date- created_at=datetime.utcnow(),+ created_at=datetime.now(timezone.utc),)self.file_to_text[file_metadata.id] = text