How the "Focus" Phase Deepens Surviving Reasoning Paths in ADHD
The "Focus" phase in ADHD selects the highest-scoring ideas and prompts the LLM to flesh them out into actionable design sketches, surface load-bearing risks, and spawn sub-variations—creating recursive, deepened reasoning paths.
The ADHD engine is an open-source recursive reasoning system that helps developers explore complex problems through structured divergence and refinement. Understanding how the Focus phase deepens surviving reasoning paths is essential for anyone building on or extending the engine. In src/engine.ts, the Focus phase transforms raw scored ideas into enriched, actionable designs with explicit risk assessment and next-step branching.
What Survives to the Focus Phase?
Before "Focus" begins, the engine runs two prior phases: Diverge (generate raw ideas) and Score + Cluster (evaluate and group them). Only ideas that survive this filtering pipeline become candidates for deepening.
The selection logic is straightforward. Once all ideas receive composite total scores, the runner sorts descending and slices the top-K entries:
// src/engine.ts lines 80-99
const ranked = scored.sort((a, b) => b.score.total - a.score.total);
const survivors = ranked.slice(0, topK); // default topK = 3
These survivors represent the most promising reasoning paths—the ones whose novelty, utility, feasibility, and elegance scores outperformed their peers.
The Deepening Process: Four Structured Steps
For each survivor, the Focus phase executes a precise, repeatable workflow.
1. Focus System Prompt
Each survivor is submitted to the LLM with a dedicated DEEPEN_SYSTEM prompt defined at lines 15-22 in src/engine.ts:
const DEEPEN_SYSTEM = `You are a senior engineer deepening a promising solution idea.
Sketch a concrete implementation (4-8 sentences).
Identify the load-bearing risk.
State the first concrete step.
Generate 3-5 sub-ideas (variations, hybrid combos, unlocks).`;
This prompt forces specificity: no vague hand-waving, only concrete implementation details and actionable next steps.
2. JSON Parsing with Schema Validation
The LLM response is validated against DeepenSchema, which enforces structure at lines 48-53:
const DeepenSchema = z.object({
sketch: z.string().min(20),
loadBearingRisk: z.string(),
firstStep: z.string(),
childIdeas: z.array(z.object({
text: z.string(),
rationale: z.string()
})).length(3, 5)
});
Parsing failures trigger a fallback placeholder—ensuring the pipeline remains robust even with malformed responses.
3. Recursive Depth Expansion
Each validated childIdea is instantiated as a new Idea node with incremented depth and parent linkage. From lines 100-107 in src/engine.ts:
const deepenedChild: Idea = {
...childIdea,
id: generateId(),
parentId: survivor.id,
depth: survivor.depth + 1,
phase: 'focus'
};
This recursive embedding creates a tree of reasoning paths where every deepened branch can itself become a candidate for future divergence.
4. Output Structure
The final DeepenedIdea contains:
- sketch: Concrete 4-8 sentence implementation outline
- loadBearingRisk: The single highest-impact failure mode
- firstStep: Immediate actionable task for a developer
- childIdeas: 3-5 sub-variations exploring adjacent solution spaces
Running the Focus Phase in Practice
Complete Engine Execution
import { run } from "./src/engine.js";
(async () => {
const result = await run({
problem: "How can we reduce latency in our microservice architecture?",
context: undefined,
framesPerRun: 5,
ideasPerFrame: 6,
topK: 3, // survivors entering Focus
concurrency: 4,
codeMode: true,
stripAnchors: true,
model: "gpt-4o-mini",
criticModel: "gpt-4o"
});
console.dir(result.deepened, { depth: null });
})();
Inspecting Deepened Branches
result.deepened.forEach((d) => {
console.log("=== Deepened Idea ===");
console.log("Sketch:", d.sketch);
console.log("First step:", d.firstStep);
console.log("Risk:", d.loadBearingRisk);
console.log("Sub-variations:", d.childIdeas.length);
});
Why This Design Deepens Reasoning
The Focus phase solves a critical problem in generative ideation systems: breadth without depth produces shallow idea pools. By constraining deepening to top-scored survivors, ADHD allocates computational resources efficiently. The explicit risk identification prevents optimistic blindness. The sub-idea generation ensures exploration continues recursively rather than terminating on a single "winning" concept.
As implemented in UditAkhourii/adhd, this architecture mirrors how experienced engineers actually work: generate many options, filter ruthlessly, then elaborate promising candidates with concrete implementation thinking and explicit risk acknowledgment.
Key Source Files
| File | Purpose |
|---|---|
src/engine.ts |
Core orchestration; DEEPEN_SYSTEM prompt, deepenIdea() function, survivor selection logic |
src/types.ts |
Idea, DeepenedIdea, Score type definitions |
src/llm.ts |
callLLM() wrapper and parseJSON() utilities |
src/frames.ts |
Divergent framing logic feeding early-phase idea generation |
Summary
- The Focus phase operates only on top-K survivors selected by composite
totalscore ranking. - The
DEEPEN_SYSTEMprompt insrc/engine.tsenforces structured output: implementation sketch, risk identification, first step, and sub-variations. - Child ideas inherit
parentIdand incrementeddepth, creating traceable, recursive reasoning trees. - Schema validation via
DeepenSchemaensures consistent, parseable outputs with fallback handling. - This design pattern—filter, then deepen, then branch—optimizes exploration depth while maintaining resource efficiency.
Frequently Asked Questions
How does the Focus phase select which ideas to deepen?
Only ideas ranking in the top-K by composite total score proceed to Focus. The engine sorts all scored ideas descending and slices ranked.slice(0, topK) where topK defaults to 3. This ensures deepening resources target the highest-quality candidates.
What happens if the LLM returns malformed JSON during deepening?
The parseJSON() utility in src/llm.ts attempts strict parsing against DeepenSchema. On failure, the engine falls back to a placeholder structure with empty fields, allowing the pipeline to continue without crashing.
Can child ideas from Focus re-enter the Diverge phase?
Yes. Child ideas are instantiated as full Idea objects with incremented depth and parentId linkage. While the current implementation completes after one deepening cycle, the data structure supports iterative re-processing—future versions could recursively feed child ideas back through the full engine loop.
Why separate load-bearing risk from general risk listing?
The prompt explicitly asks for the load-bearing risk—singular, highest-impact failure mode—rather than an enumerated list. This forces prioritization and mimics how senior engineers identify which single assumption, if wrong, collapses the entire approach.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →