diff --git a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs b/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs index 92b37efa9..c73de5bb4 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs @@ -12,6 +12,7 @@ public class FunctionCallFromLlm : RoutingArgs [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public JsonDocument? Arguments { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.Always)] public bool IsExecutionOnce { get; set; } public override string ToString() diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs index 39b532856..7743ef03c 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs @@ -36,6 +36,12 @@ public async Task Handle(IRoutingService routing, FunctionCallFromLlm inst var ret = await function.Execute(message); var agentId = context.GetCurrentAgentId(); + + // Update next action agent's name + var agentService = _services.GetRequiredService(); + var agent = await agentService.LoadAgent(agentId); + inst.AgentName = agent.Name; + if (inst.IsExecutionOnce) { message.Content = inst.Question; diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs index 6fde9dce5..50b3587b0 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs @@ -1,5 +1,6 @@ using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.MLTasks.Settings; +using BotSharp.Abstraction.Routing.Models; using BotSharp.Abstraction.Templating; namespace BotSharp.Core.Routing; @@ -33,7 +34,7 @@ public async Task InvokeAgent(string agentId, List dialog message.FunctionName = response.FunctionName; message.FunctionArgs = response.FunctionArgs; message.CurrentAgentId = agent.Id; - await InvokeFunction(agent, message, dialogs); + await InvokeFunction(message, dialogs); } else { @@ -47,7 +48,7 @@ public async Task InvokeAgent(string agentId, List dialog return true; } - private async Task InvokeFunction(Agent agent, RoleDialogModel message, List dialogs) + private async Task InvokeFunction(RoleDialogModel message, List dialogs) { // execute function // Save states @@ -61,9 +62,12 @@ private async Task InvokeFunction(Agent agent, RoleDialogModel message, Li // Pass execution result to LLM to get response if (!message.StopCompletion) { + var routing = _services.GetRequiredService(); + var agentId = routing.GetCurrentAgentId(); + // Find response template var templateService = _services.GetRequiredService(); - var responseTemplate = await templateService.RenderFunctionResponse(agent.Id, message); + var responseTemplate = await templateService.RenderFunctionResponse(agentId, message); if (!string.IsNullOrEmpty(responseTemplate)) { dialogs.Add(RoleDialogModel.From(message, @@ -78,7 +82,7 @@ private async Task InvokeFunction(Agent agent, RoleDialogModel message, Li content: message.Content)); // Send to LLM - await InvokeAgent(agent.Id, dialogs); + await InvokeAgent(agentId, dialogs); } } else