Skip to content

Commit 8fc3d94

Browse files
authored
Merge pull request #209 from hchen2020/master
Update next action agent's name
2 parents 89b5cac + e444235 commit 8fc3d94

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class FunctionCallFromLlm : RoutingArgs
1212
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
1313
public JsonDocument? Arguments { get; set; }
1414

15+
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
1516
public bool IsExecutionOnce { get; set; }
1617

1718
public override string ToString()

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public async Task<bool> Handle(IRoutingService routing, FunctionCallFromLlm inst
3636
var ret = await function.Execute(message);
3737

3838
var agentId = context.GetCurrentAgentId();
39+
40+
// Update next action agent's name
41+
var agentService = _services.GetRequiredService<IAgentService>();
42+
var agent = await agentService.LoadAgent(agentId);
43+
inst.AgentName = agent.Name;
44+
3945
if (inst.IsExecutionOnce)
4046
{
4147
message.Content = inst.Question;

src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BotSharp.Abstraction.Agents.Models;
22
using BotSharp.Abstraction.MLTasks.Settings;
3+
using BotSharp.Abstraction.Routing.Models;
34
using BotSharp.Abstraction.Templating;
45

56
namespace BotSharp.Core.Routing;
@@ -33,7 +34,7 @@ public async Task<bool> InvokeAgent(string agentId, List<RoleDialogModel> dialog
3334
message.FunctionName = response.FunctionName;
3435
message.FunctionArgs = response.FunctionArgs;
3536
message.CurrentAgentId = agent.Id;
36-
await InvokeFunction(agent, message, dialogs);
37+
await InvokeFunction(message, dialogs);
3738
}
3839
else
3940
{
@@ -47,7 +48,7 @@ public async Task<bool> InvokeAgent(string agentId, List<RoleDialogModel> dialog
4748
return true;
4849
}
4950

50-
private async Task<bool> InvokeFunction(Agent agent, RoleDialogModel message, List<RoleDialogModel> dialogs)
51+
private async Task<bool> InvokeFunction(RoleDialogModel message, List<RoleDialogModel> dialogs)
5152
{
5253
// execute function
5354
// Save states
@@ -61,9 +62,12 @@ private async Task<bool> InvokeFunction(Agent agent, RoleDialogModel message, Li
6162
// Pass execution result to LLM to get response
6263
if (!message.StopCompletion)
6364
{
65+
var routing = _services.GetRequiredService<RoutingContext>();
66+
var agentId = routing.GetCurrentAgentId();
67+
6468
// Find response template
6569
var templateService = _services.GetRequiredService<IResponseTemplateService>();
66-
var responseTemplate = await templateService.RenderFunctionResponse(agent.Id, message);
70+
var responseTemplate = await templateService.RenderFunctionResponse(agentId, message);
6771
if (!string.IsNullOrEmpty(responseTemplate))
6872
{
6973
dialogs.Add(RoleDialogModel.From(message,
@@ -78,7 +82,7 @@ private async Task<bool> InvokeFunction(Agent agent, RoleDialogModel message, Li
7882
content: message.Content));
7983

8084
// Send to LLM
81-
await InvokeAgent(agent.Id, dialogs);
85+
await InvokeAgent(agentId, dialogs);
8286
}
8387
}
8488
else

0 commit comments

Comments
 (0)