Skip to content

Commit 885097f

Browse files
committed
Add conversation summary for human_intervention_needed
1 parent 5b7e2c6 commit 885097f

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public class FunctionCallFromLlm : RoutingArgs
2525
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
2626
public bool UnmatchedAgent { get; set; }
2727

28+
/// <summary>
29+
/// Conversation summary
30+
/// </summary>
31+
[JsonPropertyName("summary")]
32+
public string? Summary { get; set; }
33+
2834
public override string ToString()
2935
{
3036
var route = string.IsNullOrEmpty(AgentName) ? "" : $"<Route to {AgentName.ToUpper()} because {Reason}>";

‎src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using BotSharp.Abstraction.Functions.Models;
2-
using BotSharp.Abstraction.Routing;
31
using BotSharp.Abstraction.Routing.Settings;
42

53
namespace BotSharp.Core.Routing.Handlers;
@@ -13,6 +11,7 @@ public class HumanInterventionNeededHandler : RoutingHandlerBase, IRoutingHandle
1311
public List<ParameterPropertyDef> Parameters => new List<ParameterPropertyDef>
1412
{
1513
new ParameterPropertyDef("reason", "why need customer service"),
14+
new ParameterPropertyDef("summary", "the whole conversation summary with important information"),
1615
new ParameterPropertyDef("response", "response content to user")
1716
};
1817

‎src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public override async Task OnFunctionExecuted(RoleDialogModel message)
6868
{
6969
var conversationId = _state.GetConversationId();
7070
var agent = await _agentService.LoadAgent(message.CurrentAgentId);
71-
var log = $"{message.FunctionName}({message.FunctionArgs})\r\n => {message.Content}";
71+
message.FunctionArgs = message.FunctionArgs ?? "{}";
72+
var args = JsonSerializer.Serialize(JsonDocument.Parse(message.FunctionArgs), _serializerOptions);
73+
var log = $"*{message.FunctionName}*\r\n```json\r\n{args}\r\n```\r\n=> {message.Content?.Trim()}";
7274

7375
var input = new ContentLogInputModel(conversationId, message)
7476
{
@@ -123,7 +125,7 @@ public override async Task OnResponseGenerated(RoleDialogModel message)
123125
if (message.RichContent != null && message.RichContent.Message.RichType != "text")
124126
{
125127
var richContent = JsonSerializer.Serialize(message.RichContent, _serializerOptions);
126-
log += $"\r\n{richContent}";
128+
log += $"\r\n```json\r\n{richContent}\r\n```";
127129
}
128130

129131
var input = new ContentLogInputModel(conv.ConversationId, message)
@@ -226,6 +228,7 @@ public async Task OnRoutingInstructionReceived(FunctionCallFromLlm instruct, Rol
226228
var conversationId = _state.GetConversationId();
227229
var agent = await _agentService.LoadAgent(message.CurrentAgentId);
228230
var log = JsonSerializer.Serialize(instruct, _serializerOptions);
231+
log = $"```json\r\n{log}\r\n```";
229232

230233
var input = new ContentLogInputModel(conversationId, message)
231234
{

‎tests/BotSharp.Plugin.PizzaBot/Functions/GetPizzaTypesFn.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BotSharp.Abstraction.Messaging.Models.RichContent;
55
using BotSharp.Abstraction.Messaging.Models.RichContent.Template;
66
using System.Linq;
7+
using System.Text.Json;
78

89
namespace BotSharp.Plugin.PizzaBot.Functions;
910

@@ -26,7 +27,7 @@ public async Task<bool> Execute(RoleDialogModel message)
2627
"Cheese Pizza",
2728
"Margherita Pizza"
2829
};
29-
message.Data = pizzaTypes;
30+
message.Content = JsonSerializer.Serialize(pizzaTypes);
3031
message.RichContent = new RichContent<IRichMessage>
3132
{
3233
Recipient = new Recipient

0 commit comments

Comments
 (0)