Update next action agent's name

This commit is contained in:
hchen 2023-11-14 14:56:51 -06:00
parent 89b5cacbe9
commit e44423570d
3 changed files with 15 additions and 4 deletions

View file

@ -12,6 +12,7 @@ public class FunctionCallFromLlm : RoutingArgs
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public JsonDocument? Arguments { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public bool IsExecutionOnce { get; set; }
public override string ToString()

View file

@ -36,6 +36,12 @@ public class RouteToAgentRoutingHandler : RoutingHandlerBase, IRoutingHandler
var ret = await function.Execute(message);
var agentId = context.GetCurrentAgentId();
// Update next action agent's name
var agentService = _services.GetRequiredService<IAgentService>();
var agent = await agentService.LoadAgent(agentId);
inst.AgentName = agent.Name;
if (inst.IsExecutionOnce)
{
message.Content = inst.Question;

View file

@ -1,5 +1,6 @@
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.MLTasks.Settings;
using BotSharp.Abstraction.Routing.Models;
using BotSharp.Abstraction.Templating;
namespace BotSharp.Core.Routing;
@ -33,7 +34,7 @@ public partial class RoutingService
message.FunctionName = response.FunctionName;
message.FunctionArgs = response.FunctionArgs;
message.CurrentAgentId = agent.Id;
await InvokeFunction(agent, message, dialogs);
await InvokeFunction(message, dialogs);
}
else
{
@ -47,7 +48,7 @@ public partial class RoutingService
return true;
}
private async Task<bool> InvokeFunction(Agent agent, RoleDialogModel message, List<RoleDialogModel> dialogs)
private async Task<bool> InvokeFunction(RoleDialogModel message, List<RoleDialogModel> dialogs)
{
// execute function
// Save states
@ -61,9 +62,12 @@ public partial class RoutingService
// Pass execution result to LLM to get response
if (!message.StopCompletion)
{
var routing = _services.GetRequiredService<RoutingContext>();
var agentId = routing.GetCurrentAgentId();
// Find response template
var templateService = _services.GetRequiredService<IResponseTemplateService>();
var responseTemplate = await templateService.RenderFunctionResponse(agent.Id, message);
var responseTemplate = await templateService.RenderFunctionResponse(agentId, message);
if (!string.IsNullOrEmpty(responseTemplate))
{
dialogs.Add(RoleDialogModel.From(message,
@ -78,7 +82,7 @@ public partial class RoutingService
content: message.Content));
// Send to LLM
await InvokeAgent(agent.Id, dialogs);
await InvokeAgent(agentId, dialogs);
}
}
else