Skip to content

Implement rule chaining support for @RuleName references and success events #680

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 26, 2025

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:

  1. Execute rules sequentially and collect their results
  2. Detect rule references in expressions (@RuleName and success event names)
  3. Inject rule results as scoped parameters for subsequent rules that reference them
  4. Preprocess expressions to replace @RuleName with RuleName before 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

  • @RuleName references: 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.

Copilot AI and others added 3 commits June 26, 2025 05:28
Co-authored-by: pbhal <47822122+pbhal@users.noreply.github.com>
Co-authored-by: pbhal <47822122+pbhal@users.noreply.github.com>
Co-authored-by: pbhal <47822122+pbhal@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Unable to bind values in rule chaining. Implement rule chaining support for @RuleName references and success events Jun 26, 2025
@Copilot Copilot AI requested a review from pbhal June 26, 2025 05:40
Copilot finished work on behalf of pbhal June 26, 2025 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to bind values in rule chaining.
2 participants