diff --git a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs b/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs index 14ac7796..c04a1e99 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs @@ -5,18 +5,9 @@ namespace BotSharp.Abstraction.Functions.Models; public class FunctionCallFromLlm : RoutingArgs { - [JsonPropertyName("function")] - public string Function { get; set; } = string.Empty; - - [JsonPropertyName("reason")] - public string Reason { get; set; } = string.Empty; - [JsonPropertyName("question")] public string? Question { get; set; } - [JsonPropertyName("answer")] - public string Answer { get; set; } = string.Empty; - [JsonPropertyName("args")] public JsonDocument Arguments { get; set; } = JsonDocument.Parse("{}"); diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs index a6c39df3..d3c1bb65 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs @@ -2,11 +2,29 @@ namespace BotSharp.Abstraction.Routing.Models; public class RoutingArgs { + [JsonPropertyName("function")] + public string Function { get; set; } = string.Empty; + + [JsonPropertyName("reason")] + public string Reason { get; set; } = string.Empty; + + [JsonPropertyName("answer")] + public string Answer { get; set; } = string.Empty; + [JsonPropertyName("agent")] public string AgentName { get; set; } = string.Empty; public override string ToString() { - return AgentName; + var route = string.IsNullOrEmpty(AgentName) ? "" : $""; + + if (string.IsNullOrEmpty(Answer)) + { + return $"[{Function} {route}]"; + } + else + { + return $"[{Function} {route}] => {Answer}"; + } } } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/TokenStatistics.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/TokenStatistics.cs index cd094e98..1654b357 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/TokenStatistics.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/TokenStatistics.cs @@ -51,7 +51,7 @@ public class TokenStatistics : ITokenStatistics public void PrintStatistics() { - var stats = $"Token Usage: {_promptTokenCount} prompt + {_completionTokenCount} completion = {Total} total (${Cost:C4}), accumulated cost: ${AccumulatedCost:C4}, model: ${_model}"; + var stats = $"Token Usage: {_promptTokenCount} prompt + {_completionTokenCount} completion = {Total} total tokens. One-Way cost: ${Cost:C4}, accumulated cost: ${AccumulatedCost:C4}. Model: {_model}"; #if DEBUG Console.WriteLine(stats, Color.DarkGray); #else diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/ResponseToUserRoutingHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/ResponseToUserRoutingHandler.cs index 41d7d874..77368127 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/ResponseToUserRoutingHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/ResponseToUserRoutingHandler.cs @@ -9,7 +9,7 @@ public class ResponseToUserRoutingHandler : RoutingHandlerBase, IRoutingHandler { public string Name => "response_to_user"; - public string Description => "You know how to response according to the context, don't need to ask specific agent."; + public string Description => "You know how to response according to the context without asking specific agent. For example user greeting."; public List Parameters => new List { diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RoutingHandlerBase.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RoutingHandlerBase.cs index 0af2f01d..458557fa 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RoutingHandlerBase.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RoutingHandlerBase.cs @@ -1,5 +1,6 @@ using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.Functions.Models; +using BotSharp.Abstraction.Routing.Models; using BotSharp.Abstraction.Routing.Settings; using BotSharp.Abstraction.Templating; using System.Drawing; @@ -37,7 +38,12 @@ public abstract class RoutingHandlerBase public async Task GetNextInstructionFromReasoner(string prompt) { - var responseFormat = JsonSerializer.Serialize(new FunctionCallFromLlm()); + var responseFormat = _settings.EnableReasoning ? + JsonSerializer.Serialize(new FunctionCallFromLlm()) : + JsonSerializer.Serialize(new RoutingArgs + { + Function = "route_to_agent" + }); var content = $"{prompt} Response must be in JSON format {responseFormat}"; var chatCompletion = CompletionProvider.GetChatCompletion(_services, diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs index 224379ce..665425d4 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs @@ -81,7 +81,8 @@ public class RoutingService : IRoutingService { loopCount++; - var inst = await handler.GetNextInstructionFromReasoner($"Tell me the next step?"); + var prompt = _settings.EnableReasoning ? "Tell me the next step?" : "Which agent is suitable to handle user's request?"; + var inst = await handler.GetNextInstructionFromReasoner(prompt); inst.Question = inst.Question ?? message; handler = handlers.FirstOrDefault(x => x.Name == inst.Function);