Merge pull request #992 from hchen2020/master

Add route_to_agent log
This commit is contained in:
Haiping 2025-04-03 14:35:36 -05:00 committed by GitHub
commit 818b18bb6e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -1,4 +1,6 @@
using BotSharp.Abstraction.Functions.Models;
using BotSharp.Abstraction.MLTasks.Settings;
using BotSharp.Abstraction.Options;
using BotSharp.Core.Infrastructures;
namespace BotSharp.Core.Realtime.Services;
@ -144,6 +146,12 @@ public class RealtimeHub : IRealtimeHub
if (message.MessageType == MessageTypeName.FunctionCall &&
!string.IsNullOrEmpty(message.FunctionName))
{
if (message.FunctionName == "route_to_agent")
{
var instruction = JsonSerializer.Deserialize<FunctionCallFromLlm>(message.FunctionArgs, BotSharpOptions.defaultJsonOptions);
await HookEmitter.Emit<IRoutingHook>(_services, async hook => await hook.OnRoutingInstructionReceived(instruction, message));
}
await routing.InvokeFunction(message.FunctionName, message);
}
else

View file

@ -163,8 +163,7 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
if (response.Type == "error")
{
var error = JsonSerializer.Deserialize<ServerEventErrorResponse>(receivedText);
_logger.LogError($"Error: {error.Body.Message}");
_logger.LogError($"{response.Type}: {receivedText}");
}
else if (response.Type == "session.created")
{
@ -677,6 +676,7 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
{
Provider = Provider,
Model = _model,
Prompt = "[hook.AfterGenerated] [UNCHANGED PROMPT]",
CompletionCount = data.Usage.OutputTokens,
PromptCount = data.Usage.InputTokens
});