Team Ai
Apppublic

openenv/repl

sourceHugging Faceupdated 6mo agoView on Hugging Face
1likes
__init__.py95 linesDownload Raw Back to root
1# Copyright (c) Meta Platforms, Inc. and affiliates.2# All rights reserved.3#4# This source code is licensed under the BSD-style license found in the5# LICENSE file in the root directory of this source tree.6 7"""8REPL Environment for OpenEnv.9 10A Python REPL environment for training language models on code execution tasks,11based on the Recursive Language Models (RLM) paradigm.12 13This environment allows language models to:14- Execute Python code in a sandboxed REPL15- Work with large contexts loaded as variables16- Finalize answers via FINAL(), FINAL_VAR(), or answer dict pattern17- Optionally make recursive LLM calls via llm_query() / llm_query_batched()18 19Example:20    >>> from repl_env import LocalREPLEnv, REPLAction21    >>>22    >>> # Local in-process helper23    >>> env = LocalREPLEnv()24    >>>25    >>> # Reset with context26    >>> result = env.reset(context="Hello World", task_prompt="Count characters")27    >>>28    >>> # Execute code29    >>> result = env.execute("count = len(context)")30    >>> result = env.execute("print(f'FINAL({count})')")31    >>>32    >>> # Check result33    >>> print(f"Done: {result.done}, Answer: {result.observation.metadata['final_answer']}")34    >>>35    >>> env.close()36 37References:38    - RLM Paper: https://arxiv.org/abs/2512.2460139    - Prime Intellect Blog: https://www.primeintellect.ai/blog/rlm40    - Alex Zhang Blog: https://alexzhang13.github.io/blog/2025/rlm/41"""42 43from .client import REPLEnv44from .local import LocalREPLEnv45from .models import CodeBlockResult, REPLAction, REPLObservation, REPLState46from .prompts import (47    build_rlm_system_prompt,48    build_user_prompt,49    # Parsing utilities50    extract_code_blocks,51    format_observations,52    # Prompt building53    QueryMetadata,54    # System prompts55    RLM_SYSTEM_PROMPT,56    RLM_SYSTEM_PROMPT_QWEN,57)58from .rubrics import (59    CodeExecutionRubric,60    CustomMetricRubric,61    ExactMatchRubric,62    FuzzyMatchRubric,63    REPLRubric,64)65from .runner import LocalRLMRunner, RLMRunResult66 67__all__ = [68    # Models69    "REPLAction",70    "REPLObservation",71    "REPLState",72    "CodeBlockResult",73    # Client74    "REPLEnv",75    "LocalREPLEnv",76    "LocalRLMRunner",77    "RLMRunResult",78    # System prompts79    "RLM_SYSTEM_PROMPT",80    "RLM_SYSTEM_PROMPT_QWEN",81    # Prompt building82    "QueryMetadata",83    "build_rlm_system_prompt",84    "build_user_prompt",85    # Parsing utilities86    "extract_code_blocks",87    "format_observations",88    # Rubrics89    "REPLRubric",90    "ExactMatchRubric",91    "FuzzyMatchRubric",92    "CustomMetricRubric",93    "CodeExecutionRubric",94]95