Skip to content

rename to criteria config - #1397

Merged
iceljc merged 1 commit into
SciSharp:masterfrom
iceljc:features/refine-rule-criteria
Aug 13, 2026
Merged

rename to criteria config#1397
iceljc merged 1 commit into
SciSharp:masterfrom
iceljc:features/refine-rule-criteria

Conversation

@iceljc

Copy link
Copy Markdown
Collaborator

No description provided.

@iceljc
iceljc merged commit afdf96b into SciSharp:masterAug 13, 2026
3 of 4 checks passed
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Rename rule criteria field to criteria_config across rule pipeline

✨ Enhancement⚙️ Configuration changes🕐 10-20 Minutes

Grey Divider

AI Description

• Rename rule criteria JSON field to "criteria_config" for clearer configuration intent.
• Update rule engine and LLM evaluator to consume the renamed criteria configuration.
• Align Mongo storage models/mappers with the new criteria_config schema.
Diagram

graph TD
A["AgentRule model"] --> B["RuleEngine"] --> C["Criteria evaluator"] --> D["LLM criteria"]
A --> E[("Mongo storage")]
E --> F["Mongo mappers"] --> A
subgraph Legend
direction LR
_m["Model"] ~~~ _svc["Service"] ~~~ _db[("Database")]
end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Backward-compatible alias during migration
  • ➕ Allows older configs/documents using "criteria" to continue working
  • ➕ Reduces rollout risk across agents and stored rules
  • ➖ Requires custom JSON (de)serialization logic or a temporary shadow property
  • ➖ Adds short-term maintenance burden until alias removal
2. Versioned rule schema (v1/v2)
  • ➕ Explicit compatibility strategy for future schema changes
  • ➕ Enables controlled migrations with clearer tooling
  • ➖ More up-front complexity and code paths
  • ➖ Requires version propagation through storage and APIs
3. Keep JSON name "criteria" and only rename internal types
  • ➕ Avoids breaking external JSON and persisted documents
  • ➕ Still clarifies code intent via type/property naming
  • ➖ External contract remains less explicit
  • ➖ Does not achieve the desired config naming in serialized data

Recommendation: If this rename affects persisted documents or external API clients, add a temporary backward-compatible read path for the old "criteria" field (or a versioned schema) and plan a migration window. If the project can tolerate a breaking change and migrations are already handled out-of-band, the current direct rename is the simplest and cleanest approach.

Files changed (4) +22 / -22

Refactor (3) +19 / -19
LlmCriteriaEvaluator.csConsume CriteriaConfig when building LLM criteria input+4/-4

Consume CriteriaConfig when building LLM criteria input

• Updates LlmCriteriaEvaluator to build prompt input from rule.CriteriaConfig instead of rule.Criteria. Renames BuildInput parameter/type usage to RuleCriteriaConfig and reads the criteria text from the new config object.

src/Infrastructure/BotSharp.Core.Rules/Criteria/Llm/LlmCriteriaEvaluator.cs

RuleEngine.csResolve evaluator from CriteriaConfig.Mode+1/-1

Resolve evaluator from CriteriaConfig.Mode

• Switches the rule engine to determine the criteria evaluator using rule.CriteriaConfig?.Mode, preserving the precedence rule of rule-defined mode over trigger options.

src/Infrastructure/BotSharp.Core.Rules/Engines/RuleEngine.cs

AgentRuleMongoElement.csRename Mongo criteria model/mapping to CriteriaConfig+14/-14

Rename Mongo criteria model/mapping to CriteriaConfig

• Renames Mongo persistence property and model from Criteria/RuleCriteriaMongoModel to CriteriaConfig/RuleCriteriaConfigMongoModel. Updates mapping helpers to translate between Mongo models and the renamed domain RuleCriteriaConfig type.

src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentRuleMongoElement.cs

Other (1) +3 / -3
AgentRule.csRename serialized criteria to criteria_config and update domain type+3/-3

Rename serialized criteria to criteria_config and update domain type

• Renames the JSON field from "criteria" to "criteria_config" and updates the AgentRule property name accordingly. Renames the criteria configuration class from RuleCriteria to RuleCriteriaConfig.

src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentRule.cs

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (1)📘 Rule violations (0)📜 Skill insights (0)

Grey Divider


Action required

1. Legacy JSON criteria ignored 🐞 Bug≡ Correctness
Description
AgentRule/Mongo rule persistence renamed the criteria field from criteria/Criteria to
criteria_config/CriteriaConfig without a compatibility path, so legacy agent JSON, API payloads,
and previously stored Mongo documents deserialize with CriteriaConfig == null. As a result, a
rule’s saved criteria/mode can be silently dropped during domain conversion and evaluation.
Code

src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentRule.cs[R17-19]

+ [JsonPropertyName("criteria_config")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
- public RuleCriteria? Criteria { get; set; }+ public RuleCriteriaConfig? CriteriaConfig { get; set; }
Evidence
The code now maps rule criteria only through criteria_config on AgentRule, and agents are
deserialized from JSON via JsonSerializer.Deserialize<Agent> while evaluation reads
rule.CriteriaConfig, so any legacy JSON payloads still using criteria will not populate the
property and will evaluate without the configured criteria/mode. Similarly, Mongo persistence
renamed AgentRuleMongoElement.Criteria to CriteriaConfig, ToDomainElement reads only
CriteriaConfig, and AgentDocument stores rules without explicit BSON element aliasing; because
the Mongo driver ignores unknown/extra fields, existing documents containing Criteria will not
hydrate CriteriaConfig, causing criteria/mode loss when reading and transforming rules into domain
objects.

src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentRule.cs[3-20]
src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs[298-306]
src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentUpdateModel.cs[94-129]
src/Infrastructure/BotSharp.Core.Rules/Engines/RuleEngine.cs[53-57]
src/Infrastructure/BotSharp.Core.Rules/Criteria/Llm/LlmCriteriaEvaluator.cs[33-45]
src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentRuleMongoElement.cs[5-33]
src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs[24-29]
src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs[753-781]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The rule criteria field was renamed from `criteria`/`Criteria` to `criteria_config`/`CriteriaConfig` in both JSON and Mongo persistence, but deserialization currently accepts only the new name. This breaks backward compatibility for existing agent JSON in the file repository, API clients still sending `criteria`, and existing Mongo documents still storing `Criteria`, resulting in `CriteriaConfig == null` and silently dropping rule criteria/mode during domain conversion and evaluation.
## Issue Context
Agents are deserialized from JSON in the file repository (`JsonSerializer.Deserialize<Agent>`), and rules are also bound from OpenAPI request models containing `List<AgentRule>`, so legacy payloads using `criteria` will be ignored. In Mongo, `AgentDocument.Rules` stores `List<AgentRuleMongoElement>` which are transformed into domain `AgentRule` objects used by the rule engine, but the renamed property lacks BSON aliasing/migration so previously stored `Criteria` fields are ignored on read.
## Fix Focus Areas
- src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentRule.cs[3-20]
- src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs[298-306]
- src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentUpdateModel.cs[94-99]
- src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentRuleMongoElement.cs[5-33]
- src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs[24-29]
- src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs[753-781]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can type 'qodo, fix this' on a finding and the fix lands right on your PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment on lines +17 to +19
[JsonPropertyName("criteria_config")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public RuleCriteria? Criteria { get; set; }
public RuleCriteriaConfig? CriteriaConfig { get; set; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Legacy json criteria ignored 🐞 Bug≡ Correctness

AgentRule/Mongo rule persistence renamed the criteria field from criteria/Criteria to
criteria_config/CriteriaConfig without a compatibility path, so legacy agent JSON, API payloads,
and previously stored Mongo documents deserialize with CriteriaConfig == null. As a result, a
rule’s saved criteria/mode can be silently dropped during domain conversion and evaluation.
Agent Prompt
## Issue description
The rule criteria field was renamed from `criteria`/`Criteria` to `criteria_config`/`CriteriaConfig` in both JSON and Mongo persistence, but deserialization currently accepts only the new name. This breaks backward compatibility for existing agent JSON in the file repository, API clients still sending `criteria`, and existing Mongo documents still storing `Criteria`, resulting in `CriteriaConfig == null` and silently dropping rule criteria/mode during domain conversion and evaluation.
## Issue Context
Agents are deserialized from JSON in the file repository (`JsonSerializer.Deserialize<Agent>`), and rules are also bound from OpenAPI request models containing `List<AgentRule>`, so legacy payloads using `criteria` will be ignored. In Mongo, `AgentDocument.Rules` stores `List<AgentRuleMongoElement>` which are transformed into domain `AgentRule` objects used by the rule engine, but the renamed property lacks BSON aliasing/migration so previously stored `Criteria` fields are ignored on read.
## Fix Focus Areas
- src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentRule.cs[3-20]
- src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs[298-306]
- src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentUpdateModel.cs[94-99]
- src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentRuleMongoElement.cs[5-33]
- src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs[24-29]
- src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs[753-781]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Sign up for freeto 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.

1 participant

@iceljc