# Recursive Language Model (RLM) mode `local_agent.py` now lets the model treat a huge input as a Python variable (`context`) instead of reading it as tokens, recurse on pieces of it, and learn from every run. ## Files - `rlm_vec.py` - pure-Python vector math (dot, cosine, matmul, solve, linreg, kmeans, pca, power_iter, bm25, hashed `embed`, `VectorIndex`) and `Ctx` (grep, outline, chunk, rank, peek, stats...). - `rlm_core.py` - REPL with timeout, recursive solver, skill library, journal, self-improvement. Standalone test: `python rlm_core.py`. - `rlm/` (created on first use, next to the script) - `journal.jsonl` (episodes, feedback, lessons), `skills/*.py` + `index.json` (+ `_history/`), `memory.json`. ## Tools (category `rlm`) | tool | does | |---|---| | `rlm_solve(task, path/name/text)` | full loop: explore, filter, decompose, recurse, aggregate, verify, FINAL | | `rlm_load` / `rlm_exec` | load into `context`; drive the persistent REPL by hand | | `rlm_improve(focus)` | model writes a helper + test from recent failures; saved only if the test passes | | `rlm_skills(list/show/save/delete)` | the self-written library; skills auto-load into every REPL | | `rlm_feedback(episode, score, note)` | grade a run; low grades become lessons | | `rlm_status` | score trend (recent10 vs previous10), skills, lessons | | `rlm_vector(op, ...)` | embed / cosine / rank / cluster / linreg / solve | In the REPL: `context`, `ctx`, `llm_query`, `llm_map`, `rlm_query` (recursive, depth-limited), vector math, `store/recall`, `skill_save`, `FINAL`, `FINAL_VAR`. ## How it self-improves 1. Before a run, similar past episodes (with their working code "recipe"), lessons and the skill index are put in the RLM system prompt. 2. After a run, the episode is scored (errors, forced finish, verifier FIX) and journaled. 3. `rlm_improve` turns failures into a tested skill + a lesson; skills track uses/errors and are auto-disabled when they keep failing (`prune_*` limits). ## Config (`CONFIG` / config file) `rlm_dir, rlm_max_depth(3), rlm_max_iters(8), rlm_max_calls(80), rlm_max_seconds(1800), rlm_sub_chars(12000), rlm_verify, rlm_temperature`. ## Limits (honest) - The REPL is **not a sandbox**: model code runs with your user's rights (same trust level as `run_python`; tools are `risk=system`). - Timeouts interrupt pure-Python loops; code stuck inside a C call may not stop. - Each sub-call reuses the one loaded model, so it works between generations and invalidates part of the KV cache (a re-prefill cost). - "Improvement" quality depends on the model; the gate is the test it writes for itself, so weak tests give weak guarantees. Use `rlm_feedback` to steer. - Verified with the scripted backend only (`python local_agent.py --selftest`, 119 pass). Not yet run against the real GGUF: try `rlm_solve` on a large file first and check `rlm_status`.