From 0cfb28fce7beaf97c0643e0c5d95da8db9c453ef Mon Sep 17 00:00:00 2001 From: Vitali sharp8n Date: Tue, 29 Sep 2026 09:43:33 +0300 Subject: [PATCH] fix limiter --- .../BotSharp.Core/Routing/RoutingService.InvokeAgent.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs index ccd176a4..eb5017cd 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs @@ -18,6 +18,14 @@ public partial class RoutingService if (Context.CurrentRecursionDepth > agent.LlmConfig.MaxRecursionDepth) { _logger.LogWarning($"Current recursive call depth greater than {agent.LlmConfig.MaxRecursionDepth}, which will cause unexpected result."); + // The caller surfaces the LAST dialog as the turn's reply, so returning here with a tool + // frame on top of the history would answer the user with a raw tool result. Add an + // explicit notice so an exhausted tool loop always ends with an assistant message. + var limit = RoleDialogModel.From(dialogs.Last(), role: AgentRole.Assistant, + content: "Stopped after reaching this agent's tool-call limit without a final answer."); + limit.CurrentAgentId = agent.Id; + dialogs.Add(limit); + Context.AddDialogs([limit]); return false; }