Skip to content

Commit 2b0f6ec

Browse files
feat: implement model-specific tool configurations
Add dynamic tool version selection based on Claude model: - Add ModelToolConfig interface and mapping for all supported models - Update HybridSession to use model-specific tool versions and beta headers - Support bash_20250124 and text_editor_20250124 for newer models - Maintain backward compatibility with 3.5 Sonnet tool versions - Update changelog and README with v1.3.1 release notes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 929c68c commit 2b0f6ec

File tree

5 files changed

+310
-6
lines changed

5 files changed

+310
-6
lines changed

CHANGELOG.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@
3232
### Fixed
3333
- Jina API retry logic for 403 responses with X-No-Cache header
3434

35-
### Latest Changes (since v1.3)
35+
## [v1.3.1] - 2025-01-27
3636

37-
No new changes yet.
37+
### Added
38+
- **Model-Specific Tool Configurations**: Dynamic tool version selection based on Claude model
39+
- Automatic selection of appropriate bash and text editor tool versions for each model
40+
- Model-specific beta headers (computer-use-2024-10-22 vs computer-use-2025-01-24)
41+
- Support for latest tool versions (bash_20250124, text_editor_20250124) for newer models
42+
- Backward compatibility maintained for Claude 3.5 Sonnet with legacy tool versions
43+
44+
### Changed
45+
- Enhanced HybridSession to use dynamic tool configuration instead of hardcoded versions
46+
- Updated API client to select appropriate beta headers based on selected model
47+
48+
### Technical Details
49+
- Added ModelToolConfig interface and mapping in constants.ts
50+
- Implemented getModelToolConfig() helper function for tool version selection
51+
- Updated tool type assertions to support multiple bash and text editor versions

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ bash command execution capabilities using Claude API with configurable model sel
1515
- Support for multiple Claude models (3.5 Sonnet, 3.7 Sonnet, 4 Sonnet, 4 Opus)
1616
- Smart planner model selection based on main model choice
1717
- Model-specific cost tracking and pricing
18+
- Dynamic tool version selection based on selected model
19+
- Automatic beta header configuration for optimal compatibility
1820
- Easy model switching via settings commands
1921
- **Enhanced Export System**:
2022
- Prompt ID-based export functionality
@@ -123,6 +125,8 @@ deno run -A src/main.ts settings --list
123125
- Automatic planner model selection based on your chosen model
124126
- Model-specific cost tracking and warnings
125127
- Thinking capabilities automatically enabled for supported models
128+
- Dynamic tool version selection ensuring compatibility with each model
129+
- Automatic beta header configuration for optimal API compatibility
126130

127131
## Project Structure
128132

plans/toolCallFix.md

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
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

src/config/constants.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,44 @@ import Anthropic from "anthropic"
33
import {homedir} from "node:os"
44
import {isJinaAvailable, loadUserSettings, getSelectedModel, getModelMap} from "./settings.ts"
55

6+
interface ModelToolConfig {
7+
textEditorTool: string;
8+
bashTool: string;
9+
betaHeader: string;
10+
supportsThinking: boolean;
11+
}
12+
13+
const MODEL_TOOL_CONFIGS: Record<string, ModelToolConfig> = {
14+
'claude-3-5-sonnet-20241022': {
15+
textEditorTool: 'text_editor_20241022',
16+
bashTool: 'bash_20241022',
17+
betaHeader: 'computer-use-2024-10-22',
18+
supportsThinking: false
19+
},
20+
'claude-3-7-sonnet-20250219': {
21+
textEditorTool: 'text_editor_20250124',
22+
bashTool: 'bash_20250124',
23+
betaHeader: 'computer-use-2025-01-24',
24+
supportsThinking: true
25+
},
26+
'claude-sonnet-4-20250514': {
27+
textEditorTool: 'text_editor_20250124',
28+
bashTool: 'bash_20250124',
29+
betaHeader: 'computer-use-2025-01-24',
30+
supportsThinking: true
31+
},
32+
'claude-opus-4-20250514': {
33+
textEditorTool: 'text_editor_20250124',
34+
bashTool: 'bash_20250124',
35+
betaHeader: 'computer-use-2025-01-24',
36+
supportsThinking: true
37+
}
38+
};
39+
40+
export function getModelToolConfig(model: string): ModelToolConfig {
41+
return MODEL_TOOL_CONFIGS[model] || MODEL_TOOL_CONFIGS['claude-3-5-sonnet-20241022'];
42+
}
43+
644
export const EDITOR_DIR = join(homedir(), ".ComputerUseAgent", "editor_dir")
745
export const SESSIONS_DIR = join(homedir(), ".ComputerUseAgent", "sessions")
846
export const LOGS_DIR = join(homedir(), ".ComputerUseAgent", "logs")

src/modules/hybrid/hybrid_session.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {BaseSession} from "../../utils/session.ts"
2-
import {getAPIConfig} from "../../config/constants.ts"
2+
import {getAPIConfig, getModelToolConfig} from "../../config/constants.ts"
33
import {log} from "../../config/logging.ts"
44
import {ToolHandler} from "../../utils/tool_handler.ts"
55
import {getConfigFileLocation} from "../../config/settings.ts"
@@ -55,17 +55,18 @@ export class HybridSession extends BaseSession {
5555
try {
5656
while (true) {
5757
const apiConfig = getAPIConfig()
58+
const toolConfig = getModelToolConfig(apiConfig.MODEL)
5859
const response = await this.client.beta.messages.create({
5960
model: apiConfig.MODEL,
6061
max_tokens: apiConfig.MAX_TOKENS,
6162
messages: this.messages,
6263
tools: [
63-
{type: "bash_20241022", name: "bash"},
64-
{type: "text_editor_20241022", name: "str_replace_editor"},
64+
{type: toolConfig.bashTool as "bash_20241022" | "bash_20250124", name: "bash"},
65+
{type: toolConfig.textEditorTool as "text_editor_20241022" | "text_editor_20250124", name: "str_replace_editor"},
6566
...tools
6667
],
6768
system: this.cachedSystemPrompt,
68-
betas: ["computer-use-2024-10-22"],
69+
betas: [toolConfig.betaHeader],
6970
})
7071

7172
const inputTokens = response.usage?.input_tokens ?? 0

0 commit comments

Comments
 (0)