-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: add tool alias support for model-specific tool customization #9989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
No new issues found. The latest commit removes a redundant alias registration loop that duplicated logic already handled in
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
8e2bd0c to
ec15a07
Compare
This PR adds a tool alias system that allows models to expose tools under
different names while mapping to existing tool implementations. This is
particularly useful for:
1. Model-specific tool naming preferences (e.g., 'edit_file' -> 'search_and_replace')
2. Backward compatibility when renaming tools
3. Semantic tool naming that better matches model training
## Changes
### Core Alias Infrastructure
- Added `aliases` property to BaseTool for defining alternative tool names
- Implemented alias registration and validation in filter-tools-for-mode.ts
- Added `resolveToolAlias()`, `applyToolAliases()`, and `getToolAliasGroup()` helpers
### Model Tool Customization
- Enhanced `applyModelToolCustomization()` to track alias renames
- Updated `filterNativeToolsForMode()` to rename tools based on aliases in modelInfo.includedTools
- Added alias resolution in presentAssistantMessage.ts for tool validation
### Parser Support
- Added alias resolution in NativeToolCallParser for both streaming and finalized tool calls
- Added `search_and_replace` case in `createPartialToolUse()` for streaming updates
### Example Usage
In modelInfo:
```typescript
{
includedTools: ['edit_file'], // Alias for search_and_replace
excludedTools: ['apply_diff']
}
```
The model will see and use 'edit_file', but internally it maps to 'search_and_replace'.
## Test Coverage
- Added comprehensive tests for alias resolution functions
- Added tests for model tool customization with aliases
- Added tests for native tool filtering with alias renames
…ion context When tool aliases are used (e.g., 'edit_file' -> 'search_and_replace'), the alias name is now preserved and written to API history instead of the canonical name. This prevents confusion in multi-turn conversations where the model sees a different tool name in history than what it was told the tool was named. Changes: - NativeToolCallParser.ts already stores originalName when alias differs from resolved - Task.ts now uses originalName (alias) when available for API history
… tool customization
923a1e3 to
08e3b8e
Compare
- Add TOOL_ALIASES constant to src/shared/tools.ts as single source of truth - Update filter-tools-for-mode.ts to use central constant instead of tool instances - Remove aliases property from BaseTool and individual tool classes - Simplifies adding new aliases to a single-line change in shared/tools.ts
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Enhancement
New feature or request
lgtm
This PR has been approved by a maintainer
PR - Needs Review
size:L
This PR changes 100-499 lines, ignoring generated files.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a tool alias system that allows models to expose tools under different names while mapping to existing tool implementations. This enables:
edit_file→apply_diff)Changes
Core Alias Infrastructure
TOOL_ALIASESconstant insrc/shared/tools.ts- single source of truth for all aliasesfilter-tools-for-mode.tsresolveToolAlias(),applyToolAliases(),getToolAliasGroup()Model Tool Customization
applyModelToolCustomization()to track alias renamesfilterNativeToolsForMode()to rename tools based on aliases inmodelInfo.includedToolspresentAssistantMessage.tsfor tool validationParser Support
NativeToolCallParserfor both streaming and finalized tool callssearch_and_replacecase increatePartialToolUse()for streaming updatesAdding a New Alias
Simply add a single line to
TOOL_ALIASESinsrc/shared/tools.ts:Example Usage
In
modelInfo:The model will see and use
edit_file, but internally it maps toapply_diff.How It Works
edit_fileis inincludedTools,filterNativeToolsForModeresolves it toapply_diff, adds it to allowed tools, and renames the tool definition back toedit_fileedit_fileNativeToolCallParser.resolveToolAlias()convertsedit_file→apply_diffvalidateToolUsereceives resolvedincludedToolsso validation passesapply_difftool executes normallyTest Coverage
Files Changed
src/shared/tools.ts- Added centralTOOL_ALIASESconstantsrc/core/prompts/tools/filter-tools-for-mode.ts- Alias registration and resolutionsrc/core/assistant-message/NativeToolCallParser.ts- Parser alias supportsrc/core/assistant-message/presentAssistantMessage.ts- Validation fixsrc/core/task/Task.ts- Preserve alias name in API historyImportant
Introduces a tool alias system for model-specific tool customization, enhancing flexibility and backward compatibility, with changes in tool resolution, validation, and execution.
TOOL_ALIASESintools.tsas a central alias registry.filter-tools-for-mode.tswith functions likeresolveToolAlias().applyModelToolCustomization()to handle alias renames.filterNativeToolsForMode()to apply alias renames.NativeToolCallParserto resolve aliases during tool call parsing.presentAssistantMessage.tsto validate tools with resolved aliases.filter-tools-for-mode.spec.ts.This description was created by
for 5964457. You can customize this summary. It will automatically update as commits are pushed.