refine routing mode
This commit is contained in:
parent
069170a01c
commit
2bf15f5078
|
|
@ -8,7 +8,7 @@ public enum AgentField
|
|||
IsPublic,
|
||||
Disabled,
|
||||
Type,
|
||||
Mode,
|
||||
RoutingMode,
|
||||
InheritAgentId,
|
||||
Profile,
|
||||
Label,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using BotSharp.Abstraction.Functions.Models;
|
||||
using BotSharp.Abstraction.Plugins.Models;
|
||||
using BotSharp.Abstraction.Routing.Enums;
|
||||
using BotSharp.Abstraction.Tasks.Models;
|
||||
|
||||
namespace BotSharp.Abstraction.Agents.Models;
|
||||
|
|
@ -17,7 +18,8 @@ public class Agent
|
|||
/// <summary>
|
||||
/// Routing Mode: lazy or eager
|
||||
/// </summary>
|
||||
public string Mode { get; set; } = AgentMode.Eager;
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? Mode { get; set; }
|
||||
|
||||
public DateTime CreatedDateTime { get; set; }
|
||||
public DateTime UpdatedDateTime { get; set; }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
namespace BotSharp.Abstraction.Agents.Enums;
|
||||
namespace BotSharp.Abstraction.Routing.Enums;
|
||||
|
||||
public class AgentMode
|
||||
public class RoutingMode
|
||||
{
|
||||
public const string Eager = "eager";
|
||||
public const string Lazy = "lazy";
|
||||
|
|
@ -2,6 +2,7 @@ using BotSharp.Abstraction.Hooks;
|
|||
using BotSharp.Abstraction.Infrastructures.Enums;
|
||||
using BotSharp.Abstraction.Messaging;
|
||||
using BotSharp.Abstraction.Messaging.Models.RichContent;
|
||||
using BotSharp.Abstraction.Routing.Enums;
|
||||
using BotSharp.Abstraction.Routing.Settings;
|
||||
|
||||
namespace BotSharp.Core.Conversations.Services;
|
||||
|
|
@ -83,10 +84,10 @@ public partial class ConversationService
|
|||
{
|
||||
// Check the routing mode
|
||||
var states = _services.GetRequiredService<IConversationStateService>();
|
||||
var routingMode = states.GetState(StateConst.ROUTING_MODE, AgentMode.Eager);
|
||||
var routingMode = states.GetState(StateConst.ROUTING_MODE, RoutingMode.Eager);
|
||||
routing.Context.Push(agent.Id, reason: "request started", updateLazyRouting: false);
|
||||
|
||||
if (routingMode == AgentMode.Lazy)
|
||||
if (routingMode == RoutingMode.Lazy)
|
||||
{
|
||||
message.CurrentAgentId = states.GetState(StateConst.LAZY_ROUTING_AGENT_ID, message.CurrentAgentId);
|
||||
routing.Context.Push(message.CurrentAgentId, reason: "lazy routing", updateLazyRouting: false);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ namespace BotSharp.Core.Repository
|
|||
case AgentField.Type:
|
||||
UpdateAgentType(agent.Id, agent.Type);
|
||||
break;
|
||||
case AgentField.Mode:
|
||||
UpdateAgentMode(agent.Id, agent.Mode);
|
||||
case AgentField.RoutingMode:
|
||||
UpdateAgentRoutingMode(agent.Id, agent.Mode);
|
||||
break;
|
||||
case AgentField.InheritAgentId:
|
||||
UpdateAgentInheritAgentId(agent.Id, agent.InheritAgentId);
|
||||
|
|
@ -145,7 +145,7 @@ namespace BotSharp.Core.Repository
|
|||
File.WriteAllText(agentFile, json);
|
||||
}
|
||||
|
||||
private void UpdateAgentMode(string agentId, string mode)
|
||||
private void UpdateAgentRoutingMode(string agentId, string? mode)
|
||||
{
|
||||
var (agent, agentFile) = GetAgentFromFile(agentId);
|
||||
if (agent == null) return;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using BotSharp.Abstraction.Infrastructures.Enums;
|
||||
using BotSharp.Abstraction.Routing.Enums;
|
||||
using BotSharp.Abstraction.Routing.Settings;
|
||||
|
||||
namespace BotSharp.Core.Routing;
|
||||
|
|
@ -290,8 +291,8 @@ public class RoutingContext : IRoutingContext
|
|||
|
||||
// Set next handling agent for lazy routing mode
|
||||
var states = _services.GetRequiredService<IConversationStateService>();
|
||||
var routingMode = states.GetState(StateConst.ROUTING_MODE, AgentMode.Eager);
|
||||
if (routingMode == AgentMode.Lazy)
|
||||
var routingMode = states.GetState(StateConst.ROUTING_MODE, RoutingMode.Eager);
|
||||
if (routingMode == RoutingMode.Lazy)
|
||||
{
|
||||
var agentId = GetCurrentAgentId();
|
||||
if (agentId != BuiltInAgentId.Fallback)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using BotSharp.Abstraction.Agents.Models;
|
||||
using BotSharp.Abstraction.Functions.Models;
|
||||
using BotSharp.Abstraction.Routing.Enums;
|
||||
|
||||
namespace BotSharp.OpenAPI.ViewModels.Agents;
|
||||
|
||||
|
|
@ -8,7 +9,11 @@ public class AgentCreationModel
|
|||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Type { get; set; } = AgentType.Task;
|
||||
public string Mode { get; set; } = AgentMode.Eager;
|
||||
|
||||
/// <summary>
|
||||
/// Agent routing mode
|
||||
/// </summary>
|
||||
public string? Mode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// LLM default system instructions
|
||||
|
|
|
|||
|
|
@ -9,7 +9,11 @@ public class AgentUpdateModel
|
|||
public string Name { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string Type { get; set; } = AgentType.Task;
|
||||
public string Mode { get; set; } = AgentMode.Eager;
|
||||
|
||||
/// <summary>
|
||||
/// Agent routing mode
|
||||
/// </summary>
|
||||
public string? Mode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Instruction
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ 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!;
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? Mode { get; set; }
|
||||
public string Instruction { get; set; }
|
||||
|
||||
[JsonPropertyName("channel_instructions")]
|
||||
|
|
|
|||
|
|
@ -5,7 +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? Mode { get; set; }
|
||||
public string? InheritAgentId { get; set; }
|
||||
public string? IconUrl { get; set; }
|
||||
public string Instruction { get; set; } = default!;
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ public partial class MongoRepository
|
|||
case AgentField.Type:
|
||||
UpdateAgentType(agent.Id, agent.Type);
|
||||
break;
|
||||
case AgentField.Mode:
|
||||
UpdateAgentMode(agent.Id, agent.Mode);
|
||||
case AgentField.RoutingMode:
|
||||
UpdateAgentRoutingMode(agent.Id, agent.Mode);
|
||||
break;
|
||||
case AgentField.InheritAgentId:
|
||||
UpdateAgentInheritAgentId(agent.Id, agent.InheritAgentId);
|
||||
|
|
@ -139,7 +139,7 @@ public partial class MongoRepository
|
|||
_dc.Agents.UpdateOne(filter, update);
|
||||
}
|
||||
|
||||
private void UpdateAgentMode(string agentId, string mode)
|
||||
private void UpdateAgentRoutingMode(string agentId, string? mode)
|
||||
{
|
||||
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
|
||||
var update = Builders<AgentDocument>.Update
|
||||
|
|
|
|||
Loading…
Reference in a new issue