Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions rlm/environments/local_repl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import copy
import io
import json
import os
import shutil
import sys
Expand Down Expand Up @@ -250,22 +249,16 @@ def add_context(

var_name = f"context_{context_index}"

# Store context directly in locals (with isolation for mutable types)
if isinstance(context_payload, str):
context_path = os.path.join(self.temp_dir, f"context_{context_index}.txt")
with open(context_path, "w") as f:
f.write(context_payload)
self.execute_code(f"with open(r'{context_path}', 'r') as f:\n {var_name} = f.read()")
self.locals[var_name] = context_payload
else:
context_path = os.path.join(self.temp_dir, f"context_{context_index}.json")
with open(context_path, "w") as f:
json.dump(context_payload, f)
self.execute_code(
f"import json\nwith open(r'{context_path}', 'r') as f:\n {var_name} = json.load(f)"
)
# Dicts/lists - deep copy for isolation as per SupportsPersistence protocol
self.locals[var_name] = copy.deepcopy(context_payload)

# Alias context_0 as 'context' for backward compatibility
if context_index == 0:
self.execute_code(f"context = {var_name}")
self.locals["context"] = self.locals[var_name]

self._context_count = max(self._context_count, context_index + 1)
return context_index
Expand Down
Loading