Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented May 24, 2025

Related GitHub Issue

Closes: #3941

Description

This PR improves the tool descriptions for file editing operations to guide LLMs toward better tool selection. The main issue was that LLMs were frequently choosing write_to_file for file edits instead of more appropriate tools like apply_diff, insert_content, or search_and_replace, likely due to misleading tool descriptions.

Key changes:

  • write_to_file tool description: Clarified primary use cases as creating new files or complete rewrites when intentionally required, reducing emphasis on full file reconstruction
  • apply_diff tool description: Enhanced to emphasize "targeted modifications" and "precise, surgical edits", clarified support for multiple search/replace operations, and positioned as the preferred tool for targeted changes
  • Removed misleading restrictions: Eliminated the "only a single operation allowed" text that was confusing for the apply_diff tool

The changes maintain all necessary technical details while providing clearer guidance on tool selection without being overly prescriptive.

Test Procedure

Manual Testing:

  1. Review the updated tool descriptions in the system prompts
  2. Verify that the descriptions clearly distinguish between use cases for each tool
  3. Check that write_to_file emphasizes new file creation and complete rewrites
  4. Confirm apply_diff emphasizes targeted modifications and supports multiple operations
  5. Ensure existing functionality remains intact

Expected Behavior:

  • LLMs should now prefer apply_diff for targeted file modifications
  • write_to_file should be used primarily for new files or intentional complete rewrites
  • Tool selection should be more appropriate based on the editing context

Type of Change

  • 🐛 Bug Fix: Non-breaking change that fixes an issue.
  • New Feature: Non-breaking change that adds functionality.
  • 💥 Breaking Change: Fix or feature that would cause existing functionality to not work as expected.
  • ♻️ Refactor: Code change that neither fixes a bug nor adds a feature.
  • 💅 Style: Changes that do not affect the meaning of the code (white-space, formatting, etc.).
  • 📚 Documentation: Updates to documentation files.
  • ⚙️ Build/CI: Changes to the build process or CI configuration.
  • 🧹 Chore: Other changes that don't modify src or test files.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Code Quality:
    • My code adheres to the project's style guidelines.
    • There are no new linting errors or warnings (npm run lint).
    • All debug code (e.g., console.log) has been removed.
  • Testing:
    • New and/or updated tests have been added to cover my changes.
    • All tests pass locally (npm test).
    • The application builds successfully with my changes.
  • Branch Hygiene: My branch is up-to-date (rebased) with the main branch.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Changeset: A changeset has been created using npm run changeset if this PR includes user-facing changes or dependency updates.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A - This change affects internal tool descriptions and prompt engineering, not user-facing UI.

Documentation Updates

  • No documentation updates are required.

The changes are internal improvements to tool descriptions used by the AI system and don't affect user-facing functionality or APIs.

Additional Notes

This improvement should lead to more appropriate tool selection by LLMs, resulting in:

  • More efficient file editing operations
  • Reduced unnecessary file reconstructions
  • Better overall developer experience when using AI-assisted coding features

The changes are backward compatible and don't affect the tool APIs or functionality, only their descriptions.

Get in Touch

Discord username: [Your Discord username here]

### Problem
LLMs were frequently choosing `write_to_file` for file edits instead of more appropriate tools like `apply_diff`, `insert_content`, or `search_and_replace`. This was likely because the tool descriptions made it seem like files needed to be reconstructed rather than edited.

### Changes Made

**write_to_file tool description:**
- Clarified primary use cases: **creating new files** or **complete rewrites when intentionally required**
- Changed opening from "write full content" to "write content" to reduce emphasis on full reconstruction
- Updated parameter description to be more specific about when complete content is needed

**apply_diff tool description:**
- Enhanced description to emphasize "targeted modifications" and "precise, surgical edits"
- Clarified that multiple search/replace operations can be performed in a single call
- Removed misleading "only a single operation allowed" restriction
- Better positioned as the preferred tool for making several targeted changes efficiently

### Impact
These changes should guide LLMs toward:
- Using `write_to_file` primarily for new files or intentional complete rewrites
- Using `apply_diff` for targeted edits and modifications to existing files
- Better understanding of when each tool is most appropriate

The updated descriptions maintain necessary technical details while providing clearer guidance on tool selection without being overly prescriptive.
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
@mrubens mrubens merged commit a8922e0 into main May 24, 2025
12 checks passed
@mrubens mrubens deleted the tool-desc-fix branch May 24, 2025 22:35
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap May 24, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap May 24, 2025
SmartManoj pushed a commit to SmartManoj/Raa-Code that referenced this pull request Jun 13, 2025
* Fix linter warnings in the webview (part 2)

Replace protobus calls using object literals to use Message.create({...})

Fix incorrect property name detected after this change in webview-ui/src/components/settings/SettingsView.tsx

Optimised imports in vscode.

* Fix typo

* formatting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Edit Tool Call Accuracy

3 participants