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

207 lines
4.9 KiB
C#
Raw Normal View History

2023-09-27 20:49:44 +00:00
using BotSharp.Abstraction.Functions.Models;
2024-01-13 21:17:40 +00:00
using BotSharp.Abstraction.Plugins.Models;
2023-09-18 18:13:49 +00:00
using BotSharp.Abstraction.Routing.Models;
2023-09-12 04:27:04 +00:00
2023-06-11 15:22:48 +00:00
namespace BotSharp.Abstraction.Agents.Models;
public class Agent
{
public string Id { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
2023-09-18 23:14:24 +00:00
public string Description { get; set; } = string.Empty;
2023-06-11 15:22:48 +00:00
public DateTime CreatedDateTime { get; set; }
public DateTime UpdatedDateTime { get; set; }
2023-12-13 18:12:25 +00:00
/// <summary>
/// Default LLM settings
/// </summary>
2023-12-13 20:33:36 +00:00
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
2023-12-13 18:12:25 +00:00
public AgentLlmConfig? LlmConfig { get; set; }
2023-06-23 04:43:00 +00:00
/// <summary>
/// Instruction
/// </summary>
2023-09-12 04:27:04 +00:00
[JsonIgnore]
2023-12-19 13:16:43 +00:00
public string? Instruction { get; set; }
2023-06-23 04:43:00 +00:00
2023-09-12 22:08:58 +00:00
/// <summary>
/// Templates
/// </summary>
[JsonIgnore]
2023-10-09 00:05:17 +00:00
public List<AgentTemplate>? Templates { get; set; }
2023-09-12 22:08:58 +00:00
2023-06-23 04:43:00 +00:00
/// <summary>
/// Samples
/// </summary>
2023-09-12 04:27:04 +00:00
[JsonIgnore]
2023-10-19 17:24:00 +00:00
public List<string> Samples { get; set; }
2023-11-01 21:30:39 +00:00
= new List<string>();
2023-06-23 04:43:00 +00:00
2023-06-29 23:14:57 +00:00
/// <summary>
2023-07-26 21:05:30 +00:00
/// Functions
2023-06-29 23:14:57 +00:00
/// </summary>
2023-09-12 04:27:04 +00:00
[JsonIgnore]
2023-09-27 20:49:44 +00:00
public List<FunctionDef> Functions { get; set; } = new List<FunctionDef>();
2023-06-29 23:14:57 +00:00
2023-06-11 15:22:48 +00:00
/// <summary>
2023-09-02 05:10:46 +00:00
/// Responses
2023-06-11 15:22:48 +00:00
/// </summary>
2023-09-12 04:27:04 +00:00
[JsonIgnore]
2023-10-09 00:05:17 +00:00
public List<AgentResponse>? Responses { get; set; }
2023-08-17 04:04:23 +00:00
2023-08-28 05:28:14 +00:00
/// <summary>
2023-09-02 05:10:46 +00:00
/// Domain knowledges
2023-08-28 05:28:14 +00:00
/// </summary>
2023-09-12 04:27:04 +00:00
[JsonIgnore]
2023-12-19 13:16:43 +00:00
public string? Knowledges { get; set; }
2023-08-28 05:28:14 +00:00
2023-09-04 15:15:11 +00:00
public bool IsPublic { get; set; }
2024-01-13 21:17:40 +00:00
[JsonIgnore]
public bool IsRouter { get; set; }
[JsonIgnore]
public PluginDef Plugin { get; set; }
2024-01-13 22:06:21 +00:00
[JsonIgnore]
public bool Installed => Plugin.Enabled;
2023-09-18 18:13:49 +00:00
/// <summary>
/// Allow to be routed
/// </summary>
public bool AllowRouting { get; set; }
2024-01-13 01:10:12 +00:00
/// <summary>
/// Default is True, user will enable this by installing appropriate plugin.
/// </summary>
public bool Disabled { get; set; } = true;
2024-01-16 03:26:18 +00:00
public string? IconUrl { get; set; }
2023-09-18 18:13:49 +00:00
/// <summary>
/// Profile by channel
/// </summary>
public List<string> Profiles { get; set; }
= new List<string>();
public List<RoutingRule> RoutingRules { get; set; }
= new List<RoutingRule>();
2023-10-28 20:59:26 +00:00
/// <summary>
/// For rendering deferral
/// </summary>
[JsonIgnore]
public Dictionary<string, object> TemplateDict { get; set; }
2023-11-01 21:30:39 +00:00
= new Dictionary<string, object>();
2023-10-28 20:59:26 +00:00
2023-08-17 04:04:23 +00:00
public override string ToString()
=> $"{Name} {Id}";
2023-09-02 05:10:46 +00:00
2023-09-07 22:04:34 +00:00
public static Agent Clone(Agent agent)
{
return new Agent
{
Id = agent.Id,
Name = agent.Name,
Description = agent.Description,
Instruction = agent.Instruction,
Functions = agent.Functions,
Responses = agent.Responses,
Samples = agent.Samples,
Knowledges = agent.Knowledges,
IsPublic = agent.IsPublic,
2023-09-18 23:14:24 +00:00
Disabled = agent.Disabled,
AllowRouting = agent.AllowRouting,
Profiles = agent.Profiles,
RoutingRules = agent.RoutingRules,
2023-12-13 20:41:47 +00:00
LlmConfig = agent.LlmConfig,
2023-09-07 22:04:34 +00:00
CreatedDateTime = agent.CreatedDateTime,
UpdatedDateTime = agent.UpdatedDateTime,
};
}
2023-09-02 05:10:46 +00:00
public Agent SetInstruction(string instruction)
{
Instruction = instruction;
return this;
}
2023-09-12 22:08:58 +00:00
public Agent SetTemplates(List<AgentTemplate> templates)
{
2023-09-18 23:14:24 +00:00
Templates = templates ?? new List<AgentTemplate>();
2023-09-12 22:08:58 +00:00
return this;
}
2023-09-27 20:49:44 +00:00
public Agent SetFunctions(List<FunctionDef> functions)
2023-09-02 05:10:46 +00:00
{
2023-09-27 20:49:44 +00:00
Functions = functions ?? new List<FunctionDef>();
2023-09-02 05:10:46 +00:00
return this;
}
2023-10-19 17:24:00 +00:00
public Agent SetSamples(List<string> samples)
{
Samples = samples ?? new List<string>();
return this;
}
2023-09-09 21:44:25 +00:00
public Agent SetResponses(List<AgentResponse> responses)
2023-09-02 05:10:46 +00:00
{
2023-09-09 21:44:25 +00:00
Responses = responses ?? new List<AgentResponse>(); ;
2023-09-02 05:10:46 +00:00
return this;
}
2023-09-07 22:04:34 +00:00
public Agent SetId(string id)
{
Id = id;
return this;
}
public Agent SetName(string name)
{
Name = name;
return this;
}
public Agent SetDescription(string description)
{
Description = description;
return this;
}
public Agent SetIsPublic(bool isPublic)
{
IsPublic = isPublic;
return this;
}
2023-09-18 23:14:24 +00:00
public Agent SetDisabled(bool disabled)
{
Disabled = disabled;
return this;
}
public Agent SetAllowRouting(bool allowRouting)
{
AllowRouting = allowRouting;
return this;
}
public Agent SetProfiles(List<string> profiles)
{
Profiles = profiles ?? new List<string>();
return this;
}
public Agent SetRoutingRules(List<RoutingRule> rules)
{
RoutingRules = rules ?? new List<RoutingRule>();
return this;
}
2023-12-13 20:26:46 +00:00
public Agent SetLlmConfig(AgentLlmConfig? llmConfig)
{
LlmConfig = llmConfig;
return this;
}
2023-06-11 15:22:48 +00:00
}