Add agent routing mode
This commit is contained in:
parent
dedf30a870
commit
948b0bb337
|
|
@ -8,6 +8,7 @@ public enum AgentField
|
|||
IsPublic,
|
||||
Disabled,
|
||||
Type,
|
||||
Mode,
|
||||
InheritAgentId,
|
||||
Profile,
|
||||
Label,
|
||||
|
|
|
|||
|
|
@ -13,6 +13,12 @@ public class Agent
|
|||
/// Agent Type
|
||||
/// </summary>
|
||||
public string Type { get; set; } = AgentType.Task;
|
||||
|
||||
/// <summary>
|
||||
/// Routing Mode: lazy or eager
|
||||
/// </summary>
|
||||
public string Mode { get; set; } = "eager";
|
||||
|
||||
public DateTime CreatedDateTime { get; set; }
|
||||
public DateTime UpdatedDateTime { get; set; }
|
||||
|
||||
|
|
@ -156,6 +162,7 @@ public class Agent
|
|||
Name = agent.Name,
|
||||
Description = agent.Description,
|
||||
Type = agent.Type,
|
||||
Mode = agent.Mode,
|
||||
Instruction = agent.Instruction,
|
||||
ChannelInstructions = agent.ChannelInstructions,
|
||||
Functions = agent.Functions,
|
||||
|
|
@ -275,6 +282,17 @@ public class Agent
|
|||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set agent mode: lazy or eager
|
||||
/// </summary>
|
||||
/// <param name="mode"></param>
|
||||
/// <returns></returns>
|
||||
public Agent SetAgentMode(string mode)
|
||||
{
|
||||
Mode = mode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Agent SetProfiles(List<string> profiles)
|
||||
{
|
||||
Profiles = profiles ?? [];
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ public partial class AgentService
|
|||
record.MergeUtility = agent.MergeUtility;
|
||||
record.MaxMessageCount = agent.MaxMessageCount;
|
||||
record.Type = agent.Type;
|
||||
record.Mode = agent.Mode;
|
||||
record.Profiles = agent.Profiles ?? [];
|
||||
record.Labels = agent.Labels ?? [];
|
||||
record.RoutingRules = agent.RoutingRules ?? [];
|
||||
|
|
@ -97,6 +98,7 @@ public partial class AgentService
|
|||
.SetDisabled(foundAgent.Disabled)
|
||||
.SetMergeUtility(foundAgent.MergeUtility)
|
||||
.SetAgentType(foundAgent.Type)
|
||||
.SetAgentMode(foundAgent.Mode)
|
||||
.SetProfiles(foundAgent.Profiles)
|
||||
.SetLabels(foundAgent.Labels)
|
||||
.SetRoutingRules(foundAgent.RoutingRules)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ namespace BotSharp.Core.Repository
|
|||
case AgentField.Type:
|
||||
UpdateAgentType(agent.Id, agent.Type);
|
||||
break;
|
||||
case AgentField.Mode:
|
||||
UpdateAgentMode(agent.Id, agent.Mode);
|
||||
break;
|
||||
case AgentField.InheritAgentId:
|
||||
UpdateAgentInheritAgentId(agent.Id, agent.InheritAgentId);
|
||||
break;
|
||||
|
|
@ -142,6 +145,17 @@ namespace BotSharp.Core.Repository
|
|||
File.WriteAllText(agentFile, json);
|
||||
}
|
||||
|
||||
private void UpdateAgentMode(string agentId, string mode)
|
||||
{
|
||||
var (agent, agentFile) = GetAgentFromFile(agentId);
|
||||
if (agent == null) return;
|
||||
|
||||
agent.Mode = mode;
|
||||
agent.UpdatedDateTime = DateTime.UtcNow;
|
||||
var json = JsonSerializer.Serialize(agent, _options);
|
||||
File.WriteAllText(agentFile, json);
|
||||
}
|
||||
|
||||
private void UpdateAgentInheritAgentId(string agentId, string? inheritAgentId)
|
||||
{
|
||||
var (agent, agentFile) = GetAgentFromFile(agentId);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public class AgentViewModel
|
|||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Type { get; set; } = AgentType.Task;
|
||||
public string Mode { get; set; } = null!;
|
||||
public string Instruction { get; set; }
|
||||
|
||||
[JsonPropertyName("channel_instructions")]
|
||||
|
|
@ -82,6 +83,7 @@ public class AgentViewModel
|
|||
Name = agent.Name,
|
||||
Description = agent.Description,
|
||||
Type = agent.Type,
|
||||
Mode = agent.Mode,
|
||||
Instruction = agent.Instruction,
|
||||
ChannelInstructions = agent.ChannelInstructions ?? [],
|
||||
Templates = agent.Templates ?? [],
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ public class AgentDocument : MongoBase
|
|||
public string Name { get; set; } = default!;
|
||||
public string Description { get; set; } = default!;
|
||||
public string Type { get; set; } = default!;
|
||||
public string Mode { get; set; } = default!;
|
||||
public string? InheritAgentId { get; set; }
|
||||
public string? IconUrl { get; set; }
|
||||
public string Instruction { get; set; } = default!;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ public partial class MongoRepository
|
|||
case AgentField.Type:
|
||||
UpdateAgentType(agent.Id, agent.Type);
|
||||
break;
|
||||
case AgentField.Mode:
|
||||
UpdateAgentMode(agent.Id, agent.Mode);
|
||||
break;
|
||||
case AgentField.InheritAgentId:
|
||||
UpdateAgentInheritAgentId(agent.Id, agent.InheritAgentId);
|
||||
break;
|
||||
|
|
@ -136,6 +139,16 @@ public partial class MongoRepository
|
|||
_dc.Agents.UpdateOne(filter, update);
|
||||
}
|
||||
|
||||
private void UpdateAgentMode(string agentId, string mode)
|
||||
{
|
||||
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
|
||||
var update = Builders<AgentDocument>.Update
|
||||
.Set(x => x.Mode, mode)
|
||||
.Set(x => x.UpdatedTime, DateTime.UtcNow);
|
||||
|
||||
_dc.Agents.UpdateOne(filter, update);
|
||||
}
|
||||
|
||||
private void UpdateAgentInheritAgentId(string agentId, string? inheritAgentId)
|
||||
{
|
||||
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
|
||||
|
|
@ -335,6 +348,7 @@ public partial class MongoRepository
|
|||
.Set(x => x.Disabled, agent.Disabled)
|
||||
.Set(x => x.MergeUtility, agent.MergeUtility)
|
||||
.Set(x => x.Type, agent.Type)
|
||||
.Set(x => x.Mode, agent.Mode)
|
||||
.Set(x => x.MaxMessageCount, agent.MaxMessageCount)
|
||||
.Set(x => x.Profiles, agent.Profiles)
|
||||
.Set(x => x.Labels, agent.Labels)
|
||||
|
|
@ -514,6 +528,7 @@ public partial class MongoRepository
|
|||
Samples = x.Samples ?? [],
|
||||
IsPublic = x.IsPublic,
|
||||
Type = x.Type,
|
||||
Mode = x.Mode,
|
||||
InheritAgentId = x.InheritAgentId,
|
||||
Disabled = x.Disabled,
|
||||
MergeUtility = x.MergeUtility,
|
||||
|
|
@ -611,6 +626,7 @@ public partial class MongoRepository
|
|||
Disabled = agentDoc.Disabled,
|
||||
MergeUtility = agentDoc.MergeUtility,
|
||||
Type = agentDoc.Type,
|
||||
Mode = agentDoc.Mode,
|
||||
InheritAgentId = agentDoc.InheritAgentId,
|
||||
Profiles = agentDoc.Profiles ?? [],
|
||||
Labels = agentDoc.Labels ?? [],
|
||||
|
|
|
|||
|
|
@ -169,10 +169,9 @@ public class TwilioInboundController : TwilioController
|
|||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
// Get agent from storage
|
||||
var agent = await agentService.GetAgent(request.AgentId);
|
||||
// Enable lazy routing mode to optimize realtime experience
|
||||
if (agent.Profiles.Contains("realtime") && agent.Type == AgentType.Routing)
|
||||
if (agent.Type == AgentType.Routing)
|
||||
{
|
||||
states.Add(new(StateConst.ROUTING_MODE, "lazy"));
|
||||
states.Add(new(StateConst.ROUTING_MODE, agent.Mode));
|
||||
}
|
||||
convService.SetConversationId(conversation.Id, states);
|
||||
convService.SaveStates();
|
||||
|
|
|
|||
Loading…
Reference in a new issue