| | | 1 | | using Intentum.Core.Behavior; |
| | | 2 | | using Intentum.Core.Contracts; |
| | | 3 | | using Intentum.Core.Intents; |
| | | 4 | | using Intentum.Core.Pipeline; |
| | | 5 | | |
| | | 6 | | namespace Intentum.Core.Models; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Result of a rule evaluation: intent name, confidence score, and optional reasoning. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <param name="Name">Intent name when the rule matches.</param> |
| | | 12 | | /// <param name="Score">Confidence score in [0, 1].</param> |
| | | 13 | | /// <param name="Reasoning">Optional human-readable explanation (e.g. "login.failed >= 2 and password.reset").</param> |
| | | 14 | | public sealed record RuleMatch(string Name, double Score, string? Reasoning = null); |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Intent inference using rule-based evaluation (no LLM). Fast, deterministic, explainable. |
| | | 18 | | /// Uses the resolution pipeline internally (signal → vector → rule inference → confidence). |
| | | 19 | | /// Use as the primary model in ChainedIntentModel so that LLM is only called when rules do not match or confidence is l |
| | | 20 | | /// </summary> |
| | | 21 | | public sealed class RuleBasedIntentModel : IIntentModel |
| | | 22 | | { |
| | | 23 | | private readonly IntentResolutionPipeline _pipeline; |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Creates a rule-based intent model with the given rules. First matching rule wins. |
| | | 27 | | /// </summary> |
| | | 28 | | /// <param name="rules">Ordered list of rules. Each rule returns a RuleMatch when it applies, or null to skip.</para |
| | 5 | 29 | | public RuleBasedIntentModel(IEnumerable<Func<BehaviorSpace, RuleMatch?>> rules) |
| | 5 | 30 | | { |
| | 5 | 31 | | var step = new RuleBasedInferenceStep(rules ?? throw new ArgumentNullException(nameof(rules))); |
| | 5 | 32 | | _pipeline = new IntentResolutionPipeline(step); |
| | 5 | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <inheritdoc /> |
| | | 36 | | public Intent Infer(BehaviorSpace behaviorSpace, BehaviorVector? precomputedVector = null) |
| | 5 | 37 | | => _pipeline.Infer(behaviorSpace, precomputedVector); |
| | | 38 | | } |