using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.Repositories; using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Settings; namespace BotSharp.Core.Routing.Handlers; public class RetrieveDataFromAgentRoutingHandler : RoutingHandlerBase, IRoutingHandler { public string Name => "retrieve_data_from_agent"; public string Description => "Retrieve data from appropriate agent."; public List Parameters => new List { new ParameterPropertyDef("agent", "the name of the agent"), new ParameterPropertyDef("question", "the question you will ask the agent to get the necessary data"), new ParameterPropertyDef("reason", "why retrieve data"), new ParameterPropertyDef("args", "required parameters extracted from question and hand over to the next agent") { Type = "object" } }; public List Planers => new List { "FeedbackReasoningPlanner" }; public RetrieveDataFromAgentRoutingHandler(IServiceProvider services, ILogger logger, RoutingSettings settings) : base(services, logger, settings) { } public async Task Handle(IRoutingService routing, FunctionCallFromLlm inst, RoleDialogModel message) { // Retrieve information from specific agent var db = _services.GetRequiredService(); var record = db.GetAgents(inst.AgentName).FirstOrDefault(); var ret = await routing.InvokeAgent(record.Id, message); /*_dialogs.Add(new RoleDialogModel(AgentRole.Assistant, inst.Parameters.Question) { CurrentAgentId = record.Id });*/ _router.Instruction += $"\r\n{AgentRole.Assistant}: {inst.Question}"; /*_dialogs.Add(new RoleDialogModel(AgentRole.Function, inst.Parameters.Answer) { MessageId = inst.MessageId, FunctionName = inst.Function, FunctionArgs = JsonSerializer.Serialize(inst.Parameters.Arguments), ExecutionResult = inst.Parameters.Answer, ExecutionData = response.ExecutionData, CurrentAgentId = record.Id });*/ _router.Instruction += $"\r\n{AgentRole.Function}: {message.Content}"; // Got the response from agent, then send to reasoner again to make the decision // inst = await GetNextInstructionFromReasoner($"What's the next step based on user's original goal and function result?"); return true; } }