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.
feat: composable EnableCondition with bitmask optimization #1641
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
Uh oh!
There was an error while loading. Please reload this page.
feat: composable EnableCondition with bitmask optimization #1641
Changes from 1 commit
3a52f7b880c194File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Add a composable EnableCondition system for tool filtering that: 1. **User-facing API** (conditions.go): - EnableCondition interface with Evaluate(ctx) method - Primitives: FeatureFlag(), ContextBool(), Static(), Always(), Never() - Combinators: And(), Or(), Not() with short-circuit evaluation - All bitmask complexity hidden from users 2. **Bitmask compiler** (condition_compiler.go): - Compiles conditions to O(1) bitmask evaluators at build time - RequestMask holds pre-computed uint64 bitmask per request - AND/OR of flags compile to single bitmask operations - Falls back gracefully for custom ConditionFunc 3. **Pre-sorting optimization** (builder.go): - Tools, resources, prompts sorted once at build time - Filtering preserves order, eliminating per-request sorting - ~45% faster request handling in benchmarks 4. **Integration** (filters.go, registry.go): - Builder.Build() compiles all EnableConditions - AvailableTools() builds RequestMask once, evaluates via bitmask - Backward compatible with legacy Enabled func and feature flags Usage example: tool.EnableCondition = Or( ContextBool("is_cca"), // CCA users bypass flag FeatureFlag("my_feature"), // Others need flag enabled ) Benchmarks (1000 requests × 50 tools): - Before: 23.7ms (with per-request sorting) - After: 12.9ms (pre-sorted + bitmask) - Improvement: 46% faster This makes it easy for remote server to adopt - just set EnableCondition on tools and the optimization is automatic.Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
Uh oh!
There was an error while loading. Please reload this page.