Skip to content

Update next action agent's name #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public async Task<bool> Handle(IRoutingService routing, FunctionCallFromLlm inst
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,7 +34,7 @@ public async Task<bool> InvokeAgent(string agentId, List<RoleDialogModel> dialog
message.FunctionName = response.FunctionName;
message.FunctionArgs = response.FunctionArgs;
message.CurrentAgentId = agent.Id;
await InvokeFunction(agent, message, dialogs);
await InvokeFunction(message, dialogs);
}
else
{
Expand All @@ -47,7 +48,7 @@ public async Task<bool> InvokeAgent(string agentId, List<RoleDialogModel> dialog
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
Expand All @@ -61,9 +62,12 @@ private async Task<bool> InvokeFunction(Agent agent, RoleDialogModel message, Li
// 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,
Expand All @@ -78,7 +82,7 @@ private async Task<bool> InvokeFunction(Agent agent, RoleDialogModel message, Li
content: message.Content));

// Send to LLM
await InvokeAgent(agent.Id, dialogs);
await InvokeAgent(agentId, dialogs);
}
}
else
Expand Down