diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs index a83cb4b35..cfbfe31e8 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Infrastructures.Enums; using BotSharp.Abstraction.Routing.Settings; namespace BotSharp.Core.Routing.Handlers; @@ -39,11 +40,8 @@ public RouteToAgentRoutingHandler(IServiceProvider services, ILogger Handle(IRoutingService routing, FunctionCallFromLlm inst, RoleDialogModel message) { - message.FunctionArgs = JsonSerializer.Serialize(inst); - var ret = await routing.InvokeFunction(message.FunctionName, message); - var states = _services.GetRequiredService(); - var goalAgent = states.GetState("user_goal_agent"); + var goalAgent = states.GetState(StateConst.EXPECTED_GOAL_AGENT); if (!string.IsNullOrEmpty(goalAgent) && inst.OriginalAgent != goalAgent) { inst.OriginalAgent = goalAgent; @@ -53,6 +51,9 @@ await hook.OnRoutingInstructionRevised(inst, message) ); } + message.FunctionArgs = JsonSerializer.Serialize(inst); + var ret = await routing.InvokeFunction(message.FunctionName, message); + var agentId = routing.Context.GetCurrentAgentId(); // Update next action agent's name diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs index 940e3dec7..ce6701b07 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs @@ -326,7 +326,7 @@ public async Task OnRoutingInstructionRevised(FunctionCallFromLlm instruct, Role { var conversationId = _state.GetConversationId(); var agent = await _agentService.LoadAgent(message.CurrentAgentId); - var log = $"Revised user goal agent to: {agent?.Name}"; + var log = $"Revised user goal agent to {instruct.OriginalAgent}"; var input = new ContentLogInputModel(conversationId, message) {