Skip to main content

Module rlm

Module rlm 

Source
Expand description

Recursive Language Model (RLM) loop — paper-spec Algorithm 1.

Implements Zhang, Kraska & Khattab (arXiv:2512.24601, §2 Algorithm 1):

state ← InitREPL(prompt=P)
state ← AddFunction(state, sub_RLM)
hist ← [Metadata(state)]
while True:
    code ← LLM(hist)
    (state, stdout) ← REPL(state, code)
    hist ← hist ∥ code ∥ Metadata(stdout)
    if state[Final] is set:
        return state[Final]

Invariants:

  • P is held only as a REPL variable (context / ctx); never appears in the root LLM’s window.
  • The root LLM receives small metadata messages — length, preview, helper list, prior-round summary.
  • Code rounds and sub-LLM calls travel over a single stdin/stdout pipe to a long-lived python3 -u subprocess. No HTTP sidecar.

Re-exports§

pub use bridge::RlmBridge;
pub use prompt::rlm_system_prompt;
pub use turn::RlmTermination;
pub use turn::RlmTurnResult;
pub use turn::run_rlm_turn;
pub use turn::run_rlm_turn_with_root;

Modules§

bridge
RPC bridge that services llm_query / rlm_query calls coming back from the long-lived Python REPL during an RLM turn.
prompt
RLM system prompt — adapted from the reference implementation (alexzhang13/rlm) and Zhang et al., arXiv:2512.24601.
turn
RLM turn loop — paper Algorithm 1 driven over a long-lived Python subprocess + stdin/stdout RPC bridge (no HTTP sidecar).