-
Initialize the REPL state
python3 ~/.pi/agent/skills/rlm/scripts/rlm_repl.py init <context_path>
The output will show the session path (e.g., .pi/rlm_state/myfile-20260120-155234/state.pkl).
Store this path mentally — use it for all subsequent --state arguments.
Available init options:
python3 ~/.pi/agent/skills/rlm/scripts/rlm_repl.py init <path> \
--max-depth 5 \
--preserve-recursive-state
Check status:
python3 ~/.pi/agent/skills/rlm/scripts/rlm_repl.py --state <session_state_path> status
-
Scout the content (optional but recommended)
Use the handle-based search to explore without flooding your context:
python3 ~/.pi/agent/skills/rlm/scripts/rlm_repl.py --state <session_state_path> exec -c "
# grep() returns a handle stub, not raw data
result = grep('ERROR')
print(result) # e.g., '\$res1: Array(47) [preview...]'
# Inspect without expanding
print(f'Found {count(\"\$res1\")} matches')
# Expand only what you need
for item in expand('\$res1', limit=5):
print(f\"Line {item['line_num']}: {item['match']}\")
"
-
Materialize chunks as files (so subagents can read them)
Option A: Basic chunking (character-based)
python3 ~/.pi/agent/skills/rlm/scripts/rlm_repl.py --state <session_state_path> exec <<'PY'
session_dir = state_path.parent
chunks_dir = str(session_dir / 'chunks')
paths = write_chunks(chunks_dir, size=200000, overlap=0)
print(f"Wrote {len(paths)} chunks")
print(paths[:5])
PY
Option B: Smart chunking (content-aware) ⭐ RECOMMENDED
python3 ~/.pi/agent/skills/rlm/scripts/rlm_repl.py --state <session_state_path> exec <<'PY'
session_dir = state_path.parent
paths = smart_chunk(
str(session_dir / 'chunks'),
target_size=200000,
min_size=50000,
max_size=400000,
)
print(f"Created {len(paths)} chunks")
PY
Smart chunking auto-detects format and splits at natural boundaries:
- Markdown: Splits at header boundaries (## and ###)
- Code: Splits at function/class boundaries (requires codemap)
- JSON: Splits arrays into element groups, objects by keys
- Text: Splits at paragraph breaks
After chunking, read the manifest to understand chunk coverage:
cat <session_dir>/chunks/manifest.json
The manifest includes:
format: Detected content type (markdown, code, json, text)
chunking_method: Method used (smart_markdown, smart_code, smart_json, smart_text)
preview: First few lines of each chunk
hints: Content analysis (e.g., likely_code, section_headers, density)
boundaries: Header/symbol boundaries for each chunk
Use hints to skip irrelevant chunks or craft better prompts.
-
Query sub-LLMs (multiple options)
Option A: Use subagent_enhanced delegation (parallel mode)
Use the subagent_enhanced tool with the rlm-subcall agent for parallel invocation:
{
"tasks": [
{"agent": "rlm-subcall", "task": "Query: <user query>\nChunk file: <absolute path to chunk_0000.txt>"},
{"agent": "rlm-subcall", "task": "Query: <user query>\nChunk file: <absolute path to chunk_0001.txt>"},
...
]
}
Option B: Use inline llm_query() (single query)
python3 ~/.pi/agent/skills/rlm/scripts/rlm_repl.py --state <session_state_path> exec -c "
chunk_path = session_dir / 'chunks' / 'chunk_0000.txt'
result = llm_query(f'Summarize: {chunk_path.read_text()[:50000]}')
print(result)
add_buffer(result)
"
Option C: Use llm_query_batch() (parallel queries)
python3 ~/.pi/agent/skills/rlm/scripts/rlm_repl.py --state <session_state_path> exec <<'PY'
chunk_dir = session_dir / 'chunks'
chunk_files = sorted(chunk_dir.glob('chunk_*.txt'))
prompts = []
for chunk_file in chunk_files:
content = chunk_file.read_text()[:50000]
prompts.append(f"Find all TODOs in this code:\n{content}")
results, failures = llm_query_batch(
prompts,
concurrency=5,
max_retries=3,
)
print(f"Got {len(results)} results, {len(failures)} failures")
for i, result in enumerate(results):
if "[ERROR:" not in result:
add_buffer(f"Chunk {i}: {result}")
PY
-
Set final answer (for external retrieval)
python3 ~/.pi/agent/skills/rlm/scripts/rlm_repl.py --state <session_state_path> exec -c "
# Compile results
final_result = {
'summary': 'Found 15 issues across 4 files',
'issues': [...] # Must be JSON-serializable
}
set_final_answer(final_result)
"
python3 ~/.pi/agent/skills/rlm/scripts/rlm_repl.py --state <session_state_path> get-final-answer
-
Synthesis
- Once enough evidence is collected, synthesize the final answer in the main conversation.
- Use the manifest to cite specific locations (line numbers, character positions).
- Optionally invoke rlm-subcall once more to merge collected buffers into a coherent draft.