From 462d37813e63449d0accfea115c6f119d8b50f18 Mon Sep 17 00:00:00 2001 From: Matthew Zhou Date: Wed, 24 Sep 2025 12:46:47 -0700 Subject: [PATCH] chore: Deprecate agent file v1 related things [LET-4500] (#4902) Deprecate agent file v1 related things --- .github/workflows/core-unit-sqlite-test.yaml | 1 - .github/workflows/core-unit-test.yml | 1 - letta/server/rest_api/routers/v1/agents.py | 12 +++------ tests/test_agent_serialization.py | 26 ++++++++++++++------ tests/test_agent_serialization_v2.py | 14 ++++------- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/.github/workflows/core-unit-sqlite-test.yaml b/.github/workflows/core-unit-sqlite-test.yaml index 105b24df..b64e6d5a 100644 --- a/.github/workflows/core-unit-sqlite-test.yaml +++ b/.github/workflows/core-unit-sqlite-test.yaml @@ -42,7 +42,6 @@ jobs: {"test_suite": "test_memory.py"}, {"test_suite": "test_utils.py"}, {"test_suite": "test_stream_buffer_readers.py"}, - {"test_suite": "test_agent_serialization.py"}, {"test_suite": "test_optimistic_json_parser.py"}, {"test_suite": "test_llm_clients.py"}, {"test_suite": "test_letta_agent_batch.py"}, diff --git a/.github/workflows/core-unit-test.yml b/.github/workflows/core-unit-test.yml index 15f58eda..c55a6981 100644 --- a/.github/workflows/core-unit-test.yml +++ b/.github/workflows/core-unit-test.yml @@ -43,7 +43,6 @@ jobs: {"test_suite": "test_memory.py"}, {"test_suite": "test_utils.py"}, {"test_suite": "test_stream_buffer_readers.py"}, - {"test_suite": "test_agent_serialization.py"}, {"test_suite": "test_agent_serialization_v2.py"}, {"test_suite": "test_optimistic_json_parser.py"}, {"test_suite": "test_llm_clients.py"}, diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py index a5ac046e..0c5e8d46 100644 --- a/letta/server/rest_api/routers/v1/agents.py +++ b/letta/server/rest_api/routers/v1/agents.py @@ -386,15 +386,9 @@ async def import_agent( ) else: # This is a legacy AgentSchema - agent_ids = import_agent_legacy( - agent_json=agent_json, - server=server, - actor=actor, - append_copy_suffix=append_copy_suffix, - override_existing_tools=override_existing_tools, - project_id=project_id, - strip_messages=strip_messages, - env_vars=env_vars, + raise HTTPException( + status_code=400, + detail="Legacy AgentSchema format is deprecated. Please use the new AgentFileSchema format with 'agents' field.", ) return ImportedAgentsResponse(agent_ids=agent_ids) diff --git a/tests/test_agent_serialization.py b/tests/test_agent_serialization.py index e5d5b78c..ca41ac78 100644 --- a/tests/test_agent_serialization.py +++ b/tests/test_agent_serialization.py @@ -1,3 +1,4 @@ +import asyncio import difflib import json import os @@ -72,12 +73,15 @@ def server_url() -> str: def _clear_tables(): - from letta.server.db import db_context + from letta.server.db import db_registry - with db_context() as session: - for table in reversed(Base.metadata.sorted_tables): # Reverse to avoid FK issues - session.execute(table.delete()) # Truncate table - session.commit() + async def _clear(): + async with db_registry.async_session() as session: + for table in reversed(Base.metadata.sorted_tables): # Reverse to avoid FK issues + await session.execute(table.delete()) # Truncate table + await session.commit() + + asyncio.run(_clear()) @pytest.fixture(autouse=True) @@ -112,14 +116,22 @@ def default_user(server: SyncServer, default_organization): @pytest.fixture def other_organization(server: SyncServer): """Fixture to create and return the default organization.""" - org = server.organization_manager.create_organization(pydantic_org=Organization(name="letta")) + + async def create_org(): + return await server.organization_manager.create_organization_async(pydantic_org=Organization(name="letta")) + + org = asyncio.run(create_org()) yield org @pytest.fixture def other_user(server: SyncServer, other_organization): """Fixture to create and return the default user within the default organization.""" - user = server.user_manager.create_user(pydantic_user=User(organization_id=other_organization.id, name="sarah")) + + async def create_user(): + return await server.user_manager.create_actor_async(pydantic_user=User(organization_id=other_organization.id, name="sarah")) + + user = asyncio.run(create_user()) yield user diff --git a/tests/test_agent_serialization_v2.py b/tests/test_agent_serialization_v2.py index 1785e3e3..11396981 100644 --- a/tests/test_agent_serialization_v2.py +++ b/tests/test_agent_serialization_v2.py @@ -1487,18 +1487,14 @@ class TestAgentFileEdgeCases: actor=default_user, ) - # Add many messages - for i in range(10): + num_messages = 5 + + for i in range(num_messages): await send_message_to_agent(server, agent_state, default_user, [MessageCreate(role=MessageRole.user, content=f"Message {i}")]) - # Export agent_file = await agent_serialization_manager.export([agent_state.id], default_user) - - # Verify large file exported_agent = agent_file.agents[0] - assert len(exported_agent.messages) >= 10 - - # Import + assert len(exported_agent.messages) >= num_messages result = await agent_serialization_manager.import_file(agent_file, other_user) # Verify all messages imported correctly @@ -1506,7 +1502,7 @@ class TestAgentFileEdgeCases: imported_agent_id = next(db_id for file_id, db_id in result.id_mappings.items() if file_id == "agent-0") imported_messages = await server.message_manager.list_messages_for_agent_async(imported_agent_id, other_user) - assert len(imported_messages) >= 10 + assert len(imported_messages) >= num_messages class TestAgentFileValidation: