Implement rule chaining support for @RuleName references and success events
This PR implements rule chaining functionality that allows rules to reference the results of previously executed rules using @RuleName syntax and success event names.
Problem
Users were unable to chain rules together where subsequent rules depend on the results of previous rules. The specific issue was that expressions like @EvaluationExpression && metrics.cost_limit >= -1 would fail with "Unknown identifier '@EvaluationExpression'" errors.
Solution
Modified the rule execution flow to:
- Execute rules sequentially and collect their results
- Detect rule references in expressions (
@RuleNameand success event names) - Inject rule results as scoped parameters for subsequent rules that reference them
- Preprocess expressions to replace
@RuleNamewithRuleNamebefore compilation
Example Usage
[
{
"WorkflowName": "Tuning",
"Rules": [
{
"RuleName": "EvaluationExpression",
"SuccessEvent": "EvaluationExpressionPassed",
"Expression": "metrics.current_value > 1000",
"RuleExpressionType": "LambdaExpression"
},
{
"RuleName": "VerificationExpression",
"SuccessEvent": "VerificationExpressionPassed",
"Expression": "@EvaluationExpression && metrics.cost_limit >= -1",
"RuleExpressionType": "LambdaExpression"
},
{
"RuleName": "ActionExpression",
"Expression": "VerificationExpressionPassed",
"RuleExpressionType": "LambdaExpression"
}
]
}
]
Key Features
@RuleNamereferences: Evaluate to the boolean result of the referenced rule- Success event references: Reference success events by name (e.g.,
EvaluationExpressionPassed) - Backward compatibility: Only activates when
EnableScopedParams = true - Performance optimized: Rule chaining logic only applies when rule references are detected
Testing
Added comprehensive test coverage including:
- Basic rule chaining scenarios
- Success event references
- Failure handling when referenced rules fail
- Graceful degradation when scoped params are disabled
- Original issue reproduction with exact JSON configuration
All existing tests continue to pass, ensuring no regressions.
Fixes #679.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.