adhd

库

UditAkhourii/adhd

面向编码代理的并行发散思维树状思维技能。

项目简介

ADHD 实现带剪枝的思维树,在隔离认知框架下并行发散推理,避免过早收敛。通过评分、修剪陷阱并深化幸存者,增强 AI 代理的创造力与跨学科工作能力。

README 预览

\n  \n    \n  \n\n\n# ADHD — a skill for agents\n\n[](https://github.com/UditAkhourii/adhd/actions/workflows/ci.yml)\n[](https://www.npmjs.com/package/adhd-agent)\n[](./LICENSE)\n[](./documentation/install.md)\n[](https://adhdstack.github.io/)\n[](https://thenewstack.io/claude-code-adhd/)\n[](https://discord.gg/NbWwkwwGw)\n\n\n\n> ### 🎮 [**Join the ADHD Discord →**](https://discord.gg/NbWwkwwGw)\n> This is where the real-time thinking happens: frame design, eval problems, trap-hunting, and neurodivergence-inspired research on reasoning architectures. If you've got opinions on premature convergence, cognitive frames, or just want to argue about the next eval problem — **[come argue with us live](https://discord.gg/NbWwkwwGw).**\n\n> 👉 [**Join the ADHD community →**](https://tally.so/r/WO1Nzj) as a contributor, maintainer, early adopter, or just a member. One short form. We coordinate frame contributions, eval problems, integrations, and adopter onboarding there.\n\n> **An architectural fix for premature convergence in autoregressive reasoning.**\n\nLinear Chain-of-Thought anchors on whatever it says first. Tree-of-Thought widens the search but still walks a single shared context, so the anchoring persists across branches. **ADHD treats this as an architectural problem, not a prompting one** — it spawns N isolated reasoning processes under deliberately distorted cognitive frames, with zero shared context during divergence, then runs a separate critic pass to score, cluster, prune traps, and deepen the survivors.\n\nReach for it on **design decisions, fuzzy debugging, naming, API surface design, strategy, and any prompt of the shape *"give me a few ways to…"***.\n\n📄 **Preprint:** [ADHD: Parallel Divergent Ideation for Coding Agents](https://adhdstack.github.io/) · 👤 **Author:** Udit Akhouri — [@akhouriudit](https://x.com/akhouriudit) · [LinkedIn](https://www.linkedin.com/in/udit-akhouri-10160a168/)\n\n---\n\n## Side-by-side: baseline vs ADHD\n\nOne eval problem, s

常见问题 (2)

故障排除
如何修复运行 `adhd --frames 1` 时通配符帧大约有一半时间丢失的问题?

这是 src/frames.ts 中 selectFrames() 在 n === 1 时存在的一个 bug。它会随机选取一帧,追加通配帧,然后最后的 .slice(0, n) 会将该通配帧移除,除非第一帧本身就已带有 wild 标记。

**临时解决办法:** 使用 --frames 2 或更大的值。当 n >= 2 时,通配帧保证机制可以正常工作:

adhd "your prompt" --frames 2

**永久修复:** 在选取其余帧之前先保留通配帧,使其永远不会被截断:

const wildPick = wild[Math.floor(Math.random() * wild.length)];
const rest = shuffle(pool.filter((f) => f.id !== wildPick.id))
  .slice(0, Math.max(0, n - 1));

return n <= 1 ? [wildPick] : [...rest, wildPick].slice(0, n);

添加一个单元测试,断言 selectFrames(1) 返回的每个结果都恰好包含一个带有 wild 标记的帧。

来源 Issue #37
故障排除
如何防止单个失败的 LLM 调用取消整个分支扇出(fan-out)并丢弃已完成的结果?

将发散扇出(frames.map(...))和深化阶段(toDeepen.map(...))这两处的 Promise.all 都替换为 Promise.allSettled。然后分别处理已兑现(fulfilled)的结果,并收集被拒绝(rejected)的分支,而不是让第一个 rejection 中止整个运行。

示例模式:

const settled = await Promise.allSettled(
  frames.map((frame) => divergeBranch(frame))
);

const branches: Branch[] = [];
const failedFrames: { frameId: string; error: string }[] = [];

settled.forEach((result, i) => {
  if (result.status === "fulfilled") {
    branches.push(result.value);
  } else {
    const frameId = frames[i].id;
    const error = String(result.reason);
    failedFrames.push({ frameId, error });
    emitter.emit("frame:failed", { frameId, error });
  }
});

对深化阶段应用同样的修改。在 types.ts 中向 RunResult 添加 failedFrames:

type RunResult = {
  // 现有字段
  failedFrames: { frameId: string; error: string }[];
};

随后 CLI 可以打印部分失败信息,例如 ✗ <frame> failed: <reason>。只有当所有分支都失败时,运行才应硬失败:

if (branches.length === 0) {
  throw new Error("All LLM branches failed");
}

这可以处理网络/LLM 层的异常抛出,例如速率限制、超时以及无法恢复的格式错误响应。divergeBranch、scoreIdeas 和 clusterIdeas 内部的 JSON 解析失败已经通过返回空结果实现 fail open。为了支持重跑,可以使用一个以 (frame_id, input_hash) 为键的可选检查点,跳过已完成的分支,并以退避(backoff)方式重试失败的分支。

来源 Issue #44