diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs index 5a67216d4..585112a2a 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs @@ -146,6 +146,7 @@ public static RoleDialogModel From(RoleDialogModel source, FunctionArgs = source.FunctionArgs, FunctionName = source.FunctionName, ToolCallId = source.ToolCallId, + Indication = source.Indication, PostbackFunctionName = source.PostbackFunctionName, RichContent = source.RichContent, Payload = source.Payload, diff --git a/src/Infrastructure/BotSharp.Abstraction/Functions/IFunctionCallback.cs b/src/Infrastructure/BotSharp.Abstraction/Functions/IFunctionCallback.cs index 405777990..b842b5b6d 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Functions/IFunctionCallback.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Functions/IFunctionCallback.cs @@ -9,7 +9,7 @@ public interface IFunctionCallback /// string Indication => string.Empty; - Task GetIndication(RoleDialogModel message) => Task.FromResult(Indication); + Task GetIndication(RoleDialogModel message) => Task.FromResult(message.Indication ?? Indication); Task Execute(RoleDialogModel message); } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs index d217d2c17..87da12b28 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Rendering.cs @@ -111,7 +111,7 @@ public bool RenderFunction(Agent agent, FunctionDef def) parameterDef.Properties = JsonSerializer.Deserialize(clonedRoot.ToString()); parameterDef.Required = required; - return parameterDef; ; + return parameterDef; } public string RenderedTemplate(Agent agent, string templateName) diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs index 39c8ed23e..fbe8c0552 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs @@ -43,6 +43,7 @@ public async Task InvokeAgent(string agentId, List dialog message.ToolCallId = response.ToolCallId; message.FunctionName = response.FunctionName; message.FunctionArgs = response.FunctionArgs; + message.Indication = response.Indication; message.CurrentAgentId = agent.Id; await InvokeFunction(message, dialogs); diff --git a/src/Infrastructure/BotSharp.Logger/Hooks/RateLimitConversationHook.cs b/src/Infrastructure/BotSharp.Logger/Hooks/RateLimitConversationHook.cs index a9a9478f9..9b71214da 100644 --- a/src/Infrastructure/BotSharp.Logger/Hooks/RateLimitConversationHook.cs +++ b/src/Infrastructure/BotSharp.Logger/Hooks/RateLimitConversationHook.cs @@ -52,7 +52,7 @@ public override async Task OnMessageReceived(RoleDialogModel message) var channel = states.GetState("channel"); // Check the number of conversations - if (channel != ConversationChannel.Phone && channel != ConversationChannel.Email) + if (channel != ConversationChannel.Phone && channel != ConversationChannel.Email && channel != ConversationChannel.Database) { var user = _services.GetRequiredService(); var convService = _services.GetRequiredService(); diff --git a/src/Infrastructure/BotSharp.Logger/Hooks/VerboseLogHook.cs b/src/Infrastructure/BotSharp.Logger/Hooks/VerboseLogHook.cs index afb8dd019..9740bb20b 100644 --- a/src/Infrastructure/BotSharp.Logger/Hooks/VerboseLogHook.cs +++ b/src/Infrastructure/BotSharp.Logger/Hooks/VerboseLogHook.cs @@ -41,7 +41,7 @@ public async Task AfterGenerated(RoleDialogModel message, TokenStatsModel tokenS var agent = await agentService.LoadAgent(message.CurrentAgentId); var log = message.Role == AgentRole.Function ? - $"[{agent?.Name}]: {message.FunctionName}({message.FunctionArgs})" : + $"[{agent?.Name}]: {message.Indication} {message.FunctionName}({message.FunctionArgs})" : $"[{agent?.Name}]: {message.Content}" + $" <== [msg_id: {message.MessageId}]"; _logger.LogInformation(tokenStats.Prompt); diff --git a/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj b/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj index d053f4d63..0dc416df4 100644 --- a/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj +++ b/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs index 45ef200e8..8657b31b2 100644 --- a/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs @@ -1,7 +1,6 @@ using Anthropic.SDK.Common; using BotSharp.Abstraction.Conversations; using BotSharp.Abstraction.MLTasks.Settings; -using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Json.Serialization; @@ -48,15 +47,16 @@ public async Task GetChatCompletions(Agent agent, List().FirstOrDefault(); var toolResult = response.Content.OfType().First(); - responseMessage = new RoleDialogModel(AgentRole.Function, response.FirstMessage?.Text ?? string.Empty) + responseMessage = new RoleDialogModel(AgentRole.Function, content?.Text ?? string.Empty) { CurrentAgentId = agent.Id, MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty, ToolCallId = toolResult.Id, FunctionName = toolResult.Name, - FunctionArgs = JsonSerializer.Serialize(toolResult.Input) + FunctionArgs = JsonSerializer.Serialize(toolResult.Input), }; } else @@ -161,7 +161,7 @@ public Task GetChatCompletionsStreamingAsync(Agent agent, List - + diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Chat/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Chat/ChatCompletionProvider.cs index bfce9d982..9f1f692f7 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Chat/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Chat/ChatCompletionProvider.cs @@ -160,6 +160,7 @@ public async Task GetChatCompletionsAsync(Agent agent, var funcContextIn = new RoleDialogModel(AgentRole.Function, text) { CurrentAgentId = agent.Id, + MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty, FunctionName = toolCall?.FunctionName, FunctionArgs = toolCall?.FunctionArguments?.ToString() }; diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs index 5b699b510..aecce9131 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs @@ -116,7 +116,8 @@ public override async Task OnFunctionExecuting(RoleDialogModel message) var agent = await _agentService.LoadAgent(message.CurrentAgentId); message.FunctionArgs = message.FunctionArgs ?? "{}"; var args = message.FunctionArgs.FormatJson(); - var log = $"{message.FunctionName} executing\r\n```json\r\n{args}\r\n```"; + var log = $"*{message.Indication.Replace("\r", string.Empty).Replace("\n", string.Empty)}* \r\n\r\n **{message.FunctionName}**()"; + log += args.Length > 5 ? $" \r\n```json\r\n{args}\r\n```" : string.Empty; var input = new ContentLogInputModel(conversationId, message) { diff --git a/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs index b52013dd6..11ea8f18b 100644 --- a/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs @@ -1,6 +1,7 @@ using BotSharp.Abstraction.Agents; using BotSharp.Abstraction.Agents.Enums; using BotSharp.Abstraction.Loggers; +using Google.Protobuf.WellKnownTypes; using Microsoft.Extensions.Logging; using Mscc.GenerativeAI; @@ -125,6 +126,7 @@ public void SetModelName(string model) if (!agentService.RenderFunction(agent, function)) continue; var def = agentService.RenderFunctionProperty(agent, function); + var str = JsonSerializer.Serialize(def.Properties); funcDeclarations.Add(new FunctionDeclaration { @@ -132,8 +134,8 @@ public void SetModelName(string model) Description = function.Description, Parameters = new() { - Type = ParameterType.Object, - Properties = def.Properties, + Type = str != "{}" ? ParameterType.Object : ParameterType.TypeUnspecified, + Properties = str != "{}" ? JsonSerializer.Deserialize(str) : null, Required = def.Required } }); diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/BotSharp.Plugin.OpenAI.csproj b/src/Plugins/BotSharp.Plugin.OpenAI/BotSharp.Plugin.OpenAI.csproj index e1138d92b..4b7792d23 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/BotSharp.Plugin.OpenAI.csproj +++ b/src/Plugins/BotSharp.Plugin.OpenAI/BotSharp.Plugin.OpenAI.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs index 6f424c336..21756f5d5 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs @@ -138,6 +138,7 @@ public async Task GetChatCompletionsAsync(Agent agent, var funcContextIn = new RoleDialogModel(AgentRole.Function, text) { CurrentAgentId = agent.Id, + MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty, ToolCallId = toolCall?.Id, FunctionName = toolCall?.FunctionName, FunctionArgs = toolCall?.FunctionArguments?.ToString()