Skip to content

Commit d807ec6

Browse files
author
Jicheng Lu
committed
add rule trigger statement
1 parent d3a45c5 commit d807ec6

File tree

6 files changed

+18
-5
lines changed

6 files changed

+18
-5
lines changed

src/Infrastructure/BotSharp.Abstraction/Rules/IRuleTrigger.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ public interface IRuleTrigger
1616
/// The default arguments as input to code trigger (display purpose)
1717
/// </summary>
1818
JsonDocument OutputArgs => JsonDocument.Parse("{}");
19+
20+
/// <summary>
21+
/// Explain the purpose of rule trigger (display purpose)
22+
/// </summary>
23+
string Statement => string.Empty;
1924
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private IEnumerable<KeyValue> BuildArguments(string? name, JsonDocument? args)
159159
var keyValues = new List<KeyValue>();
160160
if (args != null)
161161
{
162-
keyValues.Add(new KeyValue(name ?? "rule_args", args.RootElement.GetRawText()));
162+
keyValues.Add(new KeyValue(name ?? "trigger_args", args.RootElement.GetRawText()));
163163
}
164164
return keyValues;
165165
}

src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private async Task<BinaryData> DownloadFile(InstructFileModel file)
8181
private string BuildFileName(string? name, string? extension, string defaultName, string defaultExtension)
8282
{
8383
var fname = name.IfNullOrEmptyAs(defaultName);
84-
var fextension = extension.IfNullOrEmptyAs(defaultExtension);
84+
var fextension = extension.IfNullOrEmptyAs(defaultExtension)!;
8585
fextension = fextension.StartsWith(".") ? fextension.Substring(1) : fextension;
8686
return $"{name}.{fextension}";
8787
}

src/Infrastructure/BotSharp.Core/data/agents/c2a2faf6-b8b5-47fe-807b-f4714cf25dd4/templates/rule-trigger-code-generate_instruction.liquid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ User's request is {{user_request}}
44

55
Couple of notes to address:
66
1. You need to generate a function named check_trigger_criterion(args), where input is a json object. The example of this json object is {{args_example}}.
7-
2. The input to this function comes from the arguments. You must use "ArgumentParser" to take an argument named "states", and then use "parse_known_args" to get the raw args.
7+
2. The input to this function comes from the arguments. You must use "ArgumentParser" to take an argument named "trigger_args", and then use "parse_known_args" to get the raw args.
88
3. After getting the raw args, you need to use 'clean_args = bytes(raw_args, "utf-8").decode("unicode_escape")' to clean the raw argument, and then use 'args = json.loads(clean_args)' to get the json args.
99
4. Based on the user's request and input args, generate the function logic and ONLY return a boolean value.
1010
5. You must only call check_trigger_criterion with the parsed json args in "if __name__ == '__main__'" block, and print only the function output. If any error occurs, print "Error".

src/Infrastructure/BotSharp.OpenAPI/Controllers/Agent/AgentController.Rule.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ public IEnumerable<AgentRuleViewModel> GetRuleTriggers()
1111
var triggers = _services.GetServices<IRuleTrigger>();
1212
return triggers.Select(x => new AgentRuleViewModel
1313
{
14-
TriggerName = x.GetType().Name,
14+
TriggerName = x.Name,
15+
Channel = x.Channel,
16+
Statement = x.Statement,
1517
OutputArgs = x.OutputArgs
16-
}).OrderBy(x => x.TriggerName).ToList();
18+
}).OrderBy(x => x.TriggerName);
1719
}
1820

1921
[HttpGet("/rule/formalization")]

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/View/AgentRuleViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ public class AgentRuleViewModel
77
[JsonPropertyName("trigger_name")]
88
public string TriggerName { get; set; } = string.Empty;
99

10+
[JsonPropertyName("channel")]
11+
public string Channel { get; set; } = string.Empty;
12+
13+
[JsonPropertyName("statement")]
14+
public string Statement { get; set; } = string.Empty;
15+
1016
[JsonPropertyName("output_args")]
1117
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
1218
public JsonDocument? OutputArgs { get; set; }

0 commit comments

Comments
 (0)