From 9d6f5dc22d8385a701d4c016f87c43c5730ce356 Mon Sep 17 00:00:00 2001 From: Vitali sharp8n Date: Mon, 14 Sep 2026 17:27:38 +0300 Subject: [PATCH] enchancements --- .../Routing/RoutingService.InvokeAgent.cs | 4 ++++ .../Routing/RoutingService.InvokeFunction.cs | 3 +++ .../Providers/Chat/ChatCompletionProvider.cs | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs index e4465f27..adb169a4 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs @@ -124,6 +124,10 @@ public partial class RoutingService var msg = RoleDialogModel.From(message, role: AgentRole.Function, content: message.Content); + // Preserve images produced by the tool (e.g. `browser_act screenshot`) so the next + // LLM round in this turn can attach them to the tool message for a multimodal model. + // They are not persisted (ConversationStorage ignores dialog.Files). + msg.Files = message.Files; dialogs.Add(msg); Context.AddDialogs([msg]); diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs index 3850dcc1..bfec68c0 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs @@ -66,6 +66,9 @@ public partial class RoutingService message.RichContent = clonedMessage.RichContent; message.Data = clonedMessage.Data; message.MessageLabel = clonedMessage.MessageLabel; + // Tools may return images (e.g. a browser screenshot). Carry them back from the clone so + // the function dialog handed to the LLM can include the tool-produced image content. + message.Files = clonedMessage.Files; } catch (JsonException ex) { diff --git a/src/Plugins/BotSharp.Plugin.DeepSeekAI/Providers/Chat/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.DeepSeekAI/Providers/Chat/ChatCompletionProvider.cs index 0bde4fac..eebc64d1 100644 --- a/src/Plugins/BotSharp.Plugin.DeepSeekAI/Providers/Chat/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.DeepSeekAI/Providers/Chat/ChatCompletionProvider.cs @@ -524,7 +524,21 @@ public class ChatCompletionProvider : IChatCompletion messages.Add(assistantToolMsg); - messages.Add(new ToolChatMessage(message.ToolCallId.IfNullOrEmptyAs(message.FunctionName), message.LlmContent)); + // A tool may produce images (e.g. `browser_act screenshot`): attach them to the tool + // message so a multimodal model can SEE the tool output instead of only reading the + // file name. Text-only models keep the plain text result. The gateway accepts image + // parts on a `tool` message; these files are transient (never persisted in history). + var toolContentParts = new List + { + ChatMessageContentPart.CreateTextPart(message.LlmContent) + }; + if (allowMultiModal && !message.Files.IsNullOrEmpty()) + { + CollectMessageContentParts(toolContentParts, message.Files, imageDetailLevel); + } + + messages.Add(new ToolChatMessage( + message.ToolCallId.IfNullOrEmptyAs(message.FunctionName), toolContentParts)); } else if (message.Role == AgentRole.User) {