|
| 1 | +# Think / Plan Tool |
| 2 | + |
| 3 | +## Branch: `feature/think-tool` |
| 4 | + |
| 5 | +## Problem |
| 6 | + |
| 7 | +Local models (7B-32B running on LM Studio) make impulsive tool calls — they |
| 8 | +jump straight to editing without understanding the problem. Larger API models |
| 9 | +do this too but less often. There's no mechanism to force structured reasoning |
| 10 | +before acting. |
| 11 | + |
| 12 | +Delta has `Kind.Think` in its enum but no actual tool backing it. |
| 13 | + |
| 14 | +## What it is |
| 15 | + |
| 16 | +A no-op tool that accepts the model's reasoning and returns it back into context. |
| 17 | +No side effects. The model calls it to think before it acts. |
| 18 | + |
| 19 | +``` |
| 20 | +Model → think({ reasoning: "The user wants X. I see files A, B, C are involved. |
| 21 | + The dependency chain is A→B→C. I should modify B first because..." }) |
| 22 | +← Returns the same text back into context |
| 23 | +``` |
| 24 | + |
| 25 | +## Why it works |
| 26 | + |
| 27 | +Research on process reward models shows that models which checkpoint reasoning |
| 28 | +mid-task make fewer cascading errors. For weaker models this is even more |
| 29 | +pronounced — a 7B model that plans before acting outperforms the same model |
| 30 | +that jumps straight to edits. |
| 31 | + |
| 32 | +## Implementation |
| 33 | + |
| 34 | +### Tool declaration |
| 35 | + |
| 36 | +```typescript |
| 37 | +{ |
| 38 | + name: 'think', |
| 39 | + description: 'Use this tool to plan your approach before taking action. ' |
| 40 | + + 'Write out your reasoning about the problem, what files are involved, ' |
| 41 | + + 'what changes are needed, and in what order. This helps you avoid ' |
| 42 | + + 'mistakes by thinking before acting. The output is returned to you ' |
| 43 | + + 'for reference — no side effects occur.', |
| 44 | + parameters: { |
| 45 | + type: 'object', |
| 46 | + properties: { |
| 47 | + reasoning: { |
| 48 | + type: 'string', |
| 49 | + description: 'Your structured reasoning about the current task.', |
| 50 | + }, |
| 51 | + }, |
| 52 | + required: ['reasoning'], |
| 53 | + }, |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +### Tool implementation |
| 58 | + |
| 59 | +```typescript |
| 60 | +// The entire tool is ~10 lines |
| 61 | +async execute({ reasoning }: { reasoning: string }): Promise<string> { |
| 62 | + return reasoning; |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +### System prompt integration |
| 67 | + |
| 68 | +Add to the system prompt for weaker models (configurable): |
| 69 | + |
| 70 | +> Before making changes to code, use the `think` tool to plan your approach. |
| 71 | +> Outline which files need to change, in what order, and why. This is |
| 72 | +> especially important for multi-file changes. |
| 73 | +
|
| 74 | +### Optional: structured think mode |
| 75 | + |
| 76 | +For models that support it, enforce a schema: |
| 77 | + |
| 78 | +```typescript |
| 79 | +{ |
| 80 | + goal: string; |
| 81 | + files_involved: string[]; |
| 82 | + steps: string[]; |
| 83 | + risks: string[]; |
| 84 | + current_step: number; |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +This could be a `think_structured` variant or a config flag. |
| 89 | + |
| 90 | +## Files to create |
| 91 | +- `packages/core/src/tools/think.ts` — tool implementation |
| 92 | +- `packages/core/src/tools/think.test.ts` |
| 93 | + |
| 94 | +## Files to modify |
| 95 | +- `packages/core/src/config/config.ts` — register tool in `registerCoreTool()` |
| 96 | +- `packages/core/src/core/prompts.ts` — add think guidance to system prompt |
| 97 | + (gated on config flag or model capability) |
| 98 | + |
| 99 | +## Effort: ~1 hour |
0 commit comments