File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -363,7 +363,7 @@ def _validate_persistent_environment_support(self) -> None:
363363 - add_context(payload, index): Add new context for multi-turn conversations
364364 - get_context_count(): Return the number of loaded contexts
365365
366- Currently only 'local' (LocalREPL) supports these methods.
366+ Currently only 'local' (LocalREPL) and 'monty' (MontyREPL) support these methods.
367367
368368 Raises:
369369 ValueError: If the environment type does not support persistent mode.
Original file line number Diff line number Diff line change @@ -175,10 +175,6 @@ def __init__(
175175 resource_limits : pydantic_monty .ResourceLimits | None = None ,
176176 ** kwargs : Any ,
177177 ) -> None :
178- if persistent :
179- raise NotImplementedError (
180- "Persistent REPLs are currently not supported for environment: MontyREPL"
181- )
182178 super ().__init__ (persistent = persistent , depth = depth , ** kwargs )
183179
184180 self .lm_handler_address = lm_handler_address
Original file line number Diff line number Diff line change @@ -348,13 +348,29 @@ def test_local_environment_supported(self):
348348 def test_monty_environment_supported (self ):
349349 """Monty environment should support persistent mode."""
350350 pytest .importorskip ("pydantic_monty" )
351- rlm = RLM (
352- backend = "openai" ,
353- backend_kwargs = {"model_name" : "test" },
354- environment = "monty" ,
355- persistent = True ,
356- )
357- assert rlm .persistent is True
351+ responses = [
352+ "```repl\n x = 2\n print(x)\n ```\n FINAL(done)" ,
353+ "```repl\n print(x)\n ```\n FINAL(done)" ,
354+ ]
355+
356+ with patch .object (rlm_module , "get_client" ) as mock_get_client :
357+ mock_lm = create_mock_lm (responses )
358+ mock_get_client .return_value = mock_lm
359+
360+ with RLM (
361+ backend = "openai" ,
362+ backend_kwargs = {"model_name" : "test" },
363+ environment = "monty" ,
364+ persistent = True ,
365+ ) as rlm :
366+ rlm .completion ("First turn" )
367+ mock_lm .completion .side_effect = list (responses [1 :])
368+ rlm .completion ("Second turn" )
369+
370+ env = rlm ._persistent_env
371+ assert env is not None
372+ assert env .get_context_count () == 2
373+ assert "x" in env .locals
358374
359375
360376class TestMultiTurnEndToEnd :
You can’t perform that action at this time.
0 commit comments