Skip to content
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 @@ -6,7 +6,5 @@ public interface IAgentRouting
{
string AgentId { get; }
Task<Agent> LoadRouter();
RoutingItem[] GetRoutingRecords();
RoutingItem GetRecordByAgentId(string id);
RoutingItem GetRecordByName(string name);
RoutingRule[] GetRulesByName(string name);
}
18 changes: 17 additions & 1 deletion src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.Json.Serialization;
using BotSharp.Abstraction.Routing.Models;

namespace BotSharp.Abstraction.Agents.Models;

Expand Down Expand Up @@ -48,6 +48,22 @@ public class Agent

public bool IsPublic { get; set; }

/// <summary>
/// Allow to be routed
/// </summary>
public bool AllowRouting { get; set; }

public bool Disabled { get; set; }

/// <summary>
/// Profile by channel
/// </summary>
public List<string> Profiles { get; set; }
= new List<string>();

public List<RoutingRule> RoutingRules { get; set; }
= new List<RoutingRule>();

public override string ToString()
=> $"{Name} {Id}";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using BotSharp.Abstraction.Agents.Enums;
using BotSharp.Abstraction.Routing.Models;
using BotSharp.Abstraction.Users.Models;

namespace BotSharp.Abstraction.Repositories;
Expand All @@ -10,8 +8,6 @@ public interface IBotSharpRepository
IQueryable<Agent> Agents { get; }
IQueryable<UserAgent> UserAgents { get; }
IQueryable<Conversation> Conversations { get; }
IQueryable<RoutingItem> RoutingItems { get; }
IQueryable<RoutingProfile> RoutingProfiles { get; }

int Transaction<TTableInterface>(Action action);
void Add<TTableInterface>(object entity);
Expand All @@ -37,11 +33,4 @@ public interface IBotSharpRepository
Conversation GetConversation(string conversationId);
List<Conversation> GetConversations(string userId);
#endregion

#region Routing
List<RoutingItem> CreateRoutingItems(List<RoutingItem> routingItems);
List<RoutingProfile> CreateRoutingProfiles(List<RoutingProfile> profiles);
void DeleteRoutingItems();
void DeleteRoutingProfiles();
#endregion
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using BotSharp.Abstraction.Routing.Models;

namespace BotSharp.Abstraction.Routing;

public interface IRoutingService
{
Task<List<RoutingItem>> CreateRoutingItems(List<RoutingItem> routingItems);
Task<List<RoutingProfile>> CreateRoutingProfiles(List<RoutingProfile> routingProfiles);
Task DeleteRoutingItems();
Task DeleteRoutingProfiles();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System.Text.Json.Serialization;

namespace BotSharp.Abstraction.Routing.Models;

public class RoutingItem
{
public string Id { get; set; }

[JsonPropertyName("agent_id")]
public string AgentId { get; set; } = string.Empty;

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

[JsonPropertyName("required")]
public List<string> RequiredFields { get; set; } = new List<string>();

[JsonPropertyName("redirect_to")]
public string? RedirectTo { get; set; }

[JsonPropertyName("disabled")]
public bool Disabled { get; set; }

public override string ToString()
{
return Name;
}
public string[] RequiredFields { get; set; } = new string[0];
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace BotSharp.Abstraction.Routing.Models;

public class RoutingRule
{
[JsonIgnore]
public string AgentId { get; set; }

[JsonIgnore]
public string AgentName { get; set; }

public string Field { get; set; }

public bool Required { get; set; }

public string? RedirectTo { get; set; }

public override string ToString()
{
return $"{AgentName} {Field}";
}
}
1 change: 1 addition & 0 deletions src/Infrastructure/BotSharp.Abstraction/Using.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
global using System.Linq;
global using System.Threading.Tasks;
global using System.ComponentModel.DataAnnotations;
global using System.Text.Json.Serialization;
global using BotSharp.Abstraction.Agents.Models;
global using BotSharp.Abstraction.Conversations.Models;
global using BotSharp.Abstraction.Agents.Enums;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using BotSharp.Core.Instructs;
using BotSharp.Abstraction.Instructs;
using BotSharp.Abstraction.Routing;
using BotSharp.Core.Routing.Services;

namespace BotSharp.Core;

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

services.AddScoped<IAgentService, AgentService>();
services.AddScoped<IRoutingService, RoutingService>();

var agentSettings = new AgentSettings();
config.Bind("Agent", agentSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ private async Task<bool> GetChatCompletionsAsyncRecursively(Agent agent,
var agentService = _services.GetRequiredService<IAgentService>();
agent = await agentService.LoadAgent(fn.CurrentAgentId);

wholeDialogs.Add(fn);
if (fn.FunctionName != "route_to_agent")
{
wholeDialogs.Add(fn);
}

await GetChatCompletionsAsyncRecursively(agent,
wholeDialogs,
Expand All @@ -99,13 +102,16 @@ await GetChatCompletionsAsyncRecursively(agent,

return;
}

// Add to dialog history
// The server had an error processing your request. Sorry about that!
// _storage.Append(conversationId, preAgentId, fn);

// After function is executed, pass the result to LLM to get a natural response
wholeDialogs.Add(fn);
if (fn.FunctionName != "route_to_agent")
{
wholeDialogs.Add(fn);
}

await GetChatCompletionsAsyncRecursively(agent,
wholeDialogs,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using BotSharp.Abstraction.Agents.Enums;
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.Routing.Settings;
using BotSharp.Core.Routing;
Expand Down
28 changes: 0 additions & 28 deletions src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.Repositories;
using BotSharp.Abstraction.Routing.Models;
using BotSharp.Abstraction.Users.Models;
using Microsoft.EntityFrameworkCore.Infrastructure;

Expand All @@ -16,10 +15,6 @@ public class BotSharpDbContext : Database, IBotSharpRepository

public IQueryable<Conversation> Conversations => throw new NotImplementedException();

public IQueryable<RoutingItem> RoutingItems => throw new NotImplementedException();

public IQueryable<RoutingProfile> RoutingProfiles => throw new NotImplementedException();


public int Transaction<TTableInterface>(Action action)
{
Expand Down Expand Up @@ -143,27 +138,4 @@ public void CreateUser(User user)
throw new NotImplementedException();
}
#endregion


#region Routing
public List<RoutingItem> CreateRoutingItems(List<RoutingItem> routingItems)
{
throw new NotImplementedException();
}

public List<RoutingProfile> CreateRoutingProfiles(List<RoutingProfile> profiles)
{
throw new NotImplementedException();
}

public void DeleteRoutingItems()
{
throw new NotImplementedException();
}

public void DeleteRoutingProfiles()
{
throw new NotImplementedException();
}
#endregion
}
68 changes: 0 additions & 68 deletions src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
using FunctionDef = BotSharp.Abstraction.Functions.Models.FunctionDef;
using BotSharp.Abstraction.Users.Models;
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.Routing.Models;
using MongoDB.Driver;
using Microsoft.Extensions.Logging;
using System.Xml.Linq;
using static Tensorflow.TensorShapeProto.Types;

namespace BotSharp.Core.Repository;

Expand Down Expand Up @@ -135,48 +131,6 @@ public IQueryable<Conversation> Conversations
}
}

private List<RoutingItem> _routingItems;
public IQueryable<RoutingItem> RoutingItems
{
get
{
if (!_routingItems.IsNullOrEmpty())
{
return _routingItems.AsQueryable();
}

_routingItems = new List<RoutingItem>();
var filePath = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, "route.json");
if (File.Exists(filePath))
{
_routingItems = JsonSerializer.Deserialize<List<RoutingItem>>(File.ReadAllText(filePath), _options);
}

return _routingItems.AsQueryable();
}
}

private List<RoutingProfile> _routingProfiles;
public IQueryable<RoutingProfile> RoutingProfiles
{
get
{
if (!_routingProfiles.IsNullOrEmpty())
{
return _routingProfiles.AsQueryable();
}

_routingProfiles = new List<RoutingProfile>();
var filePath = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, "routing-profile.json");
if (File.Exists(filePath))
{
_routingProfiles = JsonSerializer.Deserialize<List<RoutingProfile>>(File.ReadAllText(filePath), _options);
}

return _routingProfiles.AsQueryable();
}
}

public void Add<TTableInterface>(object entity)
{
if (entity is Conversation conversation)
Expand Down Expand Up @@ -680,28 +634,6 @@ public void CreateUser(User user)
}
#endregion

#region Routing
public void DeleteRoutingItems()
{
throw new NotImplementedException();
}

public void DeleteRoutingProfiles()
{
throw new NotImplementedException();
}

public List<RoutingItem> CreateRoutingItems(List<RoutingItem> routingItems)
{
throw new NotImplementedException();
}

public List<RoutingProfile> CreateRoutingProfiles(List<RoutingProfile> profiles)
{
throw new NotImplementedException();
}
#endregion

#region Private methods
private string GetAgentDataDir(string agentId)
{
Expand Down
Loading