Skip to content

Commit a5e8e28

Browse files
authored
Merge pull request #152 from alexzhang13/ipython_repl
Add iPython REPL environment support
2 parents 95bff82 + 228ea1d commit a5e8e28

7 files changed

Lines changed: 3098 additions & 8 deletions

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ modal = ["modal>=0.73.0", "dill>=0.3.7"]
3939
e2b = ["e2b-code-interpreter>=0.0.11", "dill>=0.3.7"]
4040
daytona = ["daytona>=0.128.1", "dill>=0.3.7"]
4141
prime = ["prime-sandboxes>=0.2.0", "dill>=0.3.7"]
42+
ipython = ["ipython>=8.0.0", "jupyter_client>=8.0.0", "ipykernel>=6.0.0", "dill>=0.3.7"]
4243

4344
[build-system]
4445
requires = ["setuptools>=61.0"]

‎rlm/core/rlm.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ def _spawn_completion_context(self, prompt: str | dict[str, Any]):
232232
env_kwargs["lm_handler_address"] = (lm_handler.host, lm_handler.port)
233233
env_kwargs["context_payload"] = prompt
234234
env_kwargs["depth"] = self.depth + 1 # Environment depth is RLM depth + 1
235-
# For local environment with max_depth > 1, pass subcall callback for recursive RLM calls
236-
if self.environment_type == "local" and self.max_depth > 1:
235+
# For local/ipython environments with max_depth > 1, pass subcall callback for recursive RLM calls
236+
if self.environment_type in ("local", "ipython") and self.max_depth > 1:
237237
env_kwargs["subcall_fn"] = self._subcall
238238
# Pass custom tools to the environment
239239
if self.custom_tools is not None:
@@ -828,7 +828,7 @@ def _validate_persistent_environment_support(self) -> None:
828828
ValueError: If the environment type does not support persistent mode.
829829
"""
830830
# Known environments that support persistence
831-
persistent_supported_environments = {"local"}
831+
persistent_supported_environments = {"local", "ipython"}
832832

833833
if self.environment_type not in persistent_supported_environments:
834834
raise ValueError(

‎rlm/core/types.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"azure_openai",
1313
"gemini",
1414
]
15-
EnvironmentType = Literal["local", "docker", "modal", "prime", "daytona", "e2b"]
15+
EnvironmentType = Literal["local", "ipython", "docker", "modal", "prime", "daytona", "e2b"]
1616

1717

1818
def _serialize_value(value: Any) -> Any:

‎rlm/environments/__init__.py‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,20 @@
1414
)
1515
from rlm.environments.local_repl import LocalREPL
1616

17+
18+
def __getattr__(name: str) -> Any:
19+
# Lazy-load environments with optional dependencies so that the package
20+
# imports cleanly even when those extras aren't installed.
21+
if name == "IPythonREPL":
22+
from rlm.environments.ipython_repl import IPythonREPL
23+
24+
return IPythonREPL
25+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
26+
27+
1728
__all__ = [
1829
"BaseEnv",
30+
"IPythonREPL",
1931
"LocalREPL",
2032
"RESERVED_TOOL_NAMES",
2133
"SupportsCustomTools",
@@ -31,15 +43,19 @@
3143

3244

3345
def get_environment(
34-
environment: Literal["local", "modal", "docker", "daytona", "prime", "e2b"],
46+
environment: Literal["local", "ipython", "modal", "docker", "daytona", "prime", "e2b"],
3547
environment_kwargs: dict[str, Any],
3648
) -> BaseEnv:
3749
"""
3850
Routes a specific environment and the args (as a dict) to the appropriate environment if supported.
39-
Currently supported environments: ['local', 'modal', 'docker', 'daytona', 'prime', 'e2b']
51+
Currently supported environments: ['local', 'ipython', 'modal', 'docker', 'daytona', 'prime', 'e2b']
4052
"""
4153
if environment == "local":
4254
return LocalREPL(**environment_kwargs)
55+
elif environment == "ipython":
56+
from rlm.environments.ipython_repl import IPythonREPL
57+
58+
return IPythonREPL(**environment_kwargs)
4359
elif environment == "modal":
4460
from rlm.environments.modal_repl import ModalREPL
4561

@@ -62,5 +78,5 @@ def get_environment(
6278
return E2BREPL(**environment_kwargs)
6379
else:
6480
raise ValueError(
65-
f"Unknown environment: {environment}. Supported: ['local', 'modal', 'docker', 'daytona', 'prime', 'e2b']"
81+
f"Unknown environment: {environment}. Supported: ['local', 'ipython', 'modal', 'docker', 'daytona', 'prime', 'e2b']"
6682
)

0 commit comments

Comments
 (0)