Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Dec 10, 2025

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:

  1. Model-specific tool naming preferences (e.g., edit_fileapply_diff)
  2. Backward compatibility when renaming tools
  3. Semantic tool naming that better matches model training

Changes

Core Alias Infrastructure

  • Added central TOOL_ALIASES constant in src/shared/tools.ts - single source of truth for all aliases
  • Implemented alias resolution and validation in filter-tools-for-mode.ts
  • Added helper functions: resolveToolAlias(), applyToolAliases(), getToolAliasGroup()

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

Adding a New Alias

Simply add a single line to TOOL_ALIASES in src/shared/tools.ts:

export const TOOL_ALIASES: Record<string, ToolName> = {
    edit_file: "apply_diff",
    write_file: "write_to_file",
    // Add new aliases here - no other files need changes!
} as const

Example Usage

In modelInfo:

{
  includedTools: ["edit_file"],  // Alias for apply_diff
  excludedTools: ["search_and_replace"]
}

The model will see and use edit_file, but internally it maps to apply_diff.

How It Works

  1. API Tool Building: When edit_file is in includedTools, filterNativeToolsForMode resolves it to apply_diff, adds it to allowed tools, and renames the tool definition back to edit_file
  2. Model Invocation: Model calls edit_file
  3. Parser Resolution: NativeToolCallParser.resolveToolAlias() converts edit_fileapply_diff
  4. Validation: validateToolUse receives resolved includedTools so validation passes
  5. Execution: apply_diff tool executes normally
  6. History: Original alias name preserved in API conversation history for consistency

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
  • Added tests for parser alias resolution (streaming and finalized)

Files Changed

  • src/shared/tools.ts - Added central TOOL_ALIASES constant
  • src/core/prompts/tools/filter-tools-for-mode.ts - Alias registration and resolution
  • src/core/assistant-message/NativeToolCallParser.ts - Parser alias support
  • src/core/assistant-message/presentAssistantMessage.ts - Validation fix
  • src/core/task/Task.ts - Preserve alias name in API history

Important

Introduces a tool alias system for model-specific tool customization, enhancing flexibility and backward compatibility, with changes in tool resolution, validation, and execution.

  • Behavior:
    • Introduces tool alias system allowing models to use alternative names for tools, mapping to existing implementations.
    • Supports model-specific tool naming, backward compatibility, and semantic naming.
  • Core Infrastructure:
    • Adds TOOL_ALIASES in tools.ts as a central alias registry.
    • Implements alias resolution in filter-tools-for-mode.ts with functions like resolveToolAlias().
  • Model Customization:
    • Updates applyModelToolCustomization() to handle alias renames.
    • Modifies filterNativeToolsForMode() to apply alias renames.
  • Parser and Validation:
    • Enhances NativeToolCallParser to resolve aliases during tool call parsing.
    • Updates presentAssistantMessage.ts to validate tools with resolved aliases.
  • Testing:
    • Adds tests for alias resolution and model tool customization in filter-tools-for-mode.spec.ts.

This description was created by Ellipsis for 5964457. You can customize this summary. It will automatically update as commits are pushed.

@roomote
Copy link
Contributor

roomote bot commented Dec 10, 2025

Rooviewer Clock   See task on Roo Cloud

No new issues found. The latest commit removes a redundant alias registration loop that duplicated logic already handled in applyModelToolCustomization(). All previous issues remain resolved.

  • Missing alias registration for ApplyDiffTool and WriteToFileTool - the aliases are defined but not registered in filter-tools-for-mode.ts
  • Missing changeset file for version bump and release notes
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 10, 2025
@hannesrudolph hannesrudolph force-pushed the feat/tool-aliases-for-model-customization branch 2 times, most recently from 8e2bd0c to ec15a07 Compare December 10, 2025 20:48
daniel-lxs and others added 6 commits December 11, 2025 13:36
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
@hannesrudolph hannesrudolph force-pushed the feat/tool-aliases-for-model-customization branch from 923a1e3 to 08e3b8e Compare December 11, 2025 20:38
- 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
@hannesrudolph hannesrudolph moved this from Triage to PR [Needs Review] in Roo Code Roadmap Dec 11, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Dec 12, 2025
@cte cte mentioned this pull request Dec 12, 2025
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.

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants