Skip to content

Commit bd730e5

Browse files
committed
Resolve Monty persistence review notes
1 parent d8c40d1 commit bd730e5

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

‎rlm/core/rlm.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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.

‎rlm/environments/monty_repl.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff 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

‎tests/test_multi_turn_integration.py‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff 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\nx = 2\nprint(x)\n```\nFINAL(done)",
353+
"```repl\nprint(x)\n```\nFINAL(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

360376
class TestMultiTurnEndToEnd:

0 commit comments

Comments
 (0)