OnConversationRedirected
This commit is contained in:
parent
baae5bc938
commit
f4b4ca4329
|
|
@ -91,4 +91,9 @@ public abstract class ConversationHookBase : IConversationHook
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual Task OnConversationRedirected(string toAgentId, RoleDialogModel message)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,4 +82,12 @@ public interface IConversationHook
|
||||||
/// <param name="conversation"></param>
|
/// <param name="conversation"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task OnHumanInterventionNeeded(RoleDialogModel message);
|
Task OnHumanInterventionNeeded(RoleDialogModel message);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Conversation is redirected to another agent
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="toAgentId"></param>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task OnConversationRedirected(string toAgentId, RoleDialogModel message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,5 @@ public static class ContentLogSource
|
||||||
public const string Prompt = "prompt";
|
public const string Prompt = "prompt";
|
||||||
public const string FunctionCall = "function call";
|
public const string FunctionCall = "function call";
|
||||||
public const string AgentResponse = "agent response";
|
public const string AgentResponse = "agent response";
|
||||||
|
public const string HardRule = "hard rule";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,11 @@ public class RouteToAgentFn : IFunctionCallback
|
||||||
#else
|
#else
|
||||||
logger.LogInformation($"*** Routing redirect to {record.Name.ToUpper()} ***");
|
logger.LogInformation($"*** Routing redirect to {record.Name.ToUpper()} ***");
|
||||||
#endif
|
#endif
|
||||||
|
var hooks = _services.GetServices<IConversationHook>();
|
||||||
|
foreach (var hook in hooks)
|
||||||
|
{
|
||||||
|
hook.OnConversationRedirected(routingRule.RedirectTo, message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,18 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook
|
||||||
BuildContentLog(conversationId, _user.UserName, log, ContentLogSource.UserInput, message));
|
BuildContentLog(conversationId, _user.UserName, log, ContentLogSource.UserInput, message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task OnConversationRedirected(string toAgentId, RoleDialogModel message)
|
||||||
|
{
|
||||||
|
var agentService = _services.GetRequiredService<IAgentService>();
|
||||||
|
var conversationId = _state.GetConversationId();
|
||||||
|
var fromAgent = await agentService.LoadAgent(message.CurrentAgentId);
|
||||||
|
var toAgent = await agentService.LoadAgent(toAgentId);
|
||||||
|
|
||||||
|
var log = $"{message.Content}\r\n=====\r\nREDIRECTED TO {toAgent.Name}";
|
||||||
|
await _chatHub.Clients.User(_user.Id).SendAsync("OnConversationContentLogGenerated",
|
||||||
|
BuildContentLog(conversationId, fromAgent.Name, log, ContentLogSource.HardRule, message));
|
||||||
|
}
|
||||||
|
|
||||||
public async Task BeforeGenerating(Agent agent, List<RoleDialogModel> conversations)
|
public async Task BeforeGenerating(Agent agent, List<RoleDialogModel> conversations)
|
||||||
{
|
{
|
||||||
if (!_convSettings.ShowVerboseLog) return;
|
if (!_convSettings.ShowVerboseLog) return;
|
||||||
|
|
@ -83,23 +95,26 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook
|
||||||
var agent = await agentService.LoadAgent(message.CurrentAgentId);
|
var agent = await agentService.LoadAgent(message.CurrentAgentId);
|
||||||
var logSource = string.Empty;
|
var logSource = string.Empty;
|
||||||
|
|
||||||
|
var log = tokenStats.Prompt;
|
||||||
|
logSource = ContentLogSource.Prompt;
|
||||||
|
await _chatHub.Clients.User(_user.Id).SendAsync("OnConversationContentLogGenerated",
|
||||||
|
BuildContentLog(conversationId, agent?.Name, log, logSource, message));
|
||||||
|
|
||||||
// Log routing output
|
// Log routing output
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var inst = message.Content.JsonContent<FunctionCallFromLlm>();
|
var inst = message.Content.JsonContent<FunctionCallFromLlm>();
|
||||||
logSource = ContentLogSource.AgentResponse;
|
if (!string.IsNullOrEmpty(inst.Function))
|
||||||
await _chatHub.Clients.User(_user.Id).SendAsync("OnConversationContentLogGenerated",
|
{
|
||||||
BuildContentLog(conversationId, agent?.Name, message.Content, logSource, message));
|
logSource = ContentLogSource.AgentResponse;
|
||||||
|
await _chatHub.Clients.User(_user.Id).SendAsync("OnConversationContentLogGenerated",
|
||||||
|
BuildContentLog(conversationId, agent?.Name, message.Content, logSource, message));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
var log = tokenStats.Prompt;
|
|
||||||
logSource = ContentLogSource.Prompt;
|
|
||||||
await _chatHub.Clients.User(_user.Id).SendAsync("OnConversationContentLogGenerated",
|
|
||||||
BuildContentLog(conversationId, agent?.Name, log, logSource, message));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -118,7 +133,7 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook
|
||||||
{
|
{
|
||||||
var agentService = _services.GetRequiredService<IAgentService>();
|
var agentService = _services.GetRequiredService<IAgentService>();
|
||||||
var agent = await agentService.LoadAgent(message.CurrentAgentId);
|
var agent = await agentService.LoadAgent(message.CurrentAgentId);
|
||||||
var log = $"[{agent?.Name}]: {message.Content}";
|
var log = $"{message.Content}";
|
||||||
if (message.RichContent != null && message.RichContent.Message.RichType != "text")
|
if (message.RichContent != null && message.RichContent.Message.RichType != "text")
|
||||||
{
|
{
|
||||||
var richContent = JsonSerializer.Serialize(message.RichContent, _serializerOptions);
|
var richContent = JsonSerializer.Serialize(message.RichContent, _serializerOptions);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue