Skip to content

Commit 15e8bb0

Browse files
authored
Merge pull request #146 from hchen2020/master
Eliminate route file configuration.
2 parents ba99aab + a13ef30 commit 15e8bb0

27 files changed

+121
-536
lines changed

src/Infrastructure/BotSharp.Abstraction/Agents/IAgentRouting.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ public interface IAgentRouting
66
{
77
string AgentId { get; }
88
Task<Agent> LoadRouter();
9-
RoutingItem[] GetRoutingRecords();
10-
RoutingItem GetRecordByAgentId(string id);
11-
RoutingItem GetRecordByName(string name);
9+
RoutingRule[] GetRulesByName(string name);
1210
}

src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Text.Json.Serialization;
1+
using BotSharp.Abstraction.Routing.Models;
22

33
namespace BotSharp.Abstraction.Agents.Models;
44

@@ -48,6 +48,22 @@ public class Agent
4848

4949
public bool IsPublic { get; set; }
5050

51+
/// <summary>
52+
/// Allow to be routed
53+
/// </summary>
54+
public bool AllowRouting { get; set; }
55+
56+
public bool Disabled { get; set; }
57+
58+
/// <summary>
59+
/// Profile by channel
60+
/// </summary>
61+
public List<string> Profiles { get; set; }
62+
= new List<string>();
63+
64+
public List<RoutingRule> RoutingRules { get; set; }
65+
= new List<RoutingRule>();
66+
5167
public override string ToString()
5268
=> $"{Name} {Id}";
5369

src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using BotSharp.Abstraction.Agents.Enums;
2-
using BotSharp.Abstraction.Routing.Models;
31
using BotSharp.Abstraction.Users.Models;
42

53
namespace BotSharp.Abstraction.Repositories;
@@ -10,8 +8,6 @@ public interface IBotSharpRepository
108
IQueryable<Agent> Agents { get; }
119
IQueryable<UserAgent> UserAgents { get; }
1210
IQueryable<Conversation> Conversations { get; }
13-
IQueryable<RoutingItem> RoutingItems { get; }
14-
IQueryable<RoutingProfile> RoutingProfiles { get; }
1511

1612
int Transaction<TTableInterface>(Action action);
1713
void Add<TTableInterface>(object entity);
@@ -37,11 +33,4 @@ public interface IBotSharpRepository
3733
Conversation GetConversation(string conversationId);
3834
List<Conversation> GetConversations(string userId);
3935
#endregion
40-
41-
#region Routing
42-
List<RoutingItem> CreateRoutingItems(List<RoutingItem> routingItems);
43-
List<RoutingProfile> CreateRoutingProfiles(List<RoutingProfile> profiles);
44-
void DeleteRoutingItems();
45-
void DeleteRoutingProfiles();
46-
#endregion
4736
}
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
using BotSharp.Abstraction.Routing.Models;
2-
31
namespace BotSharp.Abstraction.Routing;
42

53
public interface IRoutingService
64
{
7-
Task<List<RoutingItem>> CreateRoutingItems(List<RoutingItem> routingItems);
8-
Task<List<RoutingProfile>> CreateRoutingProfiles(List<RoutingProfile> routingProfiles);
95
Task DeleteRoutingItems();
106
Task DeleteRoutingProfiles();
117
}
Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
using System.Text.Json.Serialization;
2-
31
namespace BotSharp.Abstraction.Routing.Models;
42

53
public class RoutingItem
64
{
7-
public string Id { get; set; }
8-
95
[JsonPropertyName("agent_id")]
106
public string AgentId { get; set; } = string.Empty;
117

@@ -16,16 +12,5 @@ public class RoutingItem
1612
public string Description { get; set; } = string.Empty;
1713

1814
[JsonPropertyName("required")]
19-
public List<string> RequiredFields { get; set; } = new List<string>();
20-
21-
[JsonPropertyName("redirect_to")]
22-
public string? RedirectTo { get; set; }
23-
24-
[JsonPropertyName("disabled")]
25-
public bool Disabled { get; set; }
26-
27-
public override string ToString()
28-
{
29-
return Name;
30-
}
15+
public string[] RequiredFields { get; set; } = new string[0];
3116
}

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

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace BotSharp.Abstraction.Routing.Models;
2+
3+
public class RoutingRule
4+
{
5+
[JsonIgnore]
6+
public string AgentId { get; set; }
7+
8+
[JsonIgnore]
9+
public string AgentName { get; set; }
10+
11+
public string Field { get; set; }
12+
13+
public bool Required { get; set; }
14+
15+
public string? RedirectTo { get; set; }
16+
17+
public override string ToString()
18+
{
19+
return $"{AgentName} {Field}";
20+
}
21+
}

src/Infrastructure/BotSharp.Abstraction/Using.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
global using System.Linq;
55
global using System.Threading.Tasks;
66
global using System.ComponentModel.DataAnnotations;
7+
global using System.Text.Json.Serialization;
78
global using BotSharp.Abstraction.Agents.Models;
89
global using BotSharp.Abstraction.Conversations.Models;
910
global using BotSharp.Abstraction.Agents.Enums;

src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using BotSharp.Core.Instructs;
1010
using BotSharp.Abstraction.Instructs;
1111
using BotSharp.Abstraction.Routing;
12-
using BotSharp.Core.Routing.Services;
1312

1413
namespace BotSharp.Core;
1514

@@ -20,7 +19,6 @@ public static IServiceCollection AddBotSharp(this IServiceCollection services, I
2019
services.AddScoped<IUserService, UserService>();
2120

2221
services.AddScoped<IAgentService, AgentService>();
23-
services.AddScoped<IRoutingService, RoutingService>();
2422

2523
var agentSettings = new AgentSettings();
2624
config.Bind("Agent", agentSettings);

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ private async Task<bool> GetChatCompletionsAsyncRecursively(Agent agent,
7777
var agentService = _services.GetRequiredService<IAgentService>();
7878
agent = await agentService.LoadAgent(fn.CurrentAgentId);
7979

80-
wholeDialogs.Add(fn);
80+
if (fn.FunctionName != "route_to_agent")
81+
{
82+
wholeDialogs.Add(fn);
83+
}
8184

8285
await GetChatCompletionsAsyncRecursively(agent,
8386
wholeDialogs,
@@ -99,13 +102,16 @@ await GetChatCompletionsAsyncRecursively(agent,
99102

100103
return;
101104
}
102-
105+
103106
// Add to dialog history
104107
// The server had an error processing your request. Sorry about that!
105108
// _storage.Append(conversationId, preAgentId, fn);
106109

107110
// After function is executed, pass the result to LLM to get a natural response
108-
wholeDialogs.Add(fn);
111+
if (fn.FunctionName != "route_to_agent")
112+
{
113+
wholeDialogs.Add(fn);
114+
}
109115

110116
await GetChatCompletionsAsyncRecursively(agent,
111117
wholeDialogs,

0 commit comments

Comments
 (0)