using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Models; using BotSharp.Abstraction.Routing.Settings; using BotSharp.Core.Planning; namespace BotSharp.Core.Routing.Handlers; /// /// Retrieve information from specific agent /// 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("reason", "why choose this function"), new ParameterPropertyDef("question", "the question you will ask the next action agent to get the necessary information"), new ParameterPropertyDef("next_action_agent", "agent that can handle the question"), new ParameterPropertyDef("user_goal_agent", "agent that can achieve user original goal"), new ParameterPropertyDef("args", "required parameters extracted from question and hand over to the next agent") { Type = "object" } }; public List Planers => new List { nameof(HFPlanner) }; public RetrieveDataFromAgentRoutingHandler(IServiceProvider services, ILogger logger, RoutingSettings settings) : base(services, logger, settings) { } public async Task Handle(IRoutingService routing, FunctionCallFromLlm inst, RoleDialogModel message) { var context = _services.GetRequiredService(); var agentId = context.GetCurrentAgentId(); var dialogs = new List { new RoleDialogModel(AgentRole.User, inst.Question) { CurrentAgentId = agentId, MessageId = message.MessageId } }; var ret = await routing.InvokeAgent(agentId, dialogs); var response = dialogs.Last(); inst.Response = response.Content; // Add final response to parent dialog _dialogs.Add(response); return ret; } }