repl / __init__.py
sergiopaniego's picture
Upload folder using huggingface_hub
dd3b168 verified
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
"""
REPL Environment for OpenEnv.
A Python REPL environment for training language models on code execution tasks,
based on the Recursive Language Models (RLM) paradigm.
This environment allows language models to:
- Execute Python code in a sandboxed REPL
- Work with large contexts loaded as variables
- Finalize answers via FINAL(), FINAL_VAR(), or answer dict pattern
- Optionally make recursive LLM calls via llm_query() / llm_batch()
Example:
>>> from repl_env import REPLEnv, REPLAction
>>>
>>> # Start from Docker
>>> env = REPLEnv.from_docker_image("repl-env:latest")
>>>
>>> # Reset with context
>>> result = env.reset(context="Hello World", task_prompt="Count characters")
>>>
>>> # Execute code
>>> result = env.execute("count = len(context)")
>>> result = env.execute("print(f'FINAL({count})')")
>>>
>>> # Check result
>>> print(f"Done: {result.done}, Answer: {result.observation.metadata['final_answer']}")
>>>
>>> env.close()
References:
- RLM Paper: https://arxiv.org/abs/2512.24601
- Prime Intellect Blog: https://www.primeintellect.ai/blog/rlm
- Alex Zhang Blog: https://alexzhang13.github.io/blog/2025/rlm/
"""
from .models import REPLAction, REPLObservation, REPLState, CodeBlockResult
from .client import REPLEnv
from .prompts import (
RLM_SYSTEM_PROMPT,
build_initial_prompt,
build_messages,
extract_code_blocks,
format_observation,
)
__all__ = [
# Models
"REPLAction",
"REPLObservation",
"REPLState",
"CodeBlockResult",
# Client
"REPLEnv",
# Prompts
"RLM_SYSTEM_PROMPT",
"build_initial_prompt",
"build_messages",
# Parsing utilities
"extract_code_blocks",
"format_observation",
]