2023-09-22 20:38:58 +00:00
|
|
|
using BotSharp.Abstraction.Functions.Models;
|
2023-09-24 16:20:02 +00:00
|
|
|
using BotSharp.Abstraction.Models;
|
2023-09-22 20:38:58 +00:00
|
|
|
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.";
|
|
|
|
|
|
2023-09-24 16:20:02 +00:00
|
|
|
public List<NameDesc> Parameters => new List<NameDesc>
|
2023-09-22 20:38:58 +00:00
|
|
|
{
|
2023-09-24 21:32:58 +00:00
|
|
|
new NameDesc("agent", "the name of the agent"),
|
2023-09-24 16:20:02 +00:00
|
|
|
new NameDesc("question", "the question you will ask the agent to get the necessary data"),
|
|
|
|
|
new NameDesc("reason", "why retrieve data"),
|
|
|
|
|
new NameDesc("args", "required parameters extracted from question and hand over to the next agent")
|
2023-09-22 20:38:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public bool IsReasoning => true;
|
|
|
|
|
|
|
|
|
|
public RetrieveDataFromAgentRoutingHandler(IServiceProvider services, ILogger<RetrieveDataFromAgentRoutingHandler> logger, RoutingSettings settings)
|
|
|
|
|
: base(services, logger, settings)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 12:51:15 +00:00
|
|
|
public async Task<RoleDialogModel> Handle(IRoutingService routing, FunctionCallFromLlm inst)
|
2023-09-22 20:38:58 +00:00
|
|
|
{
|
|
|
|
|
// Retrieve information from specific agent
|
|
|
|
|
var db = _services.GetRequiredService<IBotSharpRepository>();
|
2023-09-25 22:46:00 +00:00
|
|
|
var record = db.Agents.First(x => x.Name.ToLower() == inst.AgentName.ToLower());
|
2023-09-27 12:51:15 +00:00
|
|
|
var response = await routing.InvokeAgent(record.Id);
|
2023-09-22 20:38:58 +00:00
|
|
|
|
|
|
|
|
inst.Answer = response.Content;
|
|
|
|
|
|
|
|
|
|
/*_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)
|
|
|
|
|
{
|
|
|
|
|
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}: {response.Content}";
|
|
|
|
|
|
|
|
|
|
// Got the response from agent, then send to reasoner again to make the decision
|
2023-09-27 12:51:15 +00:00
|
|
|
// inst = await GetNextInstructionFromReasoner($"What's the next step based on user's original goal and function result?");
|
2023-09-22 20:38:58 +00:00
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|