Skip to content

Instantly share code, notes, and snippets.

@rahuldave
Created January 14, 2026 13:44
Show Gist options
  • Select an option

  • Save rahuldave/0ba600ef4601e308a42c961446128ee0 to your computer and use it in GitHub Desktop.

Select an option

Save rahuldave/0ba600ef4601e308a42c961446128ee0 to your computer and use it in GitHub Desktop.
uv run python -m examples.quickstart
╭─ ◆ RLM ━ Recursive Language Model ─────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Backend openai Environment local │
│ Model gpt-5-nano Max Iterations 30 │
│ Max Depth 1 │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
───────────────────────────────────────────────────────── Iteration 1 ──────────────────────────────────────────────────────────
╭─ ◇ LLM Response (33.66s) ─────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ```repl │
│ # Step 1: Inspect the context to understand what we’re dealing with │
│ print("TYPE:", type(context)) │
│ print("LEN:", len(context) if hasattr(context, '__len__') else "unknown") │
│ sample_start = 0 │
│ sample_end = min(1000, len(context)) if hasattr(context, '__len__') else 0 │
│ print("SAMPLE (first 1000 chars or so):") │
│ print(context[sample_start:sample_end]) │
│ ``` │
│ │
│ ```repl │
│ # Step 2: If the context is a large string, chunk it into manageable pieces │
│ if isinstance(context, str) and len(context) > 2000: │
│ chunk_size = 2000 │
│ chunks = [context[i:i+chunk_size] for i in range(0, len(context), chunk_size)] │
│ else: │
│ chunks = [str(context)] │
│ print("CHUNK COUNT:", len(chunks)) │
│ ``` │
│ │
│ ```repl │
│ # Step 3: Request a high-level plan from the LLM (without exposing internal chain-of-thought) │
│ # The plan should be concise and high-level, focusing on approach rather than detailed reasoning. │
│ plan = llm_query( │
│ "Provide a concise high-level plan for answering the user's prompt given the following context chunks: " │
│ f"{len(chunks)} chunks. Do not reveal internal chain-of-thought; present as bullets." │
│ ) │
│ print("PLAN:") │
│ print(plan) │
│ ``` │
│ │
│ ~148 words │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ ▸ Code Execution (0.000s) ───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Code: │
│ # Step 1: Inspect the context to understand what we’re dealing with │
│ print("TYPE:", type(context)) │
│ print("LEN:", len(context) if hasattr(context, '__len__') else "unknown") │
│ sample_start = 0 │
│ sample_end = min(1000, len(context)) if hasattr(context, '__len__') else 0 │
│ print("SAMPLE (first 1000 chars or so):") │
│ print(context[sample_start:sample_end]) │
│ │
│ Output: │
│ TYPE: <class 'str'> │
│ LEN: 56 │
│ SAMPLE (first 1000 chars or so): │
│ Print me the first 100 powers of two, each on a newline. │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ ▸ Code Execution (0.000s) ───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Code: │
│ # Step 2: If the context is a large string, chunk it into manageable pieces │
│ if isinstance(context, str) and len(context) > 2000: │
│ chunk_size = 2000 │
│ chunks = [context[i:i+chunk_size] for i in range(0, len(context), chunk_size)] │
│ else: │
│ chunks = [str(context)] │
│ print("CHUNK COUNT:", len(chunks)) │
│ │
│ Output: │
│ CHUNK COUNT: 1 │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ ▸ Code Execution (10.639s) ──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Code: │
│ # Step 3: Request a high-level plan from the LLM (without exposing internal chain-of-thought) │
│ # The plan should be concise and high-level, focusing on approach rather than detailed reasoning. │
│ plan = llm_query( │
│ "Provide a concise high-level plan for answering the user's prompt given the following context chunks: " │
│ f"{len(chunks)} chunks. Do not reveal internal chain-of-thought; present as bullets." │
│ ) │
│ print("PLAN:") │
│ print(plan) │
│ │
│ Output: │
│ PLAN: │
│ - Restate the objective and success criteria from the user’s prompt. │
│ - Read the 1 context chunk and extract all relevant facts, constraints, and goals. │
│ - Identify any gaps or ambiguities; note clarifying questions or reasonable assumptions. │
│ - Decide on a concise, structured approach (e.g., summary first, then key points or steps). │
│ - Outline the answer format and deliverables (one-line takeaway, 2–4 supporting bullets, conclusion). │
│ - Draft the high-level plan without delving into internal reasoning: keep to the essentials and align with context. │
│ - Validate for consistency with the context chunk and avoid introducing unsupported details. │
│ - Present the final plan succinctly. │
│ │
│ │
│ ↳ 1 sub-call(s) │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ ↳ Sub-call: gpt-5-nano (10.64s) ───────────────────────────────────────────────────────────────────────────────────────────╮
│ Prompt: Provide a concise high-level plan for answering the user's prompt given the following context chunks: 1 chunks. Do not │
│ reveal internal chain-of-thought; present as bullets. │
│ Response: - Restate the objective and success criteria from the user’s prompt. │
│ - Read the 1 context chunk and extract all relevant facts, constraints, and goals. │
│ - Identify any gaps or ambiguities; note clarifying questions or reasonable assumptions. │
│ - Decide on a concise, structured approach (e.g., summary first, then key points or steps). │
│ - Outline the answer format and deliverables (one-line takeaway, 2–4 supporting bullets, conclusion). │
│ - Draft the high-level plan without delving into internal reasoning: keep to the essentials and align with context. │
│ - Validate for consistency with the context chunk and avoid introducing unsupported details. │
│ - Present the final plan succinctly. │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
───────────────────────────────────────────────────────── Iteration 2 ──────────────────────────────────────────────────────────
╭─ ◇ LLM Response (94.20s) ─────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ```repl │
│ # Next action: generate and print the first 100 powers of two (2^0 through 2^99), │
│ # each on its own line, without any separators. │
│ powers = [1 << i for i in range(100)] │
│ print("\n".join(str(p) for p in powers)) │
│ ``` │
│ │
│ ~40 words │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ ▸ Code Execution (0.000s) ───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Code: │
│ # Next action: generate and print the first 100 powers of two (2^0 through 2^99), │
│ # each on its own line, without any separators. │
│ powers = [1 << i for i in range(100)] │
│ print("\n".join(str(p) for p in powers)) │
│ │
│ Output: │
│ 1 │
│ 2 │
│ 4 │
│ 8 │
│ 16 │
│ 32 │
│ 64 │
│ 128 │
│ 256 │
│ 512 │
│ 1024 │
│ 2048 │
│ 4096 │
│ 8192 │
│ 16384 │
│ 32768 │
│ 65536 │
│ 131072 │
│ 262144 │
│ 524288 │
│ 1048576 │
│ 2097152 │
│ 4194304 │
│ 8388608 │
│ 16777216 │
│ 33554432 │
│ 67108864 │
│ 134217728 │
│ 268435456 │
│ 536870912 │
│ 1073741824 │
│ 2147483648 │
│ 4294967296 │
│ 8589934592 │
│ 17179869184 │
│ 34359738368 │
│ 68719476736 │
│ 137438953472 │
│ 274877906944 │
│ 549755813888 │
│ 1099511627776 │
│ 2199023255552 │
│ 4398046511104 │
│ 8796093022208 │
│ 17592186044416 │
│ 35184372088832 │
│ 70368744177664 │
│ 140737488355328 │
│ 281474976710656 │
│ 562949953421312 │
│ 1125899906842624 │
│ 2251799813685248 │
│ 4503599627370496 │
│ 9007199254740992 │
│ 18014398509481984 │
│ 36028797018963968 │
│ 72057594037927936 │
│ 144115188075855872 │
│ 288230376151711744 │
│ 576460752303423488 │
│ 1152921504606846976 │
│ 2305843009213693952 │
│ 4611686018427387904 │
│ 9223372036854775808 │
│ 18446744073709551616 │
│ 36893488147419103232 │
│ 73786976294838206464 │
│ 147573952589676412928 │
│ 295147905179352825856 │
│ 590295810358705651712 │
│ 1180591620717411303424 │
│ 2361183241434822606848 │
│ 4722366482869645213696 │
│ 9444732965739290427392 │
│ 18889465931478580854784 │
│ 37778931862957161709568 │
│ 75557863725914323419136 │
│ 151115727451828646838272 │
│ 302231454903657293676544 │
│ 604462909807314587353088 │
│ 1208925819614629174706176 │
│ 2417851639229258349412352 │
│ 4835703278458516698824704 │
│ 9671406556917033397649408 │
│ 19342813113834066795298816 │
│ 38685626227668133590597632 │
│ 77371252455336267181195264 │
│ 154742504910672534362390528 │
│ 309485009821345068724781056 │
│ 618970019642690137449562112 │
│ 1237940039285380274899124224 │
│ 2475880078570760549798248448 │
│ 4951760157141521099596496896 │
│ 9903520314283042199192993792 │
│ 19807040628566084398385987584 │
│ 39614081257132168796771975168 │
│ 79228162514264337593543950336 │
│ 158456325028528675187087900672 │
│ 316912650057057350374175801344 │
│ 633825300114114700748351602688 │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
───────────────────────────────────────────────────────── Iteration 3 ──────────────────────────────────────────────────────────
╭─ ◇ LLM Response (19.95s) ─────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ```repl │
│ # Next action: verify correctness of the produced powers │
│ expected = [1 << i for i in range(100)] │
│ verification = powers == expected │
│ print("VERIFICATION_PASS:", verification) │
│ print("LAST_VALUE (2^99):", powers[-1]) │
│ ``` │
│ │
│ ~30 words │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ ▸ Code Execution (0.001s) ───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Code: │
│ # Next action: verify correctness of the produced powers │
│ expected = [1 << i for i in range(100)] │
│ verification = powers == expected │
│ print("VERIFICATION_PASS:", verification) │
│ print("LAST_VALUE (2^99):", powers[-1]) │
│ │
│ Output: │
│ VERIFICATION_PASS: True │
│ LAST_VALUE (2^99): 633825300114114700748351602688 │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
───────────────────────────────────────────────────────── Iteration 4 ──────────────────────────────────────────────────────────
╭─ ◇ LLM Response (27.03s) ─────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ```repl │
│ # Final action: assemble the exact final answer (the 100 powers of two, one per line) │
│ final_output = "\n".join(str(1 << i) for i in range(100)) │
│ print(final_output) │
│ ``` │
│ │
│ FINAL( │
│ 1 │
│ 2 │
│ 4 │
│ 8 │
│ 16 │
│ 32 │
│ 64 │
│ 128 │
│ 256 │
│ 512 │
│ 1024 │
│ 2048 │
│ 4096 │
│ 8192 │
│ 16384 │
│ 32768 │
│ 65536 │
│ 131072 │
│ 262144 │
│ 524288 │
│ 1048576 │
│ 2097152 │
│ 4194304 │
│ 8388608 │
│ 16777216 │
│ 33554432 │
│ 67108864 │
│ 134217728 │
│ 268435456 │
│ 536870912 │
│ 1073741824 │
│ 2147483648 │
│ 4294967296 │
│ 8589934592 │
│ 17179869184 │
│ 34359738368 │
│ 68719476736 │
│ 137438953472 │
│ 274877906944 │
│ 549755813888 │
│ 1099511627776 │
│ 2199023255552 │
│ 4398046511104 │
│ 8796093022208 │
│ 17592186044416 │
│ 35184372088832 │
│ 70368744177664 │
│ 140737488355328 │
│ 281474976710656 │
│ 562949953421312 │
│ 1125899906842624 │
│ 2251799813685248 │
│ 4503599627370496 │
│ 9007199254740992 │
│ 18014398509481984 │
│ 36028797018963968 │
│ 72057594037927936 │
│ 144115188075855872 │
│ 288230376151711744 │
│ 576460752303423488 │
│ 1152921504606846976 │
│ 2305843009213693952 │
│ 4611686018427387904 │
│ 9223372036854775808 │
│ 18446744073709551616 │
│ 36893488147419103232 │
│ 73786976294838206464 │
│ 147573952589676412928 │
│ 295147905179352825856 │
│ 590295810358705651712 │
│ 1180591620717411303424 │
│ 2361183241434822606848 │
│ 4722366482869645213696 │
│ 9444732965739290427392 │
│ 18889465931478580854784 │
│ 37778931862957161709568 │
│ 75557863725914323419136 │
│ 151115727451828646838272 │
│ 302231454903657293676544 │
│ 604462909807314587353088 │
│ 1208925819614629174706176 │
│ 2417851639229258349412352 │
│ 4835703278458516698824704 │
│ 9671406556917033397649408 │
│ 19342813113834066795298816 │
│ 38685626227668133590597632 │
│ 77371252455336267181195264 │
│ 154742504910672534362390528 │
│ 309485009821345068724781056 │
│ 618970019642690137449562112 │
│ 1237940039285380274899124224 │
│ 2475880078570760549798248448 │
│ 4951760157141521099596496896 │
│ 9903520314283042199192993792 │
│ 19807040628566084398385987584 │
│ 39614081257132168796771975168 │
│ 79228162514264337593543950336 │
│ 158456325028528675187087900672 │
│ 316912650057057350374175801344 │
│ 633825300114114700748351602688 │
│ ) │
│ │
│ ~130 words │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ ▸ Code Execution (0.001s) ───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Code: │
│ # Final action: assemble the exact final answer (the 100 powers of two, one per line) │
│ final_output = "\n".join(str(1 << i) for i in range(100)) │
│ print(final_output) │
│ │
│ Output: │
│ 1 │
│ 2 │
│ 4 │
│ 8 │
│ 16 │
│ 32 │
│ 64 │
│ 128 │
│ 256 │
│ 512 │
│ 1024 │
│ 2048 │
│ 4096 │
│ 8192 │
│ 16384 │
│ 32768 │
│ 65536 │
│ 131072 │
│ 262144 │
│ 524288 │
│ 1048576 │
│ 2097152 │
│ 4194304 │
│ 8388608 │
│ 16777216 │
│ 33554432 │
│ 67108864 │
│ 134217728 │
│ 268435456 │
│ 536870912 │
│ 1073741824 │
│ 2147483648 │
│ 4294967296 │
│ 8589934592 │
│ 17179869184 │
│ 34359738368 │
│ 68719476736 │
│ 137438953472 │
│ 274877906944 │
│ 549755813888 │
│ 1099511627776 │
│ 2199023255552 │
│ 4398046511104 │
│ 8796093022208 │
│ 17592186044416 │
│ 35184372088832 │
│ 70368744177664 │
│ 140737488355328 │
│ 281474976710656 │
│ 562949953421312 │
│ 1125899906842624 │
│ 2251799813685248 │
│ 4503599627370496 │
│ 9007199254740992 │
│ 18014398509481984 │
│ 36028797018963968 │
│ 72057594037927936 │
│ 144115188075855872 │
│ 288230376151711744 │
│ 576460752303423488 │
│ 1152921504606846976 │
│ 2305843009213693952 │
│ 4611686018427387904 │
│ 9223372036854775808 │
│ 18446744073709551616 │
│ 36893488147419103232 │
│ 73786976294838206464 │
│ 147573952589676412928 │
│ 295147905179352825856 │
│ 590295810358705651712 │
│ 1180591620717411303424 │
│ 2361183241434822606848 │
│ 4722366482869645213696 │
│ 9444732965739290427392 │
│ 18889465931478580854784 │
│ 37778931862957161709568 │
│ 75557863725914323419136 │
│ 151115727451828646838272 │
│ 302231454903657293676544 │
│ 604462909807314587353088 │
│ 1208925819614629174706176 │
│ 2417851639229258349412352 │
│ 4835703278458516698824704 │
│ 9671406556917033397649408 │
│ 19342813113834066795298816 │
│ 38685626227668133590597632 │
│ 77371252455336267181195264 │
│ 154742504910672534362390528 │
│ 309485009821345068724781056 │
│ 618970019642690137449562112 │
│ 1237940039285380274899124224 │
│ 2475880078570760549798248448 │
│ 4951760157141521099596496896 │
│ 9903520314283042199192993792 │
│ 19807040628566084398385987584 │
│ 39614081257132168796771975168 │
│ 79228162514264337593543950336 │
│ 158456325028528675187087900672 │
│ 316912650057057350374175801344 │
│ 633825300114114700748351602688 │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ ★ Final Answer ───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ 1 │
│ 2 │
│ 4 │
│ 8 │
│ 16 │
│ 32 │
│ 64 │
│ 128 │
│ 256 │
│ 512 │
│ 1024 │
│ 2048 │
│ 4096 │
│ 8192 │
│ 16384 │
│ 32768 │
│ 65536 │
│ 131072 │
│ 262144 │
│ 524288 │
│ 1048576 │
│ 2097152 │
│ 4194304 │
│ 8388608 │
│ 16777216 │
│ 33554432 │
│ 67108864 │
│ 134217728 │
│ 268435456 │
│ 536870912 │
│ 1073741824 │
│ 2147483648 │
│ 4294967296 │
│ 8589934592 │
│ 17179869184 │
│ 34359738368 │
│ 68719476736 │
│ 137438953472 │
│ 274877906944 │
│ 549755813888 │
│ 1099511627776 │
│ 2199023255552 │
│ 4398046511104 │
│ 8796093022208 │
│ 17592186044416 │
│ 35184372088832 │
│ 70368744177664 │
│ 140737488355328 │
│ 281474976710656 │
│ 562949953421312 │
│ 1125899906842624 │
│ 2251799813685248 │
│ 4503599627370496 │
│ 9007199254740992 │
│ 18014398509481984 │
│ 36028797018963968 │
│ 72057594037927936 │
│ 144115188075855872 │
│ 288230376151711744 │
│ 576460752303423488 │
│ 1152921504606846976 │
│ 2305843009213693952 │
│ 4611686018427387904 │
│ 9223372036854775808 │
│ 18446744073709551616 │
│ 36893488147419103232 │
│ 73786976294838206464 │
│ 147573952589676412928 │
│ 295147905179352825856 │
│ 590295810358705651712 │
│ 1180591620717411303424 │
│ 2361183241434822606848 │
│ 4722366482869645213696 │
│ 9444732965739290427392 │
│ 18889465931478580854784 │
│ 37778931862957161709568 │
│ 75557863725914323419136 │
│ 151115727451828646838272 │
│ 302231454903657293676544 │
│ 604462909807314587353088 │
│ 1208925819614629174706176 │
│ 2417851639229258349412352 │
│ 4835703278458516698824704 │
│ 9671406556917033397649408 │
│ 19342813113834066795298816 │
│ 38685626227668133590597632 │
│ 77371252455336267181195264 │
│ 154742504910672534362390528 │
│ 309485009821345068724781056 │
│ 618970019642690137449562112 │
│ 1237940039285380274899124224 │
│ 2475880078570760549798248448 │
│ 4951760157141521099596496896 │
│ 9903520314283042199192993792 │
│ 19807040628566084398385987584 │
│ 39614081257132168796771975168 │
│ 79228162514264337593543950336 │
│ 158456325028528675187087900672 │
│ 316912650057057350374175801344 │
│ 633825300114114700748351602688 │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Iterations 4
Total Time 175.15s
Input Tokens 11,104
Output Tokens 19,867
══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
RLMChatCompletion(root_model='gpt-5-nano', prompt='Print me the first 100 powers of two, each on a newline.', response='1\n2\n4\n8\n16\n32\n64\n128\n256\n512\n1024\n2048\n4096\n8192\n16384\n32768\n65536\n131072\n262144\n524288\n1048576\n2097152\n4194304\n8388608\n16777216\n33554432\n67108864\n134217728\n268435456\n536870912\n1073741824\n2147483648\n4294967296\n8589934592\n17179869184\n34359738368\n68719476736\n137438953472\n274877906944\n549755813888\n1099511627776\n2199023255552\n4398046511104\n8796093022208\n17592186044416\n35184372088832\n70368744177664\n140737488355328\n281474976710656\n562949953421312\n1125899906842624\n2251799813685248\n4503599627370496\n9007199254740992\n18014398509481984\n36028797018963968\n72057594037927936\n144115188075855872\n288230376151711744\n576460752303423488\n1152921504606846976\n2305843009213693952\n4611686018427387904\n9223372036854775808\n18446744073709551616\n36893488147419103232\n73786976294838206464\n147573952589676412928\n295147905179352825856\n590295810358705651712\n1180591620717411303424\n2361183241434822606848\n4722366482869645213696\n9444732965739290427392\n18889465931478580854784\n37778931862957161709568\n75557863725914323419136\n151115727451828646838272\n302231454903657293676544\n604462909807314587353088\n1208925819614629174706176\n2417851639229258349412352\n4835703278458516698824704\n9671406556917033397649408\n19342813113834066795298816\n38685626227668133590597632\n77371252455336267181195264\n154742504910672534362390528\n309485009821345068724781056\n618970019642690137449562112\n1237940039285380274899124224\n2475880078570760549798248448\n4951760157141521099596496896\n9903520314283042199192993792\n19807040628566084398385987584\n39614081257132168796771975168\n79228162514264337593543950336\n158456325028528675187087900672\n316912650057057350374175801344\n633825300114114700748351602688', usage_summary=UsageSummary(model_usage_summaries={'gpt-5-nano': ModelUsageSummary(total_calls=5, total_input_tokens=11104, total_output_tokens=19867)}), execution_time=175.15158712491393)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment