101101from letta .services .block_manager import BlockManager
102102from letta .services .helpers .agent_manager_helper import calculate_base_tools , calculate_multi_agent_tools , validate_agent_exists_async
103103from letta .services .step_manager import FeedbackType
104- from letta .settings import tool_settings
104+ from letta .settings import settings , tool_settings
105105from letta .utils import calculate_file_defaults_based_on_context_window
106106from tests .helpers .utils import comprehensive_agent_checks , validate_context_window_overview
107107from tests .utils import random_string
@@ -862,7 +862,7 @@ def test_calculate_multi_agent_tools(set_letta_environment):
862862 """Test that calculate_multi_agent_tools excludes local-only tools in production."""
863863 result = calculate_multi_agent_tools ()
864864
865- if set_letta_environment == "PRODUCTION" :
865+ if settings . environment == "PRODUCTION" :
866866 # Production environment should exclude local-only tools
867867 expected_tools = set (MULTI_AGENT_TOOLS ) - set (LOCAL_ONLY_MULTI_AGENT_TOOLS )
868868 assert result == expected_tools , "Production should exclude local-only multi-agent tools"
@@ -889,7 +889,7 @@ async def test_upsert_base_tools_excludes_local_only_in_production(server: SyncS
889889 tools = await server .tool_manager .upsert_base_tools_async (actor = default_user )
890890 tool_names = {tool .name for tool in tools }
891891
892- if set_letta_environment == "PRODUCTION" :
892+ if settings . environment == "PRODUCTION" :
893893 # Production environment should exclude local-only multi-agent tools
894894 for local_only_tool in LOCAL_ONLY_MULTI_AGENT_TOOLS :
895895 assert local_only_tool not in tool_names , f"Local-only tool '{ local_only_tool } ' should not be upserted in production"
@@ -912,7 +912,7 @@ async def test_upsert_multi_agent_tools_only(server: SyncServer, default_user, s
912912 tools = await server .tool_manager .upsert_base_tools_async (actor = default_user , allowed_types = {ToolType .LETTA_MULTI_AGENT_CORE })
913913 tool_names = {tool .name for tool in tools }
914914
915- if set_letta_environment == "PRODUCTION" :
915+ if settings . environment == "PRODUCTION" :
916916 # Should only have non-local multi-agent tools
917917 expected_tools = set (MULTI_AGENT_TOOLS ) - set (LOCAL_ONLY_MULTI_AGENT_TOOLS )
918918 assert tool_names == expected_tools , "Production multi-agent upsert should exclude local-only tools"
@@ -991,16 +991,14 @@ async def test_create_agent_with_default_source(server: SyncServer, default_user
991991 server .agent_manager .delete_agent (created_agent_no_source .id , default_user )
992992
993993
994- @pytest .fixture (params = ["" , "PRODUCTION" ])
995- def set_letta_environment (request ):
996- original = os .environ .get ("LETTA_ENVIRONMENT" )
997- os .environ ["LETTA_ENVIRONMENT" ] = request .param
994+ @pytest .fixture (params = [None , "PRODUCTION" ])
995+ def set_letta_environment (request , monkeypatch ):
996+ # Patch the settings.environment attribute
997+ original = settings .environment
998+ monkeypatch .setattr (settings , "environment" , request .param )
998999 yield request .param
999- # Restore original environment variable
1000- if original is not None :
1001- os .environ ["LETTA_ENVIRONMENT" ] = original
1002- else :
1003- os .environ .pop ("LETTA_ENVIRONMENT" , None )
1000+ # Restore original environment
1001+ monkeypatch .setattr (settings , "environment" , original )
10041002
10051003
10061004async def test_get_context_window_basic (
@@ -3801,7 +3799,7 @@ async def test_upsert_base_tools(server: SyncServer, default_user):
38013799 tools = await server .tool_manager .upsert_base_tools_async (actor = default_user )
38023800
38033801 # Calculate expected tools accounting for production filtering
3804- if os . getenv ( "LETTA_ENVIRONMENT" ) == "PRODUCTION" :
3802+ if settings . environment == "PRODUCTION" :
38053803 expected_tool_names = sorted (LETTA_TOOL_SET - set (LOCAL_ONLY_MULTI_AGENT_TOOLS ))
38063804 else :
38073805 expected_tool_names = sorted (LETTA_TOOL_SET )
@@ -3853,7 +3851,7 @@ async def test_upsert_filtered_base_tools(server: SyncServer, default_user, tool
38533851 tool_names = sorted ([t .name for t in tools ])
38543852
38553853 # Adjust expected names for multi-agent tools in production
3856- if tool_type == ToolType .LETTA_MULTI_AGENT_CORE and os . getenv ( "LETTA_ENVIRONMENT" ) == "PRODUCTION" :
3854+ if tool_type == ToolType .LETTA_MULTI_AGENT_CORE and settings . environment == "PRODUCTION" :
38573855 expected_sorted = sorted (set (expected_names ) - set (LOCAL_ONLY_MULTI_AGENT_TOOLS ))
38583856 else :
38593857 expected_sorted = sorted (expected_names )
0 commit comments