-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: Filter native tools by mode restrictions #9246
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
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
Native tools are now filtered based on mode restrictions before being sent to the API, matching the behavior of XML tools. Previously, all native tools were sent to the API regardless of mode, causing the model to attempt using disallowed tools. Changes: - Created filterNativeToolsForMode() and filterMcpToolsForMode() utility functions - Extracted filtering logic from Task.ts into dedicated module - Applied same filtering approach used for XML tools in system prompt - Added comprehensive test coverage (10 tests) Impact: - Model only sees tools allowed by current mode - No more failed tool attempts due to mode restrictions - Consistent behavior between XML and Native protocols - Better UX with appropriate tool suggestions per mode
- Add getAvailableToolsInGroup() helper to check tools by group instead of individually - Refactor filterNativeToolsForMode() to reuse getToolsForMode() instead of duplicating logic - Simplify capabilities.ts by using group-based checks (60% reduction) - Refactor rules.ts to use group helper (56% reduction) - Remove debug console.log statements - Update tests and snapshots Benefits: - Eliminates code duplication - Leverages existing TOOL_GROUPS structure - More maintainable - new tools in groups work automatically - All tests passing (26/26)
Contributor
All issues have been resolved.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
Ensures the agent always has functional tools even if: - A custom mode is deleted while tasks still reference it - Mode configuration becomes corrupted - An invalid mode slug is provided Without this fallback, the agent would have zero tools (not even ask_followup_question or attempt_completion), completely breaking it.
mrubens
approved these changes
Nov 14, 2025
mini2s
added a commit
to zgsm-ai/costrict
that referenced
this pull request
Nov 17, 2025
Summary
Refactored tool checking to eliminate code duplication by using group-based checks instead of repetitive individual tool checks.
Key Changes
getAvailableToolsInGroup()helper function to check tools by groupfilterNativeToolsForMode()to reuse existinggetToolsForMode()functioncapabilities.ts(60% reduction in tool checking code)rules.ts(56% reduction in tool checking code)Benefits
getToolsForMode()Testing
All existing tests pass with no changes needed.
Important
Refactor tool filtering logic to use mode-based restrictions, reducing code duplication and improving maintainability across the system prompt and task modules.
filterNativeToolsForMode()andfilterMcpToolsForMode()infilter-tools-for-mode.tsto filter tools based on mode restrictions.getAvailableToolsInGroup()to dynamically build system prompt content based on available tools.getCapabilitiesSection()andgetRulesSection()incapabilities.tsandrules.tsto use new tool filtering logic.system.tsto integrate new tool filtering functions.filter-tools-for-mode.spec.tsandnative-tools-filtering.spec.tsto verify tool filtering logic.mode-aware-sections.spec.tsandsections.spec.tsto align with new filtering logic.This description was created by
for 708e5f1. You can customize this summary. It will automatically update as commits are pushed.