# How the Deepening Phase in ADHD Connects Ideas and What Output It Produces

> Explore the deepening phase in ADHD, where top ideas are refined with an LLM to generate detailed sketches, identify risks, and create child ideas, linking concepts to implementation.

- Repository: [Udit Akhouri/adhd](https://github.com/UditAkhourii/adhd)
- Tags: deep-dive
- Published: 2026-08-01

---

**The deepening phase in ADHD selects the top-ranked ideas from previous phases and uses an LLM to generate detailed sketches, identify risks, and spawn 3-5 child ideas, producing hierarchical `DeepenedIdea` objects that link parent concepts to concrete implementation details.**

The ADHD system implements a **tree-of-thought workflow** for structured brainstorming and problem-solving. After initial divergence, scoring, and clustering phases generate a pool of candidate ideas, the deepening phase—sometimes called the "focus" pass—connects these concepts by expanding the most promising candidates into detailed, actionable proposals. This article examines the implementation in the `UditAkhourii/adhd` repository to explain exactly how the system links ideas and what structured data it returns.

## How the Deepening Phase Fits into the ADHD Workflow

The ADHD engine follows a strict multi-phase pipeline: **diverge**, **score**, **cluster**, and finally **deepen**. While the first three phases focus on generating and filtering a broad set of ideas, the deepening phase acts as the "connecting the dots" pass. It takes the highest-quality ideas and enriches them with narrative context, risk analysis, and exploratory sub-ideas that recombine insights from the broader set.

## Selecting Top-K Ideas for Deepening

The engine initiates the deepening phase by extracting the top-K ranked ideas from the previous scoring phase, explicitly ignoring any ideas marked as trapped. In [`src/engine.ts`](https://github.com/UditAkhourii/adhd/blob/main/src/engine.ts) (lines 97–101), the selection logic slices the ranked array and maps each selected idea through an asynchronous deepening routine:

```ts
// PHASE 3 — FOCUS / DEEPEN top-K. This is the "connecting the dots" pass.
const toDeepen = ranked.slice(0, topK);
const deepened = await Promise.all(
  toDeepen.map((idea) =>
    limit(async () => {
      onEvent?.({ kind: "deepen:start", ideaId: idea.id, text: idea.text });
      const d = await deepenIdea(problem, idea, allIdeas, model);
      onEvent?.({ kind: "deepen:done", ideaId: idea.id });
      return d;
    })
  )
);

```

This concurrency-limited mapping ensures that each candidate idea receives dedicated LLM processing while respecting rate limits.

## The DeepenIdea Function: Connecting Concepts with LLM Reasoning

The core logic resides in the `deepenIdea` function, which constructs a prompt that supplies three critical inputs to the LLM:

- The original **problem statement**
- The **focus idea** selected for deepening
- A selection of **sibling ideas** from `allIdeas` to enable recombination and hybridization

The LLM receives instructions via the `DEEPEN_SYSTEM` prompt to produce a structured response that `zod` validates against `DeepenSchema` (defined in [`src/engine.ts`](https://github.com/UditAkhourii/adhd/blob/main/src/engine.ts), lines 48–53):

```ts
const DeepenSchema = z.object({
  sketch: z.string(),
  childIdeas: z.array(
    z.object({ text: z.string(), rationale: z.string().optional() })
  ),
});

```

The schema enforces that the LLM outputs a narrative **sketch** (4–8 sentences describing how the idea works, its load-bearing risk, and the first concrete implementation step) alongside an array of **3–5 child ideas** representing variations, hybrids, or unlocks of the original concept.

## Output Structure and Child Idea Generation

After parsing the LLM response against `DeepenSchema`, the function assembles a `DeepenedIdea` object (lines 99–109 in [`src/engine.ts`](https://github.com/UditAkhourii/adhd/blob/main/src/engine.ts)). The return structure explicitly links the enriched content back to the original idea:

```ts
return { ideaId: idea.id, sketch: parsed.sketch, childIdeas };

```

Each object contains:

- **`ideaId`**: The UUID of the parent idea being deepened
- **`sketch`**: The detailed narrative and risk assessment
- **`childIdeas`**: An array of new `Idea` objects, each receiving its own UUID, frame reference, and depth incremented to `parent.depth + 1`, with optional rationale strings explaining the connection to the parent

This hierarchical structure creates a richer, multi-layered view of the solution space, allowing the system in [`src/render.ts`](https://github.com/UditAkhourii/adhd/blob/main/src/render.ts) to display branching concept trees or feed results into subsequent engine runs for further expansion.

## Practical Implementation: Running the Deepening Phase

You can observe the deepening phase in action by executing the full engine pipeline. The `result.deepened` array contains all `DeepenedIdea` objects generated during the focus pass:

```ts
import { run } from "./engine";

const result = await run({
  problem: "How can we make remote pair-programming less disruptive?",
  framesPerRun: 5,
  ideasPerFrame: 6,
  topK: 3,
  model: "gpt-4o-mini",
});

console.log("Deepened ideas:");
for (const d of result.deepened) {
  console.log(`• ${d.sketch}`);
  for (const child of d.childIdeas) {
    console.log(`   – ${child.text}`);
  }
}

```

For unit testing or targeted expansion without running the full pipeline, import `deepenIdea` directly and provide the required context:

```ts
import { deepenIdea } from "./engine";
import { mockIdeas } from "./tests/fixtures";

const parent = mockIdeas[0];                 // an Idea object
const siblings = mockIdeas.slice(1, 5);      // other ideas for recombination
const deep = await deepenIdea(
  "Improve remote pair-programming experience",
  parent,
  siblings,
  "gpt-4o-mini"
);

console.log(deep.sketch);           // narrative of the focus idea
console.log(deep.childIdeas);      // array of sub-ideas

```

## Key Source Files

The deepening phase spans several modules in the `UditAkhourii/adhd` codebase:

- **[`src/engine.ts`](https://github.com/UditAkhourii/adhd/blob/main/src/engine.ts)**: Core orchestration logic that defines `DeepenSchema`, implements `deepenIdea`, and manages the top-K selection and concurrency limiting.
- **[`src/types.ts`](https://github.com/UditAkhourii/adhd/blob/main/src/types.ts)**: TypeScript definitions for `Idea`, `DeepenedIdea`, `Score`, and related interfaces used throughout the workflow.
- **[`src/frames.ts`](https://github.com/UditAkhourii/adhd/blob/main/src/frames.ts)**: Supplies the cognitive frames that guide initial divergent brainstorming; the deepening phase builds upon these foundational ideas.
- **[`src/llm.ts`](https://github.com/UditAkhourii/adhd/blob/main/src/llm.ts)**: Provides the `callLLM` wrapper and `parseJSON` utility that handle the actual LLM communication and schema-validated parsing.
- **[`src/render.ts`](https://github.com/UditAkhourii/adhd/blob/main/src/render.ts)**: Consumes the hierarchical `DeepenedIdea` output to generate human-readable reports or visual tree representations.

## Summary

- The deepening phase processes the **top-K ranked ideas** from previous phases, ignoring trapped entries to focus computational resources on high-potential concepts.
- The `deepenIdea` function in [`src/engine.ts`](https://github.com/UditAkhourii/adhd/blob/main/src/engine.ts) constructs LLM prompts that recombine the focus idea with sibling concepts from the broader idea pool.
- Output strictly follows `DeepenSchema`, generating a narrative **sketch** (4–8 sentences covering mechanics, risks, and first steps) plus **3–5 child ideas** with optional rationales.
- Results are structured as **`DeepenedIdea`** objects containing `ideaId`, `sketch`, and hierarchical `childIdeas` suitable for rendering or iterative re-expansion.

## Frequently Asked Questions

### What triggers the deepening phase in ADHD?

The deepening phase triggers automatically after the diverge, score, and cluster phases complete. The engine selects the highest-ranked ideas (configurable via the `topK` parameter) that have not been marked as trapped, then passes each one to the asynchronous `deepenIdea` routine for enrichment.

### How many child ideas does the deepening phase generate?

According to the `DeepenSchema` definition in [`src/engine.ts`](https://github.com/UditAkhourii/adhd/blob/main/src/engine.ts), the LLM generates between **3 and 5 child ideas** for each deepened concept. These represent variations, hybrids, or unlocks derived from the parent idea and its siblings.

### Can I run the deepening phase on a single idea without the full engine?

Yes. Import the `deepenIdea` function directly from [`src/engine.ts`](https://github.com/UditAkhourii/adhd/blob/main/src/engine.ts) and provide a problem statement string, the target `Idea` object, an array of sibling ideas for contextual recombination, and a model identifier (e.g., `"gpt-4o-mini"`). This approach is useful for isolated testing or when iteratively expanding specific concepts.

### What information does the sketch field contain?

The `sketch` field contains a structured narrative of **4–8 sentences** that describes how the idea works in practice, identifies the **load-bearing risk**, and outlines the **first concrete implementation step**. This transforms abstract brainstorming output into actionable project specifications.