-
-
Notifications
You must be signed in to change notification settings - Fork 643
add criteria #1382
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
Merged
Merged
add criteria #1382
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3a5b149
add criteria
6348ca6
refine code script generation
41e21fb
refine instruction
1365399
Merge branch 'master' of https://github.com/SciSharp/BotSharp into fe…
f2b7672
Merge branch 'master' of https://github.com/SciSharp/BotSharp into fe…
036c813
change to json element
573ebb8
silent fallback to llm evaluator
bf80f2d
rename
5fd23e4
add json extension methods
305012e
clean code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Infrastructure/BotSharp.Abstraction/Coding/Options/CodeGenerationOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Infrastructure/BotSharp.Abstraction/Rules/Constants/BuiltInRuleCriteria.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| namespace BotSharp.Abstraction.Rules.Constants; | ||
|
|
||
| /// <summary> | ||
| /// Built-in rule criteria types. Each value maps to an | ||
| /// <see cref="IRuleCriteriaEvaluator.Type"/> registered in DI. | ||
| /// Plugins may introduce additional string types. | ||
| /// </summary> | ||
| public static class BuiltInRuleCriteria | ||
| { | ||
| /// <summary> | ||
| /// Evaluate a code script (e.g. Python) that returns a boolean result. | ||
| /// </summary> | ||
| public const string Code = "code"; | ||
|
|
||
| /// <summary> | ||
| /// Ask an LLM whether the rule applies to the request. | ||
| /// </summary> | ||
| public const string Llm = "llm"; | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/Infrastructure/BotSharp.Abstraction/Rules/IRuleCriteriaEvaluator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using BotSharp.Abstraction.Rules.Models; | ||
|
|
||
| namespace BotSharp.Abstraction.Rules; | ||
|
|
||
| /// <summary> | ||
| /// Decides whether a rule should be executed for the current request. | ||
| /// Implementations are resolved by <see cref="Type"/> in the rule engine, | ||
| /// so new criteria mechanisms can be added without changing the engine. | ||
| /// </summary> | ||
| public interface IRuleCriteriaEvaluator | ||
| { | ||
| /// <summary> | ||
| /// The criteria type this evaluator handles | ||
| /// </summary> | ||
| string Type { get; } | ||
|
|
||
| /// <summary> | ||
| /// Evaluate the criteria for a single agent's rule. | ||
| /// </summary> | ||
| /// <param name="agent">The agent whose rule is being considered</param> | ||
| /// <param name="trigger">The rule trigger</param> | ||
| /// <param name="context">The per-request criteria context</param> | ||
| /// <returns> | ||
| /// True if the rule should be executed for this request, false if it should be skipped, | ||
| /// or null when the evaluator could not produce an answer (missing script/template, | ||
| /// failed execution, error). | ||
| /// </returns> | ||
| Task<bool?> EvaluateAsync(Agent agent, IRuleTrigger trigger, RuleCriteriaContext context); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Infrastructure/BotSharp.Abstraction/Rules/Models/RuleCriteriaContext.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| namespace BotSharp.Abstraction.Rules.Models; | ||
|
|
||
| /// <summary> | ||
| /// The per-request context passed to an <see cref="IRuleCriteriaEvaluator"/> | ||
| /// to decide whether a rule should be executed. | ||
| /// </summary> | ||
| public class RuleCriteriaContext | ||
| { | ||
| /// <summary> | ||
| /// The trigger message text. | ||
| /// </summary> | ||
| public string Text { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// The criteria options (evaluator type and its arguments). | ||
| /// </summary> | ||
| public CriteriaOptions Options { get; set; } = new(); | ||
|
|
||
| /// <summary> | ||
| /// The conversation states carried with the request. | ||
| /// </summary> | ||
| public IEnumerable<MessageState>? States { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Criteria data can throw
🐞 Bug☼ ReliabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools