BotSharp/src/Infrastructure/BotSharp.Core/Routing/Handlers/RetrieveDataFromAgentRoutingHandler.cs

67 lines
2.5 KiB
C#
Raw Normal View History

2023-09-22 20:38:58 +00:00
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.";
2023-10-28 20:59:26 +00:00
public List<ParameterPropertyDef> Parameters => new List<ParameterPropertyDef>
2023-09-22 20:38:58 +00:00
{
2023-10-28 20:59:26 +00:00
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"
}
2023-09-22 20:38:58 +00:00
};
2023-10-28 20:59:26 +00:00
public List<string> Planers => new List<string>
{
"FeedbackReasoningPlanner"
};
2023-09-22 20:38:58 +00:00
public RetrieveDataFromAgentRoutingHandler(IServiceProvider services, ILogger<RetrieveDataFromAgentRoutingHandler> logger, RoutingSettings settings)
: base(services, logger, settings)
{
}
public async Task<bool> Handle(IRoutingService routing, FunctionCallFromLlm inst, RoleDialogModel message)
2023-09-22 20:38:58 +00:00
{
// Retrieve information from specific agent
var db = _services.GetRequiredService<IBotSharpRepository>();
var record = db.GetAgents(inst.AgentName).FirstOrDefault();
var ret = await routing.InvokeAgent(record.Id, message);
2023-09-22 20:38:58 +00:00
/*_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)
{
2023-10-27 15:18:48 +00:00
MessageId = inst.MessageId,
2023-09-22 20:38:58 +00:00
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}";
2023-09-22 20:38:58 +00:00
// 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?");
2023-09-22 20:38:58 +00:00
return true;
2023-09-22 20:38:58 +00:00
}
}