A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
preserve the RLM namespace after importing the package
Sebastian Müller9083398b3a13
diff --git a/.changes/rlm-import-surface.md b/.changes/rlm-import-surface.mdnew file mode 100644index 0000000000..c516048162--- /dev/null+++ b/.changes/rlm-import-surface.md@@ -0,0 +1 @@+- Kernel: `rlm.factory.run(...)`, `rlm.factory.help()`, and every other `rlm` namespace call keep working after a cell runs `import rlm`, and `dir(rlm.harness)` now lists the harness methods.diff --git a/prime-agent-runtime/src/rlm/__init__.py b/prime-agent-runtime/src/rlm/__init__.pyindex 4a40f277e4..82f1da339b 100644--- a/prime-agent-runtime/src/rlm/__init__.py+++ b/prime-agent-runtime/src/rlm/__init__.py@@ -559,6 +559,9 @@ class _HarnessProxy:def __getattr__(self, name: str) -> Any:return getattr(self._resolve(), name)+ def __dir__(self) -> list[str]:+ return sorted({*super().__dir__(), *(name for name in dir(self._resolve()) if not name.startswith("_"))})+def __repr__(self) -> str:return repr(self._resolve())@@ -689,6 +692,7 @@ class _RLMNamespace:rlm = _RLMNamespace()harness = _harness_state+factory = rlm.factoryclass _NotCallableModule(types.ModuleType):@@ -740,6 +744,4 @@ def __getattr__(name: str) -> Any: # noqa: D401 - module-level lazy attr hookfrom . import mcp_basereturn getattr(mcp_base, name)- if name == "run":- raise AttributeError(_RENAMED_RUN_MESSAGE)- raise AttributeError(f"module {__name__!r} has no attribute {name!r}")+ return getattr(rlm, name)diff --git a/prime-agent-runtime/src/rlm/repl.py b/prime-agent-runtime/src/rlm/repl.pyindex 7af6d3dcc6..8dbc102dc0 100644--- a/prime-agent-runtime/src/rlm/repl.py+++ b/prime-agent-runtime/src/rlm/repl.py@@ -32,7 +32,7 @@ import uuidfrom collections.abc import Awaitable, Callablefrom typing import Any-from . import factory as factory_module+from .factory import schedule_activityfrom .bash import _kill_live_handles, _rehydrate_persistent_shellsPROTOCOL_VERSION = 3@@ -1582,7 +1582,7 @@ def _handle_request_line(raw: bytes, queue: asyncio.Queue[dict[str, Any]]) -> No# Like bash_activity, this bypasses the cell FIFO: the factory view# must answer while a cell runs. The handler schedules the async# activity on this loop and replies when it settles.- _loop.call_soon_threadsafe(factory_module.schedule_activity, req)+ _loop.call_soon_threadsafe(schedule_activity, req)returnif rtype in ("execute", "snapshot", "restore"):with _interrupt_lock:diff --git a/prime-agent-runtime/test/test_factory.py b/prime-agent-runtime/test/test_factory.pyindex 65894467d2..d05fcf755a 100644--- a/prime-agent-runtime/test/test_factory.py+++ b/prime-agent-runtime/test/test_factory.py@@ -50,6 +50,7 @@ from __future__ import annotationsimport asyncioimport hashlib+import importlibimport jsonimport osimport re@@ -63,7 +64,6 @@ from typing import Anyfrom unittest.mock import patchimport rlm as rlm_module-from rlm import factory as factory_modulefrom rlm.factory import (ANSWER_BINDING_CAP,ANSWER_CAPTURE_CAP,@@ -104,6 +104,8 @@ from rlm.factory import ()from rlm.harness import HarnessState+factory_module = importlib.import_module("rlm.factory")+# ---------------------------------------------------------------------------# Spec fixtures@@ -8953,6 +8955,7 @@ class FactoryRunFromLibraryTest(unittest.TestCase):_INSTALLED_LIBRARY_RUNNER = r"""import asyncio+import importlibimport json@@ -9013,9 +9016,10 @@ class ScriptedHost:async def main():import rlm as rlm_module- import rlm.factory as factory_modulefrom rlm.factory import FactoryExecutor+ factory_module = importlib.import_module("rlm.factory")+rlm_module.host_request = ScriptedHost()async def instant_sleep(_seconds):diff --git a/prime-agent-runtime/test/test_harness.py b/prime-agent-runtime/test/test_harness.pyindex c2694edfd4..0aae510ca9 100644--- a/prime-agent-runtime/test/test_harness.py+++ b/prime-agent-runtime/test/test_harness.py@@ -1342,6 +1342,9 @@ class HarnessStateTest(unittest.TestCase):reloaded = HarnessState(Path(temp_dir) / "harness_state.json")self.assertEqual(reloaded.get("memory", "session_note").content, "persisted")+ def test_dir_of_module_harness_lists_state_methods(self) -> None:+ self.assertIn("delete_factory", dir(package_harness))+def test_module_harness_without_env_raises_on_local_writes_and_reads_work(self) -> None:previous_local = os.environ.get("RLM_HARNESS_STATE_DIR")previous_session = os.environ.get("RLM_SESSION_DIR")@@ -1689,7 +1692,9 @@ class HarnessRefinementsSettingTests(unittest.TestCase):def test_disabled_refinements_refuse_factory_runs_before_launch(self):import asyncio- from rlm import factory+ import importlib++ factory = importlib.import_module("rlm.factory")with tempfile.TemporaryDirectory() as tmp, patch.dict(os.environ, {"PRIME_AGENT_CODING_AGENT_DIR": tmp}):settings = Path(tmp) / "settings.json"diff --git a/prime-agent-runtime/test/test_subagent_registry.py b/prime-agent-runtime/test/test_subagent_registry.pyindex cd399a0d97..01561c6a4e 100644--- a/prime-agent-runtime/test/test_subagent_registry.py+++ b/prime-agent-runtime/test/test_subagent_registry.py@@ -2,6 +2,7 @@ from __future__ import annotationsimport asyncioimport importlib+import inspectimport unittestfrom pathlib import Pathfrom unittest.mock import AsyncMock, patch@@ -110,6 +111,14 @@ class RlmSubagentRegistryTest(unittest.TestCase):target.runself.assertFalse(hasattr(target, "run"))+ def test_package_module_resolves_namespace_attributes(self) -> None:+ self.assertIs(rlm_module.factory, rlm_module.rlm.factory)+ self.assertTrue(inspect.iscoroutinefunction(rlm_module.factory.run))+ self.assertEqual(rlm_module.factory.help(), importlib.import_module("rlm.factory").FACTORY_HELP)+ session = object()+ with patch.object(type(rlm_module.rlm), "session", session, create=True):+ self.assertIs(rlm_module.session, session)+def test_finds_authenticated_models_through_host(self) -> None:host_request = AsyncMock(return_value={