Skip to content

Commit cf4ea9c

Browse files
committed
resolve conflict.
2 parents 4e7b1d0 + 6eabda4 commit cf4ea9c

40 files changed

Lines changed: 199 additions & 601 deletions

File tree

src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationHook.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,6 @@ public interface IConversationHook
6969

7070
Task OnResponseGenerated(RoleDialogModel message);
7171

72-
/// <summary>
73-
/// LLM detected user requested a new task different from previous topic.
74-
/// </summary>
75-
/// <param name="message"></param>
76-
/// <returns></returns>
77-
Task OnNewTaskDetected(RoleDialogModel message, string reason);
78-
79-
/// <summary>
80-
/// LLM detected the current task is completed.
81-
/// It's useful for the situation of multiple tasks in the same conversation.
82-
/// </summary>
83-
/// <param name="conversation"></param>
84-
/// <returns></returns>
85-
Task OnTaskCompleted(RoleDialogModel message);
86-
8772
/// <summary>
8873
/// LLM detected the whole conversation is going to be end.
8974
/// </summary>

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ public override string ToString()
3636
{
3737
var route = string.IsNullOrEmpty(AgentName) ? "" : $"<Route to {AgentName.ToUpper()} because {NextActionReason}>";
3838

39-
if (string.IsNullOrEmpty(Response))
40-
{
41-
return $"[{Function} {route} {JsonSerializer.Serialize(Arguments)}]: {Question}";
42-
}
43-
else
44-
{
45-
return $"[{Function} {route} {JsonSerializer.Serialize(Arguments)}]: {Question} => {Response}";
46-
}
39+
return $"[{Function} {route} {JsonSerializer.Serialize(Arguments)}]: {Question}";
4740
}
4841
}

src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingHandler.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,21 @@ public interface IRoutingService
2626
/// <returns></returns>
2727
RoutingRule[] GetRulesByAgentId(string id);
2828

29-
List<RoutingHandlerDef> GetHandlers(Agent router);
30-
3129
//void ResetRecursiveCounter();
3230
//int GetRecursiveCounter();
3331
//void SetRecursiveCounter(int counter);
3432

3533
Task<bool> InvokeAgent(string agentId, List<RoleDialogModel> dialogs);
3634
Task<bool> InvokeFunction(string name, RoleDialogModel messages);
37-
Task<RoleDialogModel> InstructLoop(RoleDialogModel message, List<RoleDialogModel> dialogs);
35+
Task<RoleDialogModel> InstructLoop(Agent agent, RoleDialogModel message, List<RoleDialogModel> dialogs);
3836

3937
/// <summary>
4038
/// Talk to a specific Agent directly, bypassing the Router
4139
/// </summary>
4240
/// <param name="agent"></param>
4341
/// <param name="message"></param>
4442
/// <returns></returns>
45-
Task<RoleDialogModel> InstructDirect(Agent agent, RoleDialogModel message);
43+
Task<RoleDialogModel> InstructDirect(Agent agent, RoleDialogModel message, List<RoleDialogModel> dialogs);
4644

4745
Task<string> GetConversationContent(List<RoleDialogModel> dialogs, int maxDialogCount = 100);
4846

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace BotSharp.Abstraction.Routing.Models;
2+
3+
public class ResponseUserArgs
4+
{
5+
[JsonPropertyName("content")]
6+
public string Content { get; set; } = string.Empty;
7+
}

src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@ public class RoutingArgs
1515
[JsonPropertyName("conversation_end")]
1616
public bool ConversationEnd { get; set; }
1717

18-
[JsonPropertyName("task_completed")]
19-
public bool TaskCompleted { get; set; }
20-
21-
[JsonPropertyName("is_new_task")]
22-
public bool IsNewTask { get; set; }
23-
24-
/// <summary>
25-
/// The content of replying to user
26-
/// </summary>
27-
[JsonPropertyName("response")]
28-
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
29-
public string Response { get; set; } = string.Empty;
30-
3118
/// <summary>
3219
/// Agent for next action based on user latest response
3320
/// </summary>
@@ -38,10 +25,12 @@ public class RoutingArgs
3825
/// <summary>
3926
/// Agent who can achieve user original goal
4027
/// </summary>
28+
[Obsolete("Will be replaced by dedicate Reasoner")]
4129
[JsonPropertyName("user_goal_agent")]
4230
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
4331
public string OriginalAgent { get; set; } = string.Empty;
4432

33+
[Obsolete("Will be replaced by dedicate Reasoner")]
4534
[JsonPropertyName("user_goal_description")]
4635
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
4736
public string UserGoal { get; set; } = string.Empty;
@@ -50,13 +39,6 @@ public override string ToString()
5039
{
5140
var route = string.IsNullOrEmpty(AgentName) ? "" : $"<Route to {AgentName.ToUpper()} because {NextActionReason}>";
5241

53-
if (string.IsNullOrEmpty(Response))
54-
{
55-
return $"[{Function} {route}]";
56-
}
57-
else
58-
{
59-
return $"[{Function} {route}] => {Response}";
60-
}
42+
return $"[{Function} {route}]";
6143
}
6244
}

src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,6 @@ public static void RegisterPlugins(IServiceCollection services, IConfiguration c
150150
var loader = new PluginLoader(services, config, pluginSettings);
151151
loader.Load(assembly =>
152152
{
153-
// Register routing handlers
154-
var handlers = assembly.GetTypes()
155-
.Where(x => x.IsClass)
156-
.Where(x => x.GetInterface(nameof(IRoutingHandler)) != null)
157-
.ToArray();
158-
159-
foreach (var handler in handlers)
160-
{
161-
services.AddScoped(typeof(IRoutingHandler), handler);
162-
}
163-
164153
// Register function callback
165154
var functions = assembly.GetTypes()
166155
.Where(x => x.IsClass

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,6 @@ public async Task<bool> SendMessage(string agentId,
3838
var routing = _services.GetRequiredService<IRoutingService>();
3939
routing.Context.SetMessageId(_conversationId, message.MessageId);
4040

41-
// Check the routing mode
42-
var states = _services.GetRequiredService<IConversationStateService>();
43-
var routingMode = states.GetState(StateConst.ROUTING_MODE, "hard");
44-
routing.Context.Push(agent.Id, reason: "request started", updateLazyRouting: false);
45-
46-
if (routingMode == "lazy")
47-
{
48-
message.CurrentAgentId = states.GetState(StateConst.LAZY_ROUTING_AGENT_ID, message.CurrentAgentId);
49-
routing.Context.Push(message.CurrentAgentId, reason: "lazy routing", updateLazyRouting: false);
50-
}
51-
5241
// Save payload in order to assign the payload before hook is invoked
5342
if (replyMessage != null && !string.IsNullOrEmpty(replyMessage.Payload))
5443
{
@@ -91,11 +80,22 @@ public async Task<bool> SendMessage(string agentId,
9180

9281
if (agent.Type == AgentType.Routing)
9382
{
94-
response = await routing.InstructLoop(message, dialogs);
83+
// Check the routing mode
84+
var states = _services.GetRequiredService<IConversationStateService>();
85+
var routingMode = states.GetState(StateConst.ROUTING_MODE, "eager");
86+
routing.Context.Push(agent.Id, reason: "request started", updateLazyRouting: false);
87+
88+
if (routingMode == "lazy")
89+
{
90+
message.CurrentAgentId = states.GetState(StateConst.LAZY_ROUTING_AGENT_ID, message.CurrentAgentId);
91+
routing.Context.Push(message.CurrentAgentId, reason: "lazy routing", updateLazyRouting: false);
92+
}
93+
94+
response = await routing.InstructLoop(agent, message, dialogs);
9595
}
9696
else
9797
{
98-
response = await routing.InstructDirect(agent, message);
98+
response = await routing.InstructDirect(agent, message, dialogs);
9999
}
100100

101101
routing.Context.ResetRecursiveCounter();
@@ -155,14 +155,6 @@ response.RichContent is RichContent<IRichMessage> template &&
155155
var conversation = _services.GetRequiredService<IConversationService>();
156156
var updatedConversation = await conversation.UpdateConversationTitle(_conversationId, response.Instruction.NextActionReason);
157157

158-
// Emit conversation task completed hook
159-
if (response.Instruction.TaskCompleted)
160-
{
161-
await HookEmitter.Emit<IConversationHook>(_services, async hook =>
162-
await hook.OnTaskCompleted(response)
163-
);
164-
}
165-
166158
// Emit conversation ending hook
167159
if (response.Instruction.ConversationEnd)
168160
{

src/Infrastructure/BotSharp.Core/Routing/Functions/ResponseToUserFn.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public ResponseToUserFn(IServiceProvider services, IRoutingContext context)
2020

2121
public Task<bool> Execute(RoleDialogModel message)
2222
{
23-
var args = JsonSerializer.Deserialize<RoutingArgs>(message.FunctionArgs);
24-
message.Content = args.Response;
23+
var args = JsonSerializer.Deserialize<ResponseUserArgs>(message.FunctionArgs);
24+
message.Content = args.Content;
2525
message.Handled = true;
2626
message.StopCompletion = true;
2727
return Task.FromResult(true);

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

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)