Skip to content

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

Closed
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-679
Closed

Implement rule chaining support for @RuleName references and success events#680
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-679

Conversation

Copy link
Copy Markdown
Contributor

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 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 AI requested a review from pbhal June 26, 2025 05:40
Copilot finished work on behalf of pbhal June 26, 2025 05:40
YogeshPraj added a commit that referenced this pull request May 30, 2026
…692 (#737)

for STJ, properties on an ExpandoObject built from JSON came through as
JsonElement values. Rule expressions like `input1.country == "india"` then
failed with "binary operator Equal is not defined for the types 'JsonElement'
and 'System.String'." Utils.CreateAbstractClassType now infers the native CLR
type from a JsonElement's ValueKind (string / int / long / double / bool /
null), and Utils.CreateObject unwraps JsonElement scalars to their native
values before assigning them. Objects and arrays inside the JsonElement keep
JsonElement shape — that path is for typed Newtonsoft-style models that
weren't using ExpandoObject anyway.

in JSON examples across README.md, docs/Getting-Started.md, and docs/index.md.
Removed.

after 5.0.4." That's actually standard C# Nullable<T> semantics — both
`null < x` and `null > x` are false. The pre-5.0.4 behavior was a
Newtonsoft / Dynamic.Core quirk, not the documented contract. Added an
explicit test documenting the current behavior plus the canonical
`!Dt.HasValue || Dt < someDate` workaround for users who want null-aware
ordering.

Not changed here: #679 (rule-chaining via @RuleName) is already covered
by in-flight PR #680 — no point duplicating that work. #710 and #709 are
unrelated AGV-themed spam; closing comments are in
issue-close-comments-batch-5.md.

All 164 unit tests pass on net6 / net8 / net9 / net10.

Co-authored-by: Yogesh Prajapati <yogeshcprajapati@outlook.com>
@YogeshPraj YogeshPraj closed this May 30, 2026
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.

3 participants