| 1 | //! Recursive Language Model (RLM) loop — paper-spec Algorithm 1. |
| 2 | //! |
| 3 | //! Implements Zhang, Kraska & Khattab (arXiv:2512.24601, §2 Algorithm 1): |
| 4 | //! |
| 5 | //! ```text |
| 6 | //! state ← InitREPL(prompt=P) |
| 7 | //! state ← AddFunction(state, sub_RLM) |
| 8 | //! hist ← [Metadata(state)] |
| 9 | //! while True: |
| 10 | //! code ← LLM(hist) |
| 11 | //! (state, stdout) ← REPL(state, code) |
| 12 | //! hist ← hist ∥ code ∥ Metadata(stdout) |
| 13 | //! if state[Final] is set: |
| 14 | //! return state[Final] |
| 15 | //! ``` |
| 16 | //! |
| 17 | //! Invariants: |
| 18 | //! - `P` is held only as a REPL variable (`context` / `ctx`); never |
| 19 | //! appears in the root LLM's window. |
| 20 | //! - The root LLM receives small metadata messages — length, preview, |
| 21 | //! helper list, prior-round summary. |
| 22 | //! - Code rounds and sub-LLM calls travel over a single stdin/stdout |
| 23 | //! pipe to a long-lived `python3 -u` subprocess. No HTTP sidecar. |
| 24 | |
| 25 | pub mod bridge; |
| 26 | pub mod prompt; |
| 27 | pub mod turn; |
| 28 | |
| 29 | pub use bridge::RlmBridge; |
| 30 | pub use prompt::rlm_system_prompt; |
| 31 | pub use turn::{RlmTermination, RlmTurnResult, run_rlm_turn, run_rlm_turn_with_root}; |
| 32 |