` tokens internally can deliberate before emitting the structured output, which tends to give cleaner selections and more on-topic plans. The architecture works with any chat model (we run a Llama comparison in § 10), but Qwen-Thinking is the natural pairing for the SELECT and IMPLEMENT stages."
]
},
{
"cell_type": "markdown",
"id": "a32aeb58",
"metadata": {
"papermill": {
"duration": 0.008154,
"end_time": "2026-05-27T16:32:11.584211+00:00",
"exception": false,
"start_time": "2026-05-27T16:32:11.576057+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 4 · Setup"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "df562821",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-27T16:32:11.601851Z",
"iopub.status.busy": "2026-05-27T16:32:11.601851Z",
"iopub.status.idle": "2026-05-27T16:32:14.433056Z",
"shell.execute_reply": "2026-05-27T16:32:14.433056Z"
},
"papermill": {
"duration": 2.840341,
"end_time": "2026-05-27T16:32:14.433056+00:00",
"exception": false,
"start_time": "2026-05-27T16:32:11.592715+00:00",
"status": "completed"
},
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"Reasoning LLM: Qwen/Qwen3-235B-A22B-Thinking-2507-fast ────────────────────────────────────────────────────────────\n",
"\n"
],
"text/plain": [
"\u001b[1;36mReasoning LLM: Qwen/Qwen3-235B-A22B-Thinking-\u001b[0m\u001b[1;36m2507\u001b[0m\u001b[1;36m-fast\u001b[0m \u001b[92m────────────────────────────────────────────────────────────\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from agentic_architectures import get_llm, enable_langsmith, settings\n",
"from agentic_architectures.architectures import SelfDiscover\n",
"from agentic_architectures.ui import print_md, print_header, print_step\n",
"\n",
"enable_langsmith()\n",
"\n",
"# Per handoff §10, nb 19 defaults to Qwen3-Thinking (reasoning model).\n",
"reasoning_llm = get_llm(\n",
" provider=\"nebius\",\n",
" model=\"Qwen/Qwen3-235B-A22B-Thinking-2507-fast\",\n",
" temperature=0.4,\n",
")\n",
"print_header(f\"Reasoning LLM: {reasoning_llm.model}\")"
]
},
{
"cell_type": "markdown",
"id": "a5a29ae4",
"metadata": {
"papermill": {
"duration": 0.009077,
"end_time": "2026-05-27T16:32:14.450150+00:00",
"exception": false,
"start_time": "2026-05-27T16:32:14.441073+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 5 · Library walkthrough\n",
"\n",
"Source: [`src/agentic_architectures/architectures/self_discover.py`](../src/agentic_architectures/architectures/self_discover.py).\n",
"\n",
"The architecture exposes one constant and four schemas:\n",
"\n",
"- **`MODULE_LIBRARY`** — list of 16 atomic reasoning modules (replaceable via `modules=` constructor arg).\n",
"- **`_SelectedModules`** — Stage 1 output: indices into the library + rationale.\n",
"- **`_AdaptedModules`** — Stage 2 output: one rephrased module per selected.\n",
"- **`_ReasoningPlan`** — Stage 3 output: step list + final-answer format.\n",
"- **`_Solution`** — Stage 4 output: per-step outputs + final answer.\n",
"\n",
"Each is bound to the LLM via `with_structured_output()` in `__init__`, so the four nodes are trivial wrappers around `invoke(prompt)`."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "43b376c7",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-27T16:32:14.458772Z",
"iopub.status.busy": "2026-05-27T16:32:14.458772Z",
"iopub.status.idle": "2026-05-27T16:32:14.480769Z",
"shell.execute_reply": "2026-05-27T16:32:14.480769Z"
},
"papermill": {
"duration": 0.026009,
"end_time": "2026-05-27T16:32:14.480769+00:00",
"exception": false,
"start_time": "2026-05-27T16:32:14.454760+00:00",
"status": "completed"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MODULE_LIBRARY size: 16\n",
" [ 0] Critical thinking — question the question's assumptions and surface biases\n",
" [ 1] Break the problem into sub-problems and solve each\n",
" [ 2] Identify the type of problem (logic, math, classification, planning, ...)\n",
" [ 3] Identify the goal — what specifically must the final answer contain\n",
" [ 4] List the relevant facts, constraints, and unknowns\n",
" [ 5] Consider analogies — what problem is this structurally similar to?\n",
" [ 6] Brainstorm alternative interpretations of the question\n",
" [ 7] Step-by-step reasoning from premises to conclusion\n",
" [ 8] Consider counterexamples that would falsify a candidate answer\n",
" [ 9] Make a table, list, or diagram to organize the information\n",
" [10] Reverse-engineer from a candidate answer back to the premises\n",
" [11] Evaluate trade-offs between competing options explicitly\n",
" [12] Devise an algorithm or procedure that always finds the answer\n",
" [13] Synthesize multiple perspectives or stakeholder views\n",
" [14] Check consistency — does the candidate answer satisfy EVERY constraint?\n",
" [15] Self-verify — solve a second way and compare the two answers\n",
"\n",
"--- _SelectedModules schema ---\n",
"{\n",
" \"description\": \"Stage 1 output.\",\n",
" \"properties\": {\n",
" \"selected_ids\": {\n",
" \"description\": \"Indices (0-based) into the MODULE_LIBRARY of the atomic reasoning modules most relevant to this task type. Pick 3-6 \\u2014 enough to structure the reasoning, few enough to keep the plan focused.\",\n",
" \"items\": {\n",
" \"type\": \"integer\"\n",
" },\n",
" \"maxItems\": 8,\n",
" \"minItems\": 2,\n",
" \"ti...\n",
"\n",
"--- _ReasoningPlan schema ---\n",
"{\n",
" \"$defs\": {\n",
" \"_PlanStep\": {\n",
" \"properties\": {\n",
" \"step_number\": {\n",
" \"description\": \"1-indexed step number.\",\n",
" \"minimum\": 1,\n",
" \"title\": \"Step Number\",\n",
" \"type\": \"integer\"\n",
" },\n",
" \"description\": {\n",
" \"description\": \"What the solver does in this step. Reference which adapted module(s) this step draws on.\",\n",
" \"title\": \"Descripti...\n"
]
}
],
"source": [
"from agentic_architectures.architectures.self_discover import (\n",
" MODULE_LIBRARY, _SelectedModules, _ReasoningPlan,\n",
")\n",
"import json\n",
"\n",
"print(f\"MODULE_LIBRARY size: {len(MODULE_LIBRARY)}\")\n",
"for i, m in enumerate(MODULE_LIBRARY):\n",
" print(f\" [{i:2d}] {m}\")\n",
"print()\n",
"print('--- _SelectedModules schema ---')\n",
"print(json.dumps(_SelectedModules.model_json_schema(), indent=2)[:400] + '...')\n",
"print()\n",
"print('--- _ReasoningPlan schema ---')\n",
"print(json.dumps(_ReasoningPlan.model_json_schema(), indent=2)[:400] + '...')"
]
},
{
"cell_type": "markdown",
"id": "296c0a5a",
"metadata": {
"papermill": {
"duration": 0.015901,
"end_time": "2026-05-27T16:32:14.496670+00:00",
"exception": false,
"start_time": "2026-05-27T16:32:14.480769+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 6 · State"
]
},
{
"cell_type": "markdown",
"id": "279eccac",
"metadata": {
"papermill": {
"duration": 0.007373,
"end_time": "2026-05-27T16:32:14.511099+00:00",
"exception": false,
"start_time": "2026-05-27T16:32:14.503726+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"| Field | Set by | Notes |\n",
"|---|---|---|\n",
"| `task` | caller | The single task to solve |\n",
"| `selected_ids` / `selected_modules` / `selection_rationale` | `_select` | Stage 1 commitment |\n",
"| `adapted_modules` | `_adapt` | List of `{original, adapted}` pairs |\n",
"| `plan_steps` / `final_answer_format` | `_implement` | The reasoning recipe |\n",
"| `step_outputs` / `final_answer` | `_solve` | Stage 4 execution result |\n",
"| `history` | every node (Annotated `operator.add`) | One entry per stage |"
]
},
{
"cell_type": "markdown",
"id": "61b9dcf7",
"metadata": {
"papermill": {
"duration": 0.005017,
"end_time": "2026-05-27T16:32:14.521057+00:00",
"exception": false,
"start_time": "2026-05-27T16:32:14.516040+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 7 · Build the graph"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "8730ba8f",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-27T16:32:14.536760Z",
"iopub.status.busy": "2026-05-27T16:32:14.534750Z",
"iopub.status.idle": "2026-05-27T16:32:17.355880Z",
"shell.execute_reply": "2026-05-27T16:32:17.355880Z"
},
"papermill": {
"duration": 2.834823,
"end_time": "2026-05-27T16:32:17.355880+00:00",
"exception": false,
"start_time": "2026-05-27T16:32:14.521057+00:00",
"status": "completed"
},
"tags": []
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAHgAAAITCAIAA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ba8Bs/2Dbh0NDftRkZQXesd3lBh+/w/1ocfql3di4rzrW4K8o96c+J3CB9z/h1T0SaobTKMlXuPqNVs/MgvK9rrxskUcLq0o5goAAAB6klEQVQ8vG2Jf2Njn+HhrelxZ/Ibx0RY3Qq3kZNrvYkLSjml0nqRTdMKb68AhI/MrArbjnX6YqWLFb0UjNLTs8Lm3yv7Eoe+E+IXYkunku2ds6tmJbi6K8NbPS2W+tqftzx8mGHv2Dhfme2V6YkLo/IztYV5Regp4E7cfY7lbFYZVbMXvN/koMTTacjZeXArOyc1f9Li2qgaVHcATW6mbv1HyfWeq6lUK5EzknotI+t27pTPnugAGtOlJBZt/+aOh786vEUQci6uHb9l0LLVVxlhHOS46v2brIHyq+PlF+qN5M/tf+5lpxRovKjX5lfLYpjBOWx338bU+AsF0MoDHWuhTf1puzVb24+iHO2daxnaHB1Fow4v+rTq4oMwgX8g+r4f0xKvFOq1LM1QtIJilAzD0MLksOaTGv+aJ39F5kZmfq5ZqsxkqNaXzdOochS/j+VWYYZaYRt/NMsdHw5ER6W7UMbP6Ax6rkQHHTj87KhKDdXsGc/2vf0RVuz4acWJPfdu3yjWFRn0xZxWazCP+Bd0sHpaeBacxSbLIfqmv+ihbqWfYvDtluZjmhI8fH5mUUsVfriVZhBrgK5I5KKkFS5I46mIaKhpFYMtC5dDfnPOyhRZRtuVI0RoiSBCSwQRWiKI0BJBhJaI/wcAAP//qEo84QAAAAZJREFUAwCEeKcH8ZnMZwAAAABJRU5ErkJggg==",
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from IPython.display import Image, display\n",
"arch = SelfDiscover(llm=reasoning_llm)\n",
"graph = arch.build()\n",
"display(Image(graph.get_graph().draw_mermaid_png()))"
]
},
{
"cell_type": "markdown",
"id": "6259bf3f",
"metadata": {
"papermill": {
"duration": 0.006722,
"end_time": "2026-05-27T16:32:17.372171+00:00",
"exception": false,
"start_time": "2026-05-27T16:32:17.365449+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 8 · Live run — 5-musician height ordering puzzle\n",
"\n",
"A small logic-deduction task with a unique answer (`Dee, Cal, Bea, Alex, Ed`). We watch the agent pick reasoning modules, adapt them to musicians-and-heights language, write a step plan, and execute."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "95cfe293",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-27T16:32:17.401095Z",
"iopub.status.busy": "2026-05-27T16:32:17.401095Z",
"iopub.status.idle": "2026-05-27T16:33:42.968632Z",
"shell.execute_reply": "2026-05-27T16:33:42.966618Z"
},
"papermill": {
"duration": 85.583494,
"end_time": "2026-05-27T16:33:42.974665+00:00",
"exception": false,
"start_time": "2026-05-27T16:32:17.391171+00:00",
"status": "completed"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SELECTED_IDS: [1, 4, 7, 9, 14]\n",
"SELECTED_COUNT: 5\n",
" module: Break the problem into sub-problems and solve each\n",
" module: List the relevant facts, constraints, and unknowns\n",
" module: Step-by-step reasoning from premises to conclusion\n",
" module: Make a table, list, or diagram to organize the information\n",
" module: Check consistency — does the candidate answer satisfy EVERY constraint?\n",
"\n",
"PLAN_STEP_COUNT: 4\n",
" step 1: List all height facts (Bea shorter than Cal, Dee taller than Cal, Ed shortest) and identify unknown positions using adap\n",
" → expected_output: A structured list of given constraints and unknown relationships (e.g., Alex's position relative to others)\n",
" step 2: Resolve each constraint sequentially starting with Ed as the shortest, then Bea < Cal, and Dee > Cal using adapted modul\n",
" → expected_output: Partial orderings (Ed fixed at position 5, Cal > Bea, Dee > Cal)\n",
" step 3: Integrate all deductions to determine Alex's position between Bea and Ed using adapted module 3.\n",
" → expected_output: Complete relative sequence (Dee > Cal > Bea > Alex > Ed)\n",
" step 4: Construct the final height ranking chart formalizing the sequence using adapted module 4.\n",
" → expected_output: A comma-separated list of musicians from tallest to shortest\n",
"\n",
"FINAL_ANSWER_FORMAT: a single comma-separated list of names from tallest to shortest\n",
"FINAL_ANSWER: Dee,Cal,Bea,Alex,Ed\n",
"EXPECTED: Dee, Cal, Bea, Alex, Ed\n",
"MATCH: True\n"
]
}
],
"source": [
"TASK = (\n",
" \"Five musicians (Alex, Bea, Cal, Dee, Ed) line up by height for a photo.\\n\"\n",
" \"Constraints:\\n\"\n",
" \" - Bea is shorter than Cal but taller than Alex.\\n\"\n",
" \" - Dee is taller than Cal.\\n\"\n",
" \" - Ed is the shortest.\\n\"\n",
" \"List the musicians from TALLEST to SHORTEST as a comma-separated list.\"\n",
")\n",
"EXPECTED = \"Dee, Cal, Bea, Alex, Ed\"\n",
"\n",
"r = arch.run(TASK)\n",
"\n",
"# Normalise for comparison: strip spaces so 'Dee,Cal,...' equals 'Dee, Cal, ...'\n",
"def _norm(s):\n",
" return ''.join(s.split()).lower()\n",
"match = _norm(r.output) == _norm(EXPECTED)\n",
"\n",
"print(f\"SELECTED_IDS: {r.metadata['selected_ids']}\")\n",
"print(f\"SELECTED_COUNT: {len(r.metadata['selected_modules'])}\")\n",
"for m in r.metadata['selected_modules']:\n",
" print(f\" module: {m}\")\n",
"print()\n",
"print(f\"PLAN_STEP_COUNT: {r.metadata['plan_step_count']}\")\n",
"for s in r.metadata['plan_steps']:\n",
" print(f\" step {s['step_number']}: {s['description'][:120]}\")\n",
" print(f\" → expected_output: {s['expected_output'][:120]}\")\n",
"print()\n",
"print(f\"FINAL_ANSWER_FORMAT: {r.metadata['final_answer_format']}\")\n",
"print(f\"FINAL_ANSWER: {r.output}\")\n",
"print(f\"EXPECTED: {EXPECTED}\")\n",
"print(f\"MATCH: {match}\")"
]
},
{
"cell_type": "markdown",
"id": "49539dab",
"metadata": {
"papermill": {
"duration": 0.0,
"end_time": "2026-05-27T16:33:42.982486+00:00",
"exception": false,
"start_time": "2026-05-27T16:33:42.982486+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"### 8.0 · What just happened, briefly\n",
"\n",
"Three signals to read:\n",
"\n",
"1. **`SELECTED_COUNT` between 3 and 6.** Outside that range = SELECT mis-calibrated; either too narrow (loses useful modules) or too broad (plan becomes incoherent).\n",
"2. **`PLAN_STEP_COUNT` between 3 and 7.** Plans with 1-2 steps mean IMPLEMENT collapsed the modules; plans with 8+ mean it over-decomposed.\n",
"3. **`MATCH=True`** for the answer. The puzzle has a unique solution; if MATCH is False, look at the step outputs to see where the deduction broke."
]
},
{
"cell_type": "markdown",
"id": "f8518d31",
"metadata": {
"papermill": {
"duration": 0.0,
"end_time": "2026-05-27T16:33:42.998632+00:00",
"exception": false,
"start_time": "2026-05-27T16:33:42.998632+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"### 8.1 · Inspect the adapted modules + step outputs"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "3c74f0d6",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-27T16:33:43.016243Z",
"iopub.status.busy": "2026-05-27T16:33:43.016243Z",
"iopub.status.idle": "2026-05-27T16:33:43.032803Z",
"shell.execute_reply": "2026-05-27T16:33:43.030844Z"
},
"papermill": {
"duration": 0.018067,
"end_time": "2026-05-27T16:33:43.032803+00:00",
"exception": false,
"start_time": "2026-05-27T16:33:43.014736+00:00",
"status": "completed"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"=== ADAPTED MODULES ===\n",
"[1] original: Break the problem into sub-problems and solve each\n",
" adapted : Break the height lineup problem into specific musician constraints (Bea shorter than Cal, Dee taller than Cal, Ed shortest) and resolve each sequentially\n",
"\n",
"[2] original: List the relevant facts, constraints, and unknowns\n",
" adapted : List the height facts (Bea shorter than Cal, Dee taller than Cal, Ed shortest), constraints, and unknown musician positions\n",
"\n",
"[3] original: Step-by-step reasoning from premises to conclusion\n",
" adapted : Step-by-step deduction from height premises (Bea shorter than Cal, Dee taller than Cal, Ed shortest) to final tallest-to-shortest lineup\n",
"\n",
"[4] original: Make a table, list, or diagram to organize the information\n",
" adapted : Construct a height ranking chart for Alex, Bea, Cal, Dee, Ed using the given constraints\n",
"\n",
"[5] original: Check consistency — does the candidate answer satisfy EVERY constraint?\n",
" adapted : Verify the proposed height order satisfies all constraints: Bea shorter than Cal, Dee taller than Cal, and Ed being the shortest\n",
"\n",
"=== STEP-BY-STEP EXECUTION OUTPUT ===\n",
"[step 1] Constraints: Bea < Cal, Bea > Alex, Dee > Cal, Ed shortest. Unknown: Alex's position relative to Cal/Dee and Ed's exact placement.\n",
"[step 2] Ed fixed at position 5 (shortest). Cal > Bea > Alex established. Dee > Cal confirmed.\n",
"[step 3] Alex must be between Bea and Ed (Bea > Alex > Ed), completing the sequence Dee > Cal > Bea > Alex > Ed.\n",
"[step 4] Final ranking: Dee, Cal, Bea, Alex, Ed\n"
]
}
],
"source": [
"print('=== ADAPTED MODULES ===')\n",
"for i, a in enumerate(r.metadata['adapted_modules'], 1):\n",
" print(f\"[{i}] original: {a['original'][:80]}\")\n",
" print(f\" adapted : {a['adapted'][:200]}\")\n",
" print()\n",
"\n",
"print('=== STEP-BY-STEP EXECUTION OUTPUT ===')\n",
"for i, out in enumerate(r.metadata['step_outputs'], 1):\n",
" print(f\"[step {i}] {out}\")"
]
},
{
"cell_type": "markdown",
"id": "85e533f5",
"metadata": {
"papermill": {
"duration": 0.009973,
"end_time": "2026-05-27T16:33:43.051884+00:00",
"exception": false,
"start_time": "2026-05-27T16:33:43.041911+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 9 · What we just observed\n",
"\n",
"The cells above ran the SELECT → ADAPT → IMPLEMENT → SOLVE pipeline on a 5-musician height-ordering puzzle, then re-ran the same puzzle with a plain (non-reasoning) LLM for contrast.\n",
"\n",
"### 9.1 · The recipe the reasoning model designed\n",
"\n",
"**Stage 1 — SELECT** picked these modules from the 16-module library:\n",
"\n",
"| id | module |\n",
"|---|---|\n",
"| `[1]` | Break the problem into sub-problems and solve each |\n",
"| `[4]` | List the relevant facts, constraints, and unknowns |\n",
"| `[7]` | Step-by-step reasoning from premises to conclusion |\n",
"| `[9]` | Make a table, list, or diagram to organize the information |\n",
"| `[14]` | Check consistency — does the candidate answer satisfy EVERY constraint? |\n",
"\n",
"**Stage 3 — IMPLEMENT** composed them into this plan:\n",
"\n",
"| # | description | expected output |\n",
"|---|---|---|\n",
"| 1 | List all height facts (Bea shorter than Cal, Dee taller than Cal, Ed shortest) and identify unknown positions using adap | A structured list of given constraints and unknown relationships (e.g., Alex's position relative to others) |\n",
"| 2 | Resolve each constraint sequentially starting with Ed as the shortest, then Bea < Cal, and Dee > Cal using adapted modul | Partial orderings (Ed fixed at position 5, Cal > Bea, Dee > Cal) |\n",
"| 3 | Integrate all deductions to determine Alex's position between Bea and Ed using adapted module 3. | Complete relative sequence (Dee > Cal > Bea > Alex > Ed) |\n",
"| 4 | Construct the final height ranking chart formalizing the sequence using adapted module 4. | A comma-separated list of musicians from tallest to shortest |\n",
"\n",
"**Run summary:**\n",
"\n",
"| Field | Value |\n",
"|---|---|\n",
"| SELECTED modules | 5 of 16 |\n",
"| Module ids | `[1, 4, 7, 9, 14]` |\n",
"| PLAN steps | 4 |\n",
"| Final-answer format | a single comma-separated list of names from tallest to shortest |\n",
"| Final answer | `Dee,Cal,Bea,Alex,Ed` |\n",
"| Expected | `Dee, Cal, Bea, Alex, Ed` |\n",
"| Match | ✅ |\n",
"\n",
"### 9.2 · Reasoning vs non-reasoning LLM on the same task\n",
"\n",
"| Model | SELECT count | PLAN steps | Final answer | Match |\n",
"|---|---|---|---|---|\n",
"| Reasoning (Qwen3-Thinking) | 5 | 4 | `Dee,Cal,Bea,Alex,Ed` | ✅ |\n",
"| Plain (Llama-3.3-70B) | 4 | 5 | `Dee,Cal,Bea,Alex,Ed` | ✅ |\n",
"\n",
"### 9.3 · Patterns surfaced in this run\n",
"\n",
"- **✅ SELECT picked 5 modules** — inside the recommended 3-6 range.\n",
"\n",
"- **✅ SOLVE produced the expected answer** — the discovered structure executed correctly.\n",
"\n",
"- **🟰 Both reasoning and plain LLM converged on the correct answer.** On this puzzle, the structure-discovery pipeline produced sensible recipes for both — the underlying model's reasoning depth wasn't the bottleneck. Bigger differentiation would show on harder logic-deduction tasks (e.g., 7-element ordering with multi-hop transitivity).\n",
"\n",
"- **Structure divergence**: the two models chose different module counts / plan lengths (5/4 vs 4/5). Self-Discover's recipe is LLM-specific, not task-specific — same task, different model = different reasoning shape.\n",
"\n",
"### 9.4 · The takeaway\n",
"\n",
"Self-Discover converts the implicit \"how should I think about this?\" choice into an *explicit, inspectable* artefact (the plan in § 9.1). Two consequences:\n",
"\n",
"1. **Plans are auditable.** Unlike chain-of-thought scratchpad, the recipe is structured Pydantic data — you can save it, diff it across model versions, or hand-edit it before SOLVE runs.\n",
"2. **Plans are reusable.** Tasks of the same type share a recipe; SELECT/ADAPT/IMPLEMENT only need to run once per task family. § 11.3 extension #1 sketches a `discover() + solve()` split that makes this concrete and cuts cost 4×.\n",
"\n",
"The architecture's headline behaviour is that the *reasoning structure* itself becomes a first-class object the agent decides on, rather than an emergent property of a fixed CoT prompt. Whether that produces a better *answer* depends on the underlying model (§ 9.2 above) — but it always produces a more *transparent* one."
]
},
{
"cell_type": "markdown",
"id": "6c1c3aba",
"metadata": {
"papermill": {
"duration": 0.006686,
"end_time": "2026-05-27T16:33:43.068076+00:00",
"exception": false,
"start_time": "2026-05-27T16:33:43.061390+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 10 · Contrast — same task, plain Llama-3.3-70B (no thinking)\n",
"\n",
"Self-Discover should work with any chat model — but a non-reasoning LLM may pick weaker modules or write a shallower plan. Re-run the same puzzle with Llama-3.3-70B and compare."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "1636db63",
"metadata": {
"execution": {
"iopub.execute_input": "2026-05-27T16:33:43.076777Z",
"iopub.status.busy": "2026-05-27T16:33:43.076777Z",
"iopub.status.idle": "2026-05-27T16:34:01.706995Z",
"shell.execute_reply": "2026-05-27T16:34:01.703608Z"
},
"papermill": {
"duration": 18.638919,
"end_time": "2026-05-27T16:34:01.706995+00:00",
"exception": false,
"start_time": "2026-05-27T16:33:43.068076+00:00",
"status": "completed"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"LLAMA_SELECTED_COUNT: 4\n",
"LLAMA_PLAN_STEP_COUNT: 5\n",
"LLAMA_FINAL_ANSWER: Dee,Cal,Bea,Alex,Ed\n",
"LLAMA_MATCH: True\n",
"\n",
"(Reasoning model picked 5 modules / 4 plan steps; Llama picked 4 / 5.)\n"
]
}
],
"source": [
"plain_llm = get_llm(provider=\"nebius\", model=\"meta-llama/Llama-3.3-70B-Instruct\", temperature=0.4)\n",
"arch_llama = SelfDiscover(llm=plain_llm)\n",
"r_llama = arch_llama.run(TASK)\n",
"\n",
"match_llama = _norm(r_llama.output) == _norm(EXPECTED)\n",
"print(f\"LLAMA_SELECTED_COUNT: {len(r_llama.metadata['selected_modules'])}\")\n",
"print(f\"LLAMA_PLAN_STEP_COUNT: {r_llama.metadata['plan_step_count']}\")\n",
"print(f\"LLAMA_FINAL_ANSWER: {r_llama.output}\")\n",
"print(f\"LLAMA_MATCH: {match_llama}\")\n",
"print()\n",
"print(f\"(Reasoning model picked {len(r.metadata['selected_modules'])} modules / \"\n",
" f\"{r.metadata['plan_step_count']} plan steps; Llama picked \"\n",
" f\"{len(r_llama.metadata['selected_modules'])} / {r_llama.metadata['plan_step_count']}.)\")"
]
},
{
"cell_type": "markdown",
"id": "c1fc78e6",
"metadata": {
"papermill": {
"duration": 0.00662,
"end_time": "2026-05-27T16:34:01.727499+00:00",
"exception": false,
"start_time": "2026-05-27T16:34:01.720879+00:00",
"status": "completed"
},
"tags": []
},
"source": [
"## 11 · Failure modes, safety, extensions\n",
"\n",
"### 11.1 · Where this breaks\n",
"\n",
"| Failure | Mechanism | Mitigation |\n",
"|---|---|---|\n",
"| **Over-selection** | LLM picks 8+ modules; plan becomes a kitchen sink | `_SelectedModules.selected_ids` is `max_length=8` — and the prompt asks for 3-6 |\n",
"| **Hallucinated module ids** | LLM returns an id outside `[0, len-1)` | The `_select` node clamps to the valid range silently before passing on |\n",
"| **Plan-execution mismatch** | SOLVE doesn't actually follow the plan; produces an unstructured answer | The `_Solution.step_outputs` field enforces one entry per plan step, which forces the model to address each step explicitly |\n",
"| **Module library too small / too generic** | No module fits the task type | Replace `MODULE_LIBRARY` via the `modules=` constructor arg with a domain-specific list |\n",
"| **Non-reasoning model under-decomposes** | Llama (vs Qwen-Thinking) picks fewer/shallower modules | Use a reasoning model for the SELECT/IMPLEMENT stages even if SOLVE runs on a cheaper LLM |\n",
"\n",
"### 11.2 · Production safety\n",
"\n",
"- **Plan caching.** SELECT/ADAPT/IMPLEMENT depend only on task TYPE, not on the specific instance. Cache the plan per task-template, then only run SOLVE per instance — 4× cost reduction.\n",
"- **Plan review.** For high-stakes tasks, surface the plan to a human reviewer before SOLVE runs. The plan is interpretable text by design.\n",
"- **Module library audit.** Generic modules (\"step-by-step\") can hide bias; domain-specific modules sometimes leak unsafe heuristics. Treat `MODULE_LIBRARY` as a policy artefact.\n",
"\n",
"### 11.3 · Three extensions\n",
"\n",
"1. **Plan reuse across instances.** Split `.run()` into `.discover(task_type)` (returns a plan) and `.solve(instance, plan)` (just SOLVE). Many tasks of the same type → one plan, many solutions.\n",
"2. **Hierarchical plans.** Each plan step can itself trigger a nested Self-Discover for that sub-problem. Useful when the task is genuinely tree-shaped.\n",
"3. **Cross-task module learning.** Track which module subsets succeed on which task families; bias future SELECT calls toward proven combos. Lets the architecture \"learn\" without weight updates — and dovetails neatly with [Reflexion (nb 18)](./18_reflexion.ipynb)'s episodic memory.\n",
"\n",
"### 11.4 · What to read next\n",
"\n",
"- [**09 · Tree of Thoughts**](./09_tree_of_thoughts.ipynb) — search-in-thought-space, sibling reasoning architecture.\n",
"- [**04 · Planning**](./04_planning.ipynb) — Planning over *actions*; composes cleanly with Self-Discover's reasoning-plan.\n",
"- [**18 · Reflexion**](./18_reflexion.ipynb) — verbal memory of failures; useful for extension #3 above.\n",
"- [**22 · LATS**](./22_lats.ipynb) — MCTS-style reasoning search with explicit reward signals.\n",
"\n",
"### 11.5 · References\n",
"\n",
"1. Zhou, P. et al. *Self-Discover: Large Language Models Self-Compose Reasoning Structures.* 2024. [arXiv:2402.03620](https://arxiv.org/abs/2402.03620)\n",
"2. Wei, J. et al. *Chain-of-Thought Prompting Elicits Reasoning in Large Language Models.* NeurIPS 2022. [arXiv:2201.11903](https://arxiv.org/abs/2201.11903) — the baseline Self-Discover improves on.\n",
"3. Yao, S. et al. *Tree of Thoughts: Deliberate Problem Solving with Large Language Models.* NeurIPS 2023. [arXiv:2305.10601](https://arxiv.org/abs/2305.10601) — sibling structured-reasoning architecture."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
},
"papermill": {
"default_parameters": {},
"duration": 113.816524,
"end_time": "2026-05-27T16:34:02.845314+00:00",
"environment_variables": {},
"exception": null,
"input_path": "all-agentic-architectures/notebooks/19_self_discover.ipynb",
"output_path": "all-agentic-architectures/notebooks/19_self_discover.ipynb",
"parameters": {},
"start_time": "2026-05-27T16:32:09.028790+00:00",
"version": "2.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}