diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs index df2d63132..44d41f319 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs @@ -5,9 +5,6 @@ public class RoutingArgs [JsonPropertyName("function")] public string Function { get; set; } = "route_to_agent"; - [JsonPropertyName("function_args")] - public string? FunctionArgs { get; set; } - /// /// The reason why you select this function or agent /// diff --git a/src/Infrastructure/BotSharp.Core/Routing/Reasoning/HFReasoner.cs b/src/Infrastructure/BotSharp.Core/Routing/Reasoning/HFReasoner.cs index 9f1b5fd52..7af5e63e9 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Reasoning/HFReasoner.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Reasoning/HFReasoner.cs @@ -51,20 +51,8 @@ public async Task GetNextInstruction(Agent router, string m } }; var response = await completion.GetChatCompletions(router, dialogs); - var inst = response.Content.JsonContent(); - if (inst != null) - { - if (!string.IsNullOrEmpty(response.FunctionName)) - { - inst.Function = response.FunctionName; - } - - if (!string.IsNullOrEmpty(response.FunctionArgs)) - { - inst.FunctionArgs = response.FunctionArgs; - } - } + var inst = response.Content.JsonContent(); // Fix LLM malformed response await ReasonerHelper.FixMalformedResponse(_services, inst); @@ -85,14 +73,7 @@ public async Task AgentExecuting(Agent router, FunctionCallFromLlm inst, R // Set user content as Planner's question message.FunctionName = inst.Function; - if (!string.IsNullOrEmpty(inst.FunctionArgs)) - { - message.FunctionArgs = inst.FunctionArgs; - } - else - { - message.FunctionArgs = inst.Arguments == null ? "{}" : JsonSerializer.Serialize(inst.Arguments); - } + message.FunctionArgs = inst.Arguments == null ? "{}" : JsonSerializer.Serialize(inst.Arguments); } return true; diff --git a/src/Infrastructure/BotSharp.Core/Routing/Reasoning/InstructExecutor.cs b/src/Infrastructure/BotSharp.Core/Routing/Reasoning/InstructExecutor.cs index 0c10f75fe..23eee53d2 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Reasoning/InstructExecutor.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Reasoning/InstructExecutor.cs @@ -31,19 +31,10 @@ await HookEmitter.Emit(_services, async hook => await hook.OnRouti } message.FunctionArgs = JsonSerializer.Serialize(inst); - if (!string.IsNullOrEmpty(inst.FunctionArgs)) - { - message.FunctionArgs = inst.FunctionArgs; - } - if (!string.IsNullOrEmpty(message.FunctionName)) { var msg = RoleDialogModel.From(message, role: AgentRole.Function); await routing.InvokeFunction(message.FunctionName, msg, options: new() { From = InvokeSource.Routing }); - if (msg.StopCompletion) - { - message = RoleDialogModel.From(msg, role: AgentRole.Assistant); - } } var agentId = routing.Context.GetCurrentAgentId(); @@ -85,8 +76,8 @@ await HookEmitter.Emit(_services, async hook => await hook.OnRouti } var response = dialogs.Last(); + response.Instruction = inst; - response.StopCompletion = message.StopCompletion; return response; } diff --git a/src/Infrastructure/BotSharp.Core/Routing/Reasoning/NaiveReasoner.cs b/src/Infrastructure/BotSharp.Core/Routing/Reasoning/NaiveReasoner.cs index 5cab06725..39e8be430 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Reasoning/NaiveReasoner.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Reasoning/NaiveReasoner.cs @@ -57,18 +57,6 @@ public async Task GetNextInstruction(Agent router, string m var response = await completion.GetChatCompletions(router, dialogs); var inst = (response.FunctionArgs ?? response.Content).JsonContent(); - if (inst != null) - { - if (!string.IsNullOrEmpty(response.FunctionName)) - { - inst.Function = response.FunctionName; - } - - if (!string.IsNullOrEmpty(response.FunctionArgs)) - { - inst.FunctionArgs = response.FunctionArgs; - } - } // Fix LLM malformed response await ReasonerHelper.FixMalformedResponse(_services, inst); @@ -80,14 +68,7 @@ public Task AgentExecuting(Agent router, FunctionCallFromLlm inst, RoleDia { // Set user content as Planner's question message.FunctionName = inst.Function; - if (!string.IsNullOrEmpty(inst.FunctionArgs)) - { - message.FunctionArgs = inst.FunctionArgs; - } - else - { - message.FunctionArgs = inst.Arguments == null ? "{}" : JsonSerializer.Serialize(inst.Arguments); - } + message.FunctionArgs = inst.Arguments == null ? "{}" : JsonSerializer.Serialize(inst.Arguments); return Task.FromResult(true); } diff --git a/src/Infrastructure/BotSharp.Core/Routing/Reasoning/OneStepForwardReasoner.cs b/src/Infrastructure/BotSharp.Core/Routing/Reasoning/OneStepForwardReasoner.cs index 49463238f..3af0614da 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Reasoning/OneStepForwardReasoner.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Reasoning/OneStepForwardReasoner.cs @@ -67,22 +67,8 @@ public async Task GetNextInstruction(Agent router, string m // eliminating format drift where the LLM completes with finishReason=stop and returns // free text or JSON in Content instead of a structured function call. var response = await GetChatCompletionsWithScopedState(completion, router, dialogs, "tool_choice", "required"); - var inst = response.FunctionArgs?.JsonContent(); - - if (inst != null) - { - if (!string.IsNullOrEmpty(response.FunctionName)) - { - inst.Function = response.FunctionName; - } - - if (!string.IsNullOrEmpty(response.FunctionArgs)) - { - inst.FunctionArgs = response.FunctionArgs; - } - } - + var inst = response.FunctionArgs?.JsonContent(); _logger.LogInformation("[OneStepForwardReasoner] ConversationId: {ConversationId}, MessageId: {MessageId}, Next instruction: {Instruction}", _services.GetRequiredService().ConversationId, messageId, response.FunctionArgs); @@ -96,14 +82,7 @@ public Task AgentExecuting(Agent router, FunctionCallFromLlm inst, RoleDia { // Set user content as Planner's question message.FunctionName = inst.Function; - if (!string.IsNullOrEmpty(inst.FunctionArgs)) - { - message.FunctionArgs = inst.FunctionArgs; - } - else - { - message.FunctionArgs = inst.Arguments == null ? "{}" : JsonSerializer.Serialize(inst.Arguments); - } + message.FunctionArgs = inst.Arguments == null ? "{}" : JsonSerializer.Serialize(inst.Arguments); return Task.FromResult(true); }