|
| 1 | +# Tool Configuration Plan by Model |
| 2 | + |
| 3 | +This document outlines the tool configurations that need to be adjusted based on the selected Claude model for optimal computer use functionality. |
| 4 | + |
| 5 | +## Current Implementation Analysis |
| 6 | + |
| 7 | +Based on the codebase analysis, the current implementation in `src/modules/hybrid/hybrid_session.ts:62-68` uses hardcoded tool configurations: |
| 8 | + |
| 9 | +```typescript |
| 10 | +tools: [ |
| 11 | + {type: "bash_20241022", name: "bash"}, |
| 12 | + {type: "text_editor_20241022", name: "str_replace_editor"}, |
| 13 | + ...tools |
| 14 | +], |
| 15 | +betas: ["computer-use-2024-10-22"], |
| 16 | +``` |
| 17 | + |
| 18 | +## Model-Specific Tool Configurations |
| 19 | + |
| 20 | +### Claude 4 (claude-sonnet-4-20250514, claude-opus-4-20250514) |
| 21 | +- **Bash Tool**: `bash_20250124` |
| 22 | +- **Text Editor Tool**: `text_editor_20250429` (without `undo_edit` capability) |
| 23 | +- **Beta Header**: `computer-use-2025-01-24` |
| 24 | +- **Special Features**: |
| 25 | + - Supports thinking capability with token budget |
| 26 | + - Latest tool versions with enhanced capabilities |
| 27 | + |
| 28 | +### Claude Sonnet 3.7 (claude-3-7-sonnet-20250219) |
| 29 | +- **Bash Tool**: `bash_20250124` |
| 30 | +- **Text Editor Tool**: `text_editor_20250124` (includes `undo_edit` capability) |
| 31 | +- **Bash Tool**: `bash_20250124` |
| 32 | +- **Beta Header**: `computer-use-2025-01-24` |
| 33 | +- **Special Features**: |
| 34 | + - Supports thinking capability with token budget |
| 35 | + - Latest bash tools like Claude 4 |
| 36 | + - Different text editor version with undo functionality |
| 37 | + |
| 38 | +### Claude Sonnet 3.5 (claude-3-5-sonnet-20241022) |
| 39 | +- **Bash Tool**: `bash_20241022` |
| 40 | +- **Text Editor Tool**: `text_editor_20241022` |
| 41 | +- **Beta Header**: `computer-use-2024-10-22` |
| 42 | +- **Special Features**: |
| 43 | + - Current implementation (no changes needed) |
| 44 | + - No thinking capability |
| 45 | + - Legacy beta header |
| 46 | + |
| 47 | +## Implementation Requirements |
| 48 | + |
| 49 | +### 1. Tool Configuration Mapping |
| 50 | +Create a model-to-tool mapping in `src/config/constants.ts`: |
| 51 | + |
| 52 | +```typescript |
| 53 | +interface ModelToolConfig { |
| 54 | + textEditorTool: string; |
| 55 | + bashTool: string; |
| 56 | + betaHeader: string; |
| 57 | + supportsThinking: boolean; |
| 58 | +} |
| 59 | + |
| 60 | +const MODEL_TOOL_CONFIGS: Record<string, ModelToolConfig> = { |
| 61 | + 'claude-3-5-sonnet-20241022': { |
| 62 | + textEditorTool: 'text_editor_20241022', |
| 63 | + bashTool: 'bash_20241022', |
| 64 | + betaHeader: 'computer-use-2024-10-22', |
| 65 | + supportsThinking: false |
| 66 | + }, |
| 67 | + 'claude-3-7-sonnet-20250219': { |
| 68 | + textEditorTool: 'text_editor_20250124', |
| 69 | + bashTool: 'bash_20250124', |
| 70 | + betaHeader: 'computer-use-2025-01-24', |
| 71 | + supportsThinking: true |
| 72 | + }, |
| 73 | + 'claude-sonnet-4-20250514': { |
| 74 | + textEditorTool: 'text_editor_20250429', |
| 75 | + bashTool: 'bash_20250124', |
| 76 | + betaHeader: 'computer-use-2025-01-24', |
| 77 | + supportsThinking: true |
| 78 | + }, |
| 79 | + 'claude-opus-4-20250514': { |
| 80 | + textEditorTool: 'text_editor_20250429', |
| 81 | + bashTool: 'bash_20250124', |
| 82 | + betaHeader: 'computer-use-2025-01-24', |
| 83 | + supportsThinking: true |
| 84 | + } |
| 85 | +}; |
| 86 | + |
| 87 | +export function getModelToolConfig(model: string): ModelToolConfig { |
| 88 | + return MODEL_TOOL_CONFIGS[model] || MODEL_TOOL_CONFIGS['claude-3-7-sonnet-20250219']; |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +### 2. API Client Configuration Update |
| 93 | +**File**: `src/modules/hybrid/hybrid_session.ts:58-69` |
| 94 | + |
| 95 | +**Current hardcoded implementation**: |
| 96 | +```typescript |
| 97 | +const response = await this.client.beta.messages.create({ |
| 98 | + model: apiConfig.MODEL, |
| 99 | + max_tokens: apiConfig.MAX_TOKENS, |
| 100 | + messages: this.messages, |
| 101 | + tools: [ |
| 102 | + {type: "bash_20241022", name: "bash"}, |
| 103 | + {type: "text_editor_20241022", name: "str_replace_editor"}, |
| 104 | + ...tools |
| 105 | + ], |
| 106 | + system: this.cachedSystemPrompt, |
| 107 | + betas: ["computer-use-2024-10-22"], |
| 108 | +}) |
| 109 | +``` |
| 110 | + |
| 111 | +**Required dynamic implementation**: |
| 112 | +```typescript |
| 113 | +const toolConfig = getModelToolConfig(apiConfig.MODEL); |
| 114 | +const response = await this.client.beta.messages.create({ |
| 115 | + model: apiConfig.MODEL, |
| 116 | + max_tokens: apiConfig.MAX_TOKENS, |
| 117 | + messages: this.messages, |
| 118 | + tools: [ |
| 119 | + {type: toolConfig.bashTool, name: "bash"}, |
| 120 | + {type: toolConfig.textEditorTool, name: "str_replace_editor"}, |
| 121 | + ...tools |
| 122 | + ], |
| 123 | + system: this.cachedSystemPrompt, |
| 124 | + betas: [toolConfig.betaHeader], |
| 125 | +}) |
| 126 | +``` |
| 127 | + |
| 128 | +### 3. Text Editor Capability Handling |
| 129 | +**File**: `src/types/interfaces.ts:75` |
| 130 | + |
| 131 | +The `FileTool` interface currently includes `undo_edit` command: |
| 132 | +```typescript |
| 133 | +export interface FileTool { |
| 134 | + command: 'view' | 'create' | 'str_replace' | 'insert' | 'undo_edit' |
| 135 | + // ... |
| 136 | +} |
| 137 | +``` |
| 138 | + |
| 139 | +**Required change**: Make `undo_edit` conditionally available based on model tool configuration. |
| 140 | + |
| 141 | +### 4. System Prompt Template Updates |
| 142 | +**File**: `src/config/constants.ts:50-144` |
| 143 | + |
| 144 | +The `SYSTEM_PROMPT_TEMPLATE` hardcodes tool names in the documentation section. Need to make this dynamic based on model configuration. |
| 145 | + |
| 146 | +### 5. Thinking Capability Integration |
| 147 | +Already implemented in `src/config/constants.ts:157-160`: |
| 148 | +```typescript |
| 149 | +function shouldUseThinking(mainModel: string): boolean { |
| 150 | + const modelMap = getModelMap() |
| 151 | + return mainModel !== modelMap["3.5-sonnet"] |
| 152 | +} |
| 153 | +``` |
| 154 | + |
| 155 | +This logic aligns with the tool configuration requirements. |
| 156 | + |
| 157 | +## Files to Modify |
| 158 | + |
| 159 | +### Primary Implementation Files |
| 160 | + |
| 161 | +1. **`src/config/constants.ts`** |
| 162 | + - **Line 1-4**: Add import for `getModelToolConfig` function |
| 163 | + - **Add**: `ModelToolConfig` interface and `MODEL_TOOL_CONFIGS` mapping |
| 164 | + - **Add**: `getModelToolConfig()` helper function |
| 165 | + - **Optional**: Update `SYSTEM_PROMPT_TEMPLATE` to be dynamic (lines 50-144) |
| 166 | + |
| 167 | +2. **`src/modules/hybrid/hybrid_session.ts`** |
| 168 | + - **Line 2**: Add import for `getModelToolConfig` from constants |
| 169 | + - **Lines 62-68**: Replace hardcoded tool types and beta headers with dynamic configuration |
| 170 | + - **Implementation Priority**: HIGH - This is the main API call site |
| 171 | + |
| 172 | +3. **`src/modules/planner/planner.ts`** |
| 173 | + - ✅ **No changes needed** - Uses `claude.messages.create()` without tool configurations (line 44) |
| 174 | + - Already uses dynamic model selection via `apiConfig.REASONING_MODEL` (line 27) |
| 175 | + |
| 176 | +### Secondary Files (If Needed) |
| 177 | + |
| 178 | +4. **`src/types/interfaces.ts`** |
| 179 | + - **Line 76**: Consider making `undo_edit` conditional in `FileTool` interface |
| 180 | + - **Implementation Priority**: LOW - Only if undo_edit validation is required |
| 181 | + |
| 182 | +5. **`src/modules/editor/handlers.ts`** |
| 183 | + - Check if editor handlers need to be aware of model capabilities |
| 184 | + - Update undo_edit handling based on model tool configuration |
| 185 | + |
| 186 | +### Files Already Configured (No Changes Needed) |
| 187 | + |
| 188 | +- **`src/config/settings.ts`**: Model mapping already implemented (lines 5-66) |
| 189 | +- **`src/config/constants.ts`**: Thinking capability logic already exists (lines 157-160) |
| 190 | + |
| 191 | +## Current Implementation Status |
| 192 | + |
| 193 | +Based on `plans/configurableModels.md`, the following are already implemented: |
| 194 | +- ✅ Model selection in settings (MODEL_MAP in settings.ts) |
| 195 | +- ✅ Dynamic model configuration (getSelectedModel() function) |
| 196 | +- ✅ Thinking capability control (shouldUseThinking() function) |
| 197 | +- ✅ Model-specific token usage tracking (SESSION_LOGGER class) |
| 198 | + |
| 199 | +**Missing Implementation**: Tool configuration mapping based on selected model. |
| 200 | + |
| 201 | +## Implementation Priority |
| 202 | + |
| 203 | +### Critical (Must Fix) |
| 204 | +1. **`src/modules/hybrid/hybrid_session.ts:62-68`** - Main API call using hardcoded tools |
| 205 | +2. **`src/config/constants.ts`** - Add model-tool mapping configuration |
| 206 | + |
| 207 | +### Important (Should Fix) |
| 208 | +3. Search for any other files making direct API calls with tool configurations |
| 209 | +4. Validate no other hardcoded `computer-use-2024-10-22` beta headers exist |
| 210 | + |
| 211 | +### Optional (Nice to Have) |
| 212 | +5. Dynamic system prompt template |
| 213 | +6. Conditional undo_edit capability handling |
| 214 | + |
| 215 | +## Testing Strategy |
| 216 | + |
| 217 | +### Model-Specific Tool Tests |
| 218 | +```bash |
| 219 | +# Test with 3.5 Sonnet (current default) |
| 220 | +deno run -A src/main.ts --mode=hybrid "test bash and editor tools" |
| 221 | + |
| 222 | +# Test with 3.7 Sonnet |
| 223 | +deno run -A src/main.ts settings --set-model "3.7-sonnet" |
| 224 | +deno run -A src/main.ts --mode=hybrid "test undo_edit capability" |
| 225 | + |
| 226 | +# Test with 4 Sonnet |
| 227 | +deno run -A src/main.ts settings --set-model "4-sonnet" |
| 228 | +deno run -A src/main.ts --mode=hybrid "test latest tool versions" |
| 229 | +``` |
| 230 | + |
| 231 | +### Validation Tests |
| 232 | +- Verify correct beta headers in API calls |
| 233 | +- Confirm tool types match expected model versions |
| 234 | +- Test thinking capability with supported models |
| 235 | + |
| 236 | +## Risk Assessment |
| 237 | + |
| 238 | +### High Risk |
| 239 | +- **API Call Failures**: If wrong tool versions are used with incompatible models |
| 240 | +- **Beta Header Mismatches**: Could cause API rejections |
| 241 | + |
| 242 | +### Medium Risk |
| 243 | +- **Feature Degradation**: undo_edit not available where expected |
| 244 | +- **Cost Implications**: No validation for expensive model selections |
| 245 | + |
| 246 | +### Low Risk |
| 247 | +- **System Prompt Inconsistencies**: Static documentation vs dynamic tools |
0 commit comments