Buckets:

download
raw
60 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;REPL Environment for OpenEnv&quot;,&quot;local&quot;:&quot;repl-environment-for-openenv&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Quick Start&quot;,&quot;local&quot;:&quot;quick-start&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;In Process&quot;,&quot;local&quot;:&quot;in-process&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Server Configuration&quot;,&quot;local&quot;:&quot;server-configuration&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Reward&quot;,&quot;local&quot;:&quot;reward&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Running an RLM Locally&quot;,&quot;local&quot;:&quot;running-an-rlm-locally&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Different Models for Outer and Inner Loops&quot;,&quot;local&quot;:&quot;different-models-for-outer-and-inner-loops&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Actions and Observations&quot;,&quot;local&quot;:&quot;actions-and-observations&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;REPL Helpers&quot;,&quot;local&quot;:&quot;repl-helpers&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Finalization Patterns&quot;,&quot;local&quot;:&quot;finalization-patterns&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;FINAL(...)&quot;,&quot;local&quot;:&quot;final&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;FINAL_VAR(...)&quot;,&quot;local&quot;:&quot;finalvar&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;answer dict&quot;,&quot;local&quot;:&quot;answer-dict&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Prompts and Examples&quot;,&quot;local&quot;:&quot;prompts-and-examples&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;References&quot;,&quot;local&quot;:&quot;references&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/>
<link href="/docs/openenv/main/en/_app/immutable/entry/start.D7897gYC.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/CIuctm9a.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/CkB8YxkR.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/entry/app.DEcMydco.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/DSBQ3IWM.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/Cs50_Xpk.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/BJRjUCyW.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/nodes/0.r69jlE9K.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/nodes/8.B1z7-4ry.js" rel="modulepreload">
<link href="/docs/openenv/main/en/_app/immutable/chunks/D52I3jXE.js" rel="modulepreload">
<!--1ou6tal--><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;REPL Environment for OpenEnv&quot;,&quot;local&quot;:&quot;repl-environment-for-openenv&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Quick Start&quot;,&quot;local&quot;:&quot;quick-start&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;In Process&quot;,&quot;local&quot;:&quot;in-process&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Server Configuration&quot;,&quot;local&quot;:&quot;server-configuration&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Reward&quot;,&quot;local&quot;:&quot;reward&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Running an RLM Locally&quot;,&quot;local&quot;:&quot;running-an-rlm-locally&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Different Models for Outer and Inner Loops&quot;,&quot;local&quot;:&quot;different-models-for-outer-and-inner-loops&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Actions and Observations&quot;,&quot;local&quot;:&quot;actions-and-observations&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;REPL Helpers&quot;,&quot;local&quot;:&quot;repl-helpers&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Finalization Patterns&quot;,&quot;local&quot;:&quot;finalization-patterns&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;FINAL(...)&quot;,&quot;local&quot;:&quot;final&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;FINAL_VAR(...)&quot;,&quot;local&quot;:&quot;finalvar&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;answer dict&quot;,&quot;local&quot;:&quot;answer-dict&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Prompts and Examples&quot;,&quot;local&quot;:&quot;prompts-and-examples&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;References&quot;,&quot;local&quot;:&quot;references&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/><!---->
<link href="/docs/openenv/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="repl-environment-for-openenv" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#repl-environment-for-openenv"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>REPL Environment for OpenEnv</span></h1><!--]--><!----> <p><code>repl_env</code> is a Python REPL environment for <a href="https://huggingface.co/papers/2512.24601" rel="nofollow">Recursive Language Model</a> (RLM) style execution. The model writes code that runs in a persistent namespace and can:</p> <ul><li>inspect <code>context</code></li> <li>execute Python across multiple turns with persistent state</li> <li>call <code>llm_query(...)</code> and <code>llm_query_batched(...)</code> to query a language model</li> <li>call <code>rlm_query(...)</code> and <code>rlm_query_batched(...)</code> for recursive child runs, when configured</li> <li>finish with <code>FINAL(...)</code>, <code>FINAL_VAR(...)</code>, or <code>answer = {"content": ..., "ready": True}</code></li></ul> <p>The package provides:</p> <ul><li><code>REPLEnv</code>: the async client for a remote server (<code>.sync()</code> for synchronous code), with <code>execute(code)</code>, <code>submit_final_answer(answer)</code>, <code>get_variable(name)</code> and <code>list_variables()</code> on top of <code>reset()</code>/<code>step()</code></li> <li><code>LocalREPLEnv</code>: the same environment, in process</li> <li><code>LocalRLMRunner</code>: a local RLM loop that prompts a model, runs its code and handles recursion</li></ul> <!--[1--><h2 class="relative group"><a id="quick-start" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#quick-start"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Quick Start</span></h2><!--]--><!----> <p>Start a server:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-bash "><!---->PYTHONPATH=src:envs uvicorn envs.repl_env.server.app:app --host 127.0.0.1 --port 8000<!----></pre></div><!----> <p>Async:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> asyncio
<span class="hljs-keyword">from</span> repl_env <span class="hljs-keyword">import</span> REPLEnv
<span class="hljs-keyword">async</span> <span class="hljs-keyword">def</span> <span class="hljs-title function_">main</span>():
<span class="hljs-keyword">async</span> <span class="hljs-keyword">with</span> REPLEnv(base_url=<span class="hljs-string">&quot;http://127.0.0.1:8000&quot;</span>) <span class="hljs-keyword">as</span> env:
result = <span class="hljs-keyword">await</span> env.reset(
context=<span class="hljs-string">&quot;alpha beta gamma&quot;</span>,
task_prompt=<span class="hljs-string">&quot;Count the words&quot;</span>,
)
result = <span class="hljs-keyword">await</span> env.execute(<span class="hljs-string">&quot;count = len(context.split())&quot;</span>)
result = <span class="hljs-keyword">await</span> env.execute(<span class="hljs-string">&quot;print(FINAL(count))&quot;</span>)
<span class="hljs-built_in">print</span>(result.done)
asyncio.run(main())<!----></pre></div><!----> <p>Sync:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> repl_env <span class="hljs-keyword">import</span> REPLEnv
<span class="hljs-keyword">with</span> REPLEnv(base_url=<span class="hljs-string">&quot;http://127.0.0.1:8000&quot;</span>).sync() <span class="hljs-keyword">as</span> env:
result = env.reset(
context=<span class="hljs-string">&quot;alpha beta gamma&quot;</span>,
task_prompt=<span class="hljs-string">&quot;Count the words&quot;</span>,
)
result = env.execute(<span class="hljs-string">&quot;count = len(context.split())&quot;</span>)
result = env.execute(<span class="hljs-string">&quot;print(FINAL(count))&quot;</span>)
<span class="hljs-built_in">print</span>(result.observation.result.stdout)<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="in-process" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#in-process"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>In Process</span></h3><!--]--><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> repl_env <span class="hljs-keyword">import</span> LocalREPLEnv
<span class="hljs-keyword">with</span> LocalREPLEnv() <span class="hljs-keyword">as</span> env:
result = env.reset(
context=<span class="hljs-string">&quot;The quick brown fox jumps over the lazy dog&quot;</span>,
task_prompt=<span class="hljs-string">&quot;Count the words&quot;</span>,
)
result = env.execute(<span class="hljs-string">&quot;count = len(context.split())&quot;</span>)
result = env.execute(<span class="hljs-string">&quot;print(FINAL(count))&quot;</span>)
<span class="hljs-built_in">print</span>(env.state().final_answer)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="server-configuration" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#server-configuration"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Server Configuration</span></h2><!--]--><!----> <p>Environment variables read by <a href="https://github.com/huggingface/OpenEnv/blob/main/envs/repl_env/server/app.py" rel="nofollow"><code>server/app.py</code></a>:</p> <table><thead><tr><th>Variable</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td><code>HF_TOKEN</code></td><td>unset</td><td>Enables <code>llm_query</code> on the server. Without it, a client can pass <code>hf_token</code> to <code>reset()</code></td></tr><tr><td><code>LLM_MODEL</code></td><td><code>Qwen/Qwen3.5-9B</code></td><td>Default model for <code>llm_query</code>. A client can pass <code>llm_model</code> to <code>reset()</code></td></tr><tr><td><code>REPL_MAX_ITERATIONS</code></td><td><code>30</code></td><td>Maximum steps per episode</td></tr><tr><td><code>REPL_MAX_OUTPUT_LENGTH</code></td><td><code>8192</code></td><td>Maximum captured output per step</td></tr><tr><td><code>REPL_CONTEXT_PREVIEW_LENGTH</code></td><td><code>500</code></td><td>Length of <code>context_preview</code> in observations</td></tr><tr><td><code>REPL_RLM_MAX_DEPTH</code></td><td><code>2</code></td><td>Maximum recursion depth for <code>rlm_query</code></td></tr><tr><td><code>REPL_RLM_MAX_ITERATIONS</code></td><td><code>30</code></td><td>Maximum iterations for recursive child runs</td></tr><tr><td><code>MAX_CONCURRENT_ENVS</code></td><td><code>8</code></td><td>Maximum concurrent sessions</td></tr></tbody></table> <!--[1--><h2 class="relative group"><a id="reward" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#reward"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Reward</span></h2><!--]--><!----> <p>Rewards use the OpenEnv <a href="https://huggingface.co/docs/openenv/guides/rewards" rel="nofollow">rubric system</a>. The default <code>REPLRubric</code> combines:</p> <ul><li><strong>Outcome reward</strong> (on terminal steps): compares <code>final_answer</code> against <code>expected_answer</code> if provided. Returns 1.0 for match, 0.0 otherwise.</li> <li><strong>Process reward</strong> (on non-terminal steps): returns -0.05 for code
execution errors, 0.0 for successful steps.</li> <li><strong>Failure reward</strong>: returns -0.1 when max iterations exhausted without an answer.</li></ul> <p>For RL training (GRPO, etc.), pass <code>expected_answer</code> at reset time:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">with</span> LocalREPLEnv() <span class="hljs-keyword">as</span> env:
env.reset(
context=<span class="hljs-string">&quot;...&quot;</span>,
task_prompt=<span class="hljs-string">&quot;...&quot;</span>,
expected_answer=<span class="hljs-string">&quot;42&quot;</span>, <span class="hljs-comment"># ground truth for rubric scoring</span>
)
result = env.execute(<span class="hljs-string">&quot;print(FINAL(42))&quot;</span>)
<span class="hljs-built_in">print</span>(result.reward) <span class="hljs-comment"># 1.0 (correct)</span><!----></pre></div><!----> <p>Other rubrics: <code>ExactMatchRubric</code> (binary match), <code>FuzzyMatchRubric</code> (1.0 for an exact match, 0.5 when the expected answer is contained in the final answer), <code>CustomMetricRubric</code> (your <code>metric(expected, predicted) -> float</code>) and <code>CodeExecutionRubric</code> (per-step error penalty). Pass one at construction:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> repl_env <span class="hljs-keyword">import</span> LocalREPLEnv, CustomMetricRubric, REPLRubric
<span class="hljs-keyword">def</span> <span class="hljs-title function_">my_metric</span>(<span class="hljs-params">expected, predicted</span>):
<span class="hljs-keyword">return</span> <span class="hljs-number">1.0</span> <span class="hljs-keyword">if</span> expected.strip() == predicted.strip() <span class="hljs-keyword">else</span> <span class="hljs-number">0.0</span>
env = LocalREPLEnv(rubric=REPLRubric(outcome=CustomMetricRubric(my_metric)))<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="running-an-rlm-locally" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#running-an-rlm-locally"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Running an RLM Locally</span></h2><!--]--><!----> <p><code>LocalRLMRunner</code> takes any <code>chat_fn(messages, model=None) -> str</code>. It works
with HF Inference API, vLLM, SGLang, Ollama, or any OpenAI-compatible server.</p> <p>With HF Inference API:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> InferenceClient
<span class="hljs-keyword">from</span> repl_env <span class="hljs-keyword">import</span> LocalRLMRunner, RLM_SYSTEM_PROMPT
client = InferenceClient(model=<span class="hljs-string">&quot;Qwen/Qwen3.5-9B&quot;</span>, timeout=<span class="hljs-number">300</span>)
<span class="hljs-keyword">def</span> <span class="hljs-title function_">chat_fn</span>(<span class="hljs-params">messages, model=<span class="hljs-literal">None</span></span>):
response = client.chat.completions.create(
model=model <span class="hljs-keyword">or</span> <span class="hljs-string">&quot;Qwen/Qwen3.5-9B&quot;</span>,
messages=messages,
max_tokens=<span class="hljs-number">2048</span>,
temperature=<span class="hljs-number">0.6</span>,
extra_body={<span class="hljs-string">&quot;chat_template_kwargs&quot;</span>: {<span class="hljs-string">&quot;enable_thinking&quot;</span>: <span class="hljs-literal">False</span>}},
)
<span class="hljs-keyword">return</span> response.choices[<span class="hljs-number">0</span>].message.content
runner = LocalRLMRunner(chat_fn, max_iterations=<span class="hljs-number">30</span>, max_depth=<span class="hljs-number">2</span>)
result = runner.run(<span class="hljs-string">&quot;The answer is 42&quot;</span>, <span class="hljs-string">&quot;What number is mentioned?&quot;</span>)
<span class="hljs-built_in">print</span>(result.final_answer)<!----></pre></div><!----> <p>With a local vLLM server:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> openai <span class="hljs-keyword">import</span> OpenAI
<span class="hljs-keyword">from</span> repl_env <span class="hljs-keyword">import</span> LocalRLMRunner
client = OpenAI(base_url=<span class="hljs-string">&quot;http://localhost:8000/v1&quot;</span>, api_key=<span class="hljs-string">&quot;unused&quot;</span>)
<span class="hljs-keyword">def</span> <span class="hljs-title function_">chat_fn</span>(<span class="hljs-params">messages, model=<span class="hljs-literal">None</span></span>):
response = client.chat.completions.create(
model=model <span class="hljs-keyword">or</span> <span class="hljs-string">&quot;Qwen/Qwen3.5-9B&quot;</span>,
messages=messages,
max_tokens=<span class="hljs-number">2048</span>,
temperature=<span class="hljs-number">0.6</span>,
)
<span class="hljs-keyword">return</span> response.choices[<span class="hljs-number">0</span>].message.content
runner = LocalRLMRunner(chat_fn, max_iterations=<span class="hljs-number">30</span>, max_depth=<span class="hljs-number">2</span>)
result = runner.run(context, task)<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="different-models-for-outer-and-inner-loops" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#different-models-for-outer-and-inner-loops"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Different Models for Outer and Inner Loops</span></h3><!--]--><!----> <p>The outer loop (code generation) can use a large model while inner <code>llm_query</code>/<code>rlm_query</code> calls use a smaller, faster model. Pass a
custom <code>backend_factory</code> to the runner:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> openai <span class="hljs-keyword">import</span> OpenAI
<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> InferenceClient
<span class="hljs-keyword">from</span> repl_env <span class="hljs-keyword">import</span> LocalRLMRunner
<span class="hljs-keyword">from</span> repl_env.recursive_backends <span class="hljs-keyword">import</span> BackendLimits, LocalChildRLMBackend
<span class="hljs-comment"># Outer loop: large local model via vLLM</span>
vllm = OpenAI(base_url=<span class="hljs-string">&quot;http://localhost:8000/v1&quot;</span>, api_key=<span class="hljs-string">&quot;unused&quot;</span>)
<span class="hljs-keyword">def</span> <span class="hljs-title function_">outer_chat</span>(<span class="hljs-params">messages, model=<span class="hljs-literal">None</span></span>):
r = vllm.chat.completions.create(
model=<span class="hljs-string">&quot;Qwen/Qwen3-32B&quot;</span>, messages=messages, max_tokens=<span class="hljs-number">2048</span>,
)
<span class="hljs-keyword">return</span> r.choices[<span class="hljs-number">0</span>].message.content
<span class="hljs-comment"># Inner calls (llm_query/rlm_query): smaller HF-hosted model</span>
hf = InferenceClient(model=<span class="hljs-string">&quot;Qwen/Qwen3.5-9B&quot;</span>)
<span class="hljs-keyword">def</span> <span class="hljs-title function_">inner_chat</span>(<span class="hljs-params">messages, model=<span class="hljs-literal">None</span></span>):
r = hf.chat.completions.create(
model=model <span class="hljs-keyword">or</span> <span class="hljs-string">&quot;Qwen/Qwen3.5-9B&quot;</span>, messages=messages, max_tokens=<span class="hljs-number">2048</span>,
extra_body={<span class="hljs-string">&quot;chat_template_kwargs&quot;</span>: {<span class="hljs-string">&quot;enable_thinking&quot;</span>: <span class="hljs-literal">False</span>}},
)
<span class="hljs-keyword">return</span> r.choices[<span class="hljs-number">0</span>].message.content
<span class="hljs-keyword">def</span> <span class="hljs-title function_">my_backend_factory</span>(<span class="hljs-params">llm_chat_fn, **kwargs</span>):
<span class="hljs-keyword">return</span> LocalChildRLMBackend(
inner_chat, <span class="hljs-comment"># inner calls use the smaller model</span>
runner_factory=LocalRLMRunner,
system_prompt=kwargs[<span class="hljs-string">&quot;system_prompt&quot;</span>],
max_iterations=kwargs[<span class="hljs-string">&quot;max_iterations&quot;</span>],
env_max_iterations_multiplier=kwargs[<span class="hljs-string">&quot;env_max_iterations_multiplier&quot;</span>],
depth=kwargs[<span class="hljs-string">&quot;depth&quot;</span>],
limits=BackendLimits(max_depth=<span class="hljs-number">2</span>),
)
runner = LocalRLMRunner(
outer_chat, <span class="hljs-comment"># outer loop: large model</span>
backend_factory=my_backend_factory, <span class="hljs-comment"># inner calls: small model</span>
max_iterations=<span class="hljs-number">30</span>,
max_depth=<span class="hljs-number">2</span>,
)
result = runner.run(context, task)<!----></pre></div><!----> <p><code>LocalRLMRunner</code> also takes recursion limits (<code>max_children_total</code>, <code>max_children_per_batch</code>, <code>per_child_timeout_s</code>, <code>result_truncation_limit</code>) and lifecycle callbacks (<code>on_subcall_start(depth, model, prompt_preview)</code>, <code>on_subcall_complete(depth, model, duration, error_or_none)</code>). Its results carry lightweight child trace metadata.</p> <!--[1--><h2 class="relative group"><a id="actions-and-observations" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#actions-and-observations"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Actions and Observations</span></h2><!--]--><!----> <p><code>REPLAction</code></p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!---->code: <span class="hljs-built_in">str</span> = <span class="hljs-string">&quot;&quot;</span>
is_final: <span class="hljs-built_in">bool</span> = <span class="hljs-literal">False</span>
final_answer: <span class="hljs-built_in">str</span> | <span class="hljs-literal">None</span> = <span class="hljs-literal">None</span><!----></pre></div><!----> <p><code>REPLObservation</code></p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!---->result: CodeBlockResult
context_preview: <span class="hljs-built_in">str</span> | <span class="hljs-literal">None</span>
context_length: <span class="hljs-built_in">int</span>
available_variables: <span class="hljs-built_in">list</span>[<span class="hljs-built_in">str</span>]
iteration: <span class="hljs-built_in">int</span>
max_iterations: <span class="hljs-built_in">int</span>
done: <span class="hljs-built_in">bool</span>
reward: <span class="hljs-built_in">float</span> | <span class="hljs-literal">None</span>
metadata: <span class="hljs-built_in">dict</span><!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="repl-helpers" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#repl-helpers"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>REPL Helpers</span></h2><!--]--><!----> <p>When configured, the REPL namespace exposes:</p> <ul><li><code>llm_query(prompt, model=None)</code> and <code>llm_query_batched(prompts, model=None)</code></li> <li><code>rlm_query(prompt, model=None)</code> and <code>rlm_query_batched(prompts, model=None)</code>: recursive child runs. At the maximum depth they fall back to direct model calls.</li> <li><code>FINAL(value)</code>, <code>FINAL_VAR(name)</code> and <code>SHOW_VARS()</code></li></ul> <!--[1--><h2 class="relative group"><a id="finalization-patterns" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#finalization-patterns"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Finalization Patterns</span></h2><!--]--><!----> <!--[2--><h3 class="relative group"><a id="final" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#final"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>FINAL(...)</span></h3><!--]--><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!---->result = env.execute(<span class="hljs-string">&quot;answer = 42&quot;</span>)
result = env.execute(<span class="hljs-string">&quot;print(FINAL(answer))&quot;</span>)<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="finalvar" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#finalvar"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>FINAL_VAR(...)</span></h3><!--]--><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!---->result = env.execute(<span class="hljs-string">&quot;my_answer = &#x27;42&#x27;&quot;</span>)
result = env.execute(<span class="hljs-string">&#x27;print(FINAL_VAR(&quot;my_answer&quot;))&#x27;</span>)<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="answer-dict" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#answer-dict"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>answer dict</span></h3><!--]--><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!---->result = env.execute(<span class="hljs-string">&quot;answer[&#x27;content&#x27;] = &#x27;42&#x27;&quot;</span>)
result = env.execute(<span class="hljs-string">&quot;answer[&#x27;ready&#x27;] = True&quot;</span>)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="prompts-and-examples" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#prompts-and-examples"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Prompts and Examples</span></h2><!--]--><!----> <p><a href="https://github.com/huggingface/OpenEnv/blob/main/envs/repl_env/prompts.py" rel="nofollow"><code>prompts.py</code></a> has the system prompts and helpers used by the runner: <code>RLM_SYSTEM_PROMPT</code>, <code>RLM_SYSTEM_PROMPT_QWEN</code>, <code>QueryMetadata</code>, <code>build_rlm_system_prompt(...)</code>, <code>build_user_prompt(...)</code>, <code>extract_code_blocks(...)</code> and <code>format_observations(...)</code>.</p> <p>Examples, which default to <code>Qwen/Qwen3.5-9B</code> through Hugging Face inference (needs <code>HF_TOKEN</code>):</p> <ul><li><a href="https://github.com/huggingface/OpenEnv/blob/main/examples/repl_with_llm.py" rel="nofollow"><code>examples/repl_with_llm.py</code></a></li> <li><a href="https://github.com/huggingface/OpenEnv/blob/main/examples/repl_oolong_simple.py" rel="nofollow"><code>examples/repl_oolong_simple.py</code></a></li></ul> <!--[1--><h2 class="relative group"><a id="references" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#references"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>References</span></h2><!--]--><!----> <ul><li><a href="https://huggingface.co/papers/2512.24601" rel="nofollow">RLM Paper (arXiv:2512.24601)</a></li> <li><a href="https://github.com/alexzhang13/rlm" rel="nofollow">RLM Implementation</a></li> <li><a href="https://alexzhang13.github.io/blog/2025/rlm/" rel="nofollow">Alex Zhang’s RLM Blog</a></li> <li><a href="https://www.primeintellect.ai/blog/rlm" rel="nofollow">Prime Intellect RLM Blog</a></li></ul> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/openenv/blob/main/docs/source/environments/repl.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg><!----> <span><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]-->
<script>
{
__sveltekit_z3ymrf = {
base: "/docs/openenv/main/en",
assets: "/docs/openenv/main/en"
};
const element = document.currentScript.parentElement;
Promise.all([
import("/docs/openenv/main/en/_app/immutable/entry/start.D7897gYC.js"),
import("/docs/openenv/main/en/_app/immutable/entry/app.DEcMydco.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 8],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
60 kB
·
Xet hash:
a35729ffcd3f37b2295a203c84302e3102c67de4b5089c2bf1d69ee96099355a

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.