Add conversation summary for human_intervention_needed

This commit is contained in:
Haiping Chen 2024-03-03 13:29:10 -06:00
parent 5b7e2c64c2
commit 885097ff3d
4 changed files with 14 additions and 5 deletions

View file

@ -25,6 +25,12 @@ public class FunctionCallFromLlm : RoutingArgs
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public bool UnmatchedAgent { get; set; }
/// <summary>
/// Conversation summary
/// </summary>
[JsonPropertyName("summary")]
public string? Summary { get; set; }
public override string ToString()
{
var route = string.IsNullOrEmpty(AgentName) ? "" : $"<Route to {AgentName.ToUpper()} because {Reason}>";

View file

@ -1,5 +1,3 @@
using BotSharp.Abstraction.Functions.Models;
using BotSharp.Abstraction.Routing;
using BotSharp.Abstraction.Routing.Settings;
namespace BotSharp.Core.Routing.Handlers;
@ -13,6 +11,7 @@ public class HumanInterventionNeededHandler : RoutingHandlerBase, IRoutingHandle
public List<ParameterPropertyDef> Parameters => new List<ParameterPropertyDef>
{
new ParameterPropertyDef("reason", "why need customer service"),
new ParameterPropertyDef("summary", "the whole conversation summary with important information"),
new ParameterPropertyDef("response", "response content to user")
};

View file

@ -68,7 +68,9 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
{
var conversationId = _state.GetConversationId();
var agent = await _agentService.LoadAgent(message.CurrentAgentId);
var log = $"{message.FunctionName}({message.FunctionArgs})\r\n => {message.Content}";
message.FunctionArgs = message.FunctionArgs ?? "{}";
var args = JsonSerializer.Serialize(JsonDocument.Parse(message.FunctionArgs), _serializerOptions);
var log = $"*{message.FunctionName}*\r\n```json\r\n{args}\r\n```\r\n=> {message.Content?.Trim()}";
var input = new ContentLogInputModel(conversationId, message)
{
@ -123,7 +125,7 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
if (message.RichContent != null && message.RichContent.Message.RichType != "text")
{
var richContent = JsonSerializer.Serialize(message.RichContent, _serializerOptions);
log += $"\r\n{richContent}";
log += $"\r\n```json\r\n{richContent}\r\n```";
}
var input = new ContentLogInputModel(conv.ConversationId, message)
@ -226,6 +228,7 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
var conversationId = _state.GetConversationId();
var agent = await _agentService.LoadAgent(message.CurrentAgentId);
var log = JsonSerializer.Serialize(instruct, _serializerOptions);
log = $"```json\r\n{log}\r\n```";
var input = new ContentLogInputModel(conversationId, message)
{

View file

@ -4,6 +4,7 @@ using BotSharp.Abstraction.Messaging;
using BotSharp.Abstraction.Messaging.Models.RichContent;
using BotSharp.Abstraction.Messaging.Models.RichContent.Template;
using System.Linq;
using System.Text.Json;
namespace BotSharp.Plugin.PizzaBot.Functions;
@ -26,7 +27,7 @@ public class GetPizzaTypesFn : IFunctionCallback
"Cheese Pizza",
"Margherita Pizza"
};
message.Data = pizzaTypes;
message.Content = JsonSerializer.Serialize(pizzaTypes);
message.RichContent = new RichContent<IRichMessage>
{
Recipient = new Recipient