refine agent utility
This commit is contained in:
parent
99dd39d9ba
commit
b7c619750e
|
|
@ -57,9 +57,9 @@ public abstract class AgentHookBase : IAgentHook
|
|||
{
|
||||
}
|
||||
|
||||
public virtual void OnLoadAgentUtility(Agent agent, IEnumerable<AgentUtility> utilities)
|
||||
public virtual void OnAgentUtilityloaded(Agent agent)
|
||||
{
|
||||
if (agent.Type == AgentType.Routing || utilities.IsNullOrEmpty()) return;
|
||||
if (agent.Type == AgentType.Routing) return;
|
||||
|
||||
var conv = _services.GetRequiredService<IConversationService>();
|
||||
var isConvMode = conv.IsConversationMode();
|
||||
|
|
@ -68,16 +68,13 @@ public abstract class AgentHookBase : IAgentHook
|
|||
var render = _services.GetRequiredService<ITemplateRender>();
|
||||
|
||||
agent.Functions ??= [];
|
||||
var agentUtilities = agent.Utilities ?? [];
|
||||
agent.Utilities ??= [];
|
||||
|
||||
foreach (var utillity in utilities)
|
||||
foreach (var utillity in agent.Utilities)
|
||||
{
|
||||
if (utillity.Name.IsNullOrEmpty() || utillity.Content == null) continue;
|
||||
if (utillity == null || string.IsNullOrWhiteSpace(utillity.Name)) continue;
|
||||
|
||||
var isEnabled = agentUtilities.Contains(utillity.Name);
|
||||
if (!isEnabled) continue;
|
||||
|
||||
var (fns, prompts) = GetUtilityContent(utillity.Content);
|
||||
var (fns, prompts) = GetUtilityContent(utillity);
|
||||
|
||||
if (!fns.IsNullOrEmpty())
|
||||
{
|
||||
|
|
@ -94,7 +91,7 @@ public abstract class AgentHookBase : IAgentHook
|
|||
}
|
||||
}
|
||||
|
||||
private (IEnumerable<FunctionDef>, IEnumerable<string>) GetUtilityContent(UtilityContent content)
|
||||
private (IEnumerable<FunctionDef>, IEnumerable<string>) GetUtilityContent(AgentUtility utility)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var render = _services.GetRequiredService<ITemplateRender>();
|
||||
|
|
@ -108,15 +105,15 @@ public abstract class AgentHookBase : IAgentHook
|
|||
return (fns, prompts);
|
||||
}
|
||||
|
||||
if (!content.Functions.IsNullOrEmpty())
|
||||
if (!utility.Functions.IsNullOrEmpty())
|
||||
{
|
||||
var functionNames = content.Functions?.Select(x => x.Name)?.ToList() ?? [];
|
||||
var functionNames = utility.Functions?.Select(x => x.Name)?.ToList() ?? [];
|
||||
fns = agent?.Functions?.Where(x => functionNames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))?.ToList() ?? [];
|
||||
}
|
||||
|
||||
if (!content.Templates.IsNullOrEmpty())
|
||||
if (!utility.Templates.IsNullOrEmpty())
|
||||
{
|
||||
foreach (var template in content.Templates)
|
||||
foreach (var template in utility.Templates)
|
||||
{
|
||||
var prompt = agent?.Templates?.FirstOrDefault(x => x.Name.IsEqualTo(template.Name))?.Content ?? string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(prompt)) continue;
|
||||
|
|
|
|||
|
|
@ -25,12 +25,12 @@ public interface IAgentHook
|
|||
|
||||
bool OnSamplesLoaded(List<string> samples);
|
||||
|
||||
void OnAgentUtilityloaded(Agent agent);
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when agent is loaded completely.
|
||||
/// </summary>
|
||||
/// <param name="agent"></param>
|
||||
/// <returns></returns>
|
||||
void OnAgentLoaded(Agent agent);
|
||||
|
||||
void OnLoadAgentUtility(Agent agent, IEnumerable<AgentUtility> utilities);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ public class Agent
|
|||
/// <summary>
|
||||
/// Agent utilities
|
||||
/// </summary>
|
||||
public List<string> Utilities { get; set; } = new();
|
||||
public List<AgentUtility> Utilities { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Inherit from agent
|
||||
|
|
@ -173,9 +173,9 @@ public class Agent
|
|||
return this;
|
||||
}
|
||||
|
||||
public Agent SetUtilities(List<string> utilities)
|
||||
public Agent SetUtilities(List<AgentUtility> utilities)
|
||||
{
|
||||
Utilities = utilities ?? new List<string>();
|
||||
Utilities = utilities ?? new List<AgentUtility>();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,33 +2,32 @@ namespace BotSharp.Abstraction.Agents.Models;
|
|||
|
||||
public class AgentUtility
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
public UtilityContent Content { get; set; }
|
||||
|
||||
[JsonPropertyName("functions")]
|
||||
public IEnumerable<UtilityFunction> Functions { get; set; } = [];
|
||||
|
||||
[JsonPropertyName("templates")]
|
||||
public IEnumerable<UtilityTemplate> Templates { get; set; } = [];
|
||||
|
||||
public AgentUtility()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public AgentUtility(string utilityName, UtilityContent content)
|
||||
public AgentUtility(
|
||||
string name,
|
||||
IEnumerable<UtilityFunction>? functions = null,
|
||||
IEnumerable<UtilityTemplate>? templates = null)
|
||||
{
|
||||
Name = utilityName;
|
||||
Content = content;
|
||||
Name = name;
|
||||
Functions = functions ?? [];
|
||||
Templates = templates ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class UtilityContent
|
||||
{
|
||||
public IEnumerable<UtilityFunction> Functions { get; set; } = [];
|
||||
public IEnumerable<UtilityTemplate> Templates { get; set; } = [];
|
||||
|
||||
public UtilityContent()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class UtilityFunction : UtilityBase
|
||||
{
|
||||
public UtilityFunction()
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ public interface IRoutingContext
|
|||
string FirstGoalAgentId();
|
||||
bool ContainsAgentId(string agentId);
|
||||
string OriginAgentId { get; }
|
||||
string EntryAgentId { get; }
|
||||
string ConversationId { get; }
|
||||
string MessageId { get; }
|
||||
void SetMessageId(string conversationId, string messageId);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
namespace BotSharp.Abstraction.Users.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// User actions on agent level
|
||||
/// </summary>
|
||||
public static class UserAction
|
||||
{
|
||||
public const string Edit = "edit";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
namespace BotSharp.Abstraction.Users.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// User permission
|
||||
/// </summary>
|
||||
public static class UserPermission
|
||||
{
|
||||
public const string CreateAgent = "create-agent";
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ public partial class AgentService
|
|||
hook.OnSamplesLoaded(agent.Samples);
|
||||
}
|
||||
|
||||
hook.OnAgentUtilityloaded(agent);
|
||||
hook.OnAgentLoaded(agent);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public partial class AgentService
|
|||
record.Templates = agent.Templates ?? new List<AgentTemplate>();
|
||||
record.Responses = agent.Responses ?? new List<AgentResponse>();
|
||||
record.Samples = agent.Samples ?? new List<string>();
|
||||
record.Utilities = agent.Utilities ?? new List<string>();
|
||||
record.Utilities = agent.Utilities ?? new List<AgentUtility>();
|
||||
if (agent.LlmConfig != null && !agent.LlmConfig.IsInherit)
|
||||
{
|
||||
record.LlmConfig = agent.LlmConfig;
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ namespace BotSharp.Core.Repository
|
|||
File.WriteAllText(agentFile, json);
|
||||
}
|
||||
|
||||
private void UpdateAgentUtilities(string agentId, List<string> utilities)
|
||||
private void UpdateAgentUtilities(string agentId, List<AgentUtility> utilities)
|
||||
{
|
||||
if (utilities == null) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ public class RoutingContext : IRoutingContext
|
|||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
_routerAgentIds = agentService.GetAgents(new AgentFilter
|
||||
{
|
||||
Type = AgentType.Routing
|
||||
Type = AgentType.Routing,
|
||||
Pager = new Pagination { Size = 20 }
|
||||
}).Result.Items.Select(x => x.Id).ToArray();
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +50,17 @@ public class RoutingContext : IRoutingContext
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Entry agent
|
||||
/// </summary>
|
||||
public string EntryAgentId
|
||||
{
|
||||
get
|
||||
{
|
||||
return _stack.LastOrDefault() ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEmpty => !_stack.Any();
|
||||
|
||||
public string GetCurrentAgentId()
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class AgentCreationModel
|
|||
/// Combine different Agents together to form a Profile.
|
||||
/// </summary>
|
||||
public List<string> Profiles { get; set; } = new();
|
||||
public List<string> Utilities { get; set; } = new();
|
||||
public List<AgentUtility> Utilities { get; set; } = new();
|
||||
public List<RoutingRuleUpdateModel> RoutingRules { get; set; } = new();
|
||||
public AgentLlmConfig? LlmConfig { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public class AgentUpdateModel
|
|||
/// <summary>
|
||||
/// Utilities
|
||||
/// </summary>
|
||||
public List<string>? Utilities { get; set; }
|
||||
public List<AgentUtility>? Utilities { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Functions
|
||||
|
|
@ -81,7 +81,7 @@ public class AgentUpdateModel
|
|||
Templates = Templates ?? new List<AgentTemplate>(),
|
||||
Functions = Functions ?? new List<FunctionDef>(),
|
||||
Responses = Responses ?? new List<AgentResponse>(),
|
||||
Utilities = Utilities ?? new List<string>(),
|
||||
Utilities = Utilities ?? new List<AgentUtility>(),
|
||||
LlmConfig = LlmConfig
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class AgentViewModel
|
|||
public List<FunctionDef> Functions { get; set; }
|
||||
public List<AgentResponse> Responses { get; set; }
|
||||
public List<string> Samples { get; set; }
|
||||
public List<string> Utilities { get; set; }
|
||||
public List<AgentUtility> Utilities { get; set; }
|
||||
|
||||
[JsonPropertyName("is_public")]
|
||||
public bool IsPublic { get; set; }
|
||||
|
|
|
|||
|
|
@ -18,14 +18,10 @@ public class AudioHandlerHook : AgentHookBase, IAgentHook
|
|||
var utilityLoad = new AgentUtility
|
||||
{
|
||||
Name = UtilityName.AudioHandler,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = [new(HANDLER_AUDIO)],
|
||||
Templates = [new($"{HANDLER_AUDIO}.fn")]
|
||||
}
|
||||
Functions = [new(HANDLER_AUDIO)],
|
||||
Templates = [new($"{HANDLER_AUDIO}.fn")]
|
||||
};
|
||||
|
||||
base.OnLoadAgentUtility(agent, [utilityLoad]);
|
||||
base.OnAgentLoaded(agent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,14 +21,10 @@ public class EmailHandlerHook : AgentHookBase
|
|||
var utilityLoad = new AgentUtility
|
||||
{
|
||||
Name = UtilityName.EmailHandler,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = [new(EMAIL_READER_FN), new(EMAIL_SENDER_FN)],
|
||||
Templates = [new($"{EMAIL_READER_FN}.fn"), new($"{EMAIL_SENDER_FN}.fn")]
|
||||
}
|
||||
Functions = [new(EMAIL_READER_FN), new(EMAIL_SENDER_FN)],
|
||||
Templates = [new($"{EMAIL_READER_FN}.fn"), new($"{EMAIL_SENDER_FN}.fn")]
|
||||
};
|
||||
|
||||
base.OnLoadAgentUtility(agent, [utilityLoad]);
|
||||
base.OnAgentLoaded(agent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,14 +15,10 @@ public class ExcelHandlerHook : AgentHookBase, IAgentHook
|
|||
var utilityLoad = new AgentUtility
|
||||
{
|
||||
Name = UtilityName.ExcelHandler,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = [new(HANDLER_EXCEL)],
|
||||
Templates = [new($"{HANDLER_EXCEL}.fn")]
|
||||
}
|
||||
Functions = [new(HANDLER_EXCEL)],
|
||||
Templates = [new($"{HANDLER_EXCEL}.fn")]
|
||||
};
|
||||
|
||||
base.OnLoadAgentUtility(agent, [utilityLoad]);
|
||||
base.OnAgentLoaded(agent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,42 +20,29 @@ public class FileHandlerHook : AgentHookBase, IAgentHook
|
|||
new AgentUtility
|
||||
{
|
||||
Name = UtilityName.ImageGenerator,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = [new(GENERATE_IMAGE_FN)],
|
||||
Templates = [new($"{GENERATE_IMAGE_FN}.fn")]
|
||||
}
|
||||
Functions = [new(GENERATE_IMAGE_FN)],
|
||||
Templates = [new($"{GENERATE_IMAGE_FN}.fn")]
|
||||
},
|
||||
new AgentUtility
|
||||
{
|
||||
Name = UtilityName.ImageReader,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = [new(READ_IMAGE_FN)],
|
||||
Templates = [new($"{READ_IMAGE_FN}.fn")]
|
||||
}
|
||||
Functions = [new(READ_IMAGE_FN)],
|
||||
Templates = [new($"{READ_IMAGE_FN}.fn")]
|
||||
},
|
||||
new AgentUtility
|
||||
{
|
||||
Name = UtilityName.ImageEditor,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = [new(EDIT_IMAGE_FN)],
|
||||
Templates = [new($"{EDIT_IMAGE_FN}.fn")]
|
||||
}
|
||||
Functions = [new(EDIT_IMAGE_FN)],
|
||||
Templates = [new($"{EDIT_IMAGE_FN}.fn")]
|
||||
},
|
||||
new AgentUtility
|
||||
{
|
||||
Name = UtilityName.PdfReader,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = [new(READ_PDF_FN)],
|
||||
Templates = [new($"{READ_PDF_FN}.fn")]
|
||||
}
|
||||
Functions = [new(READ_PDF_FN)],
|
||||
Templates = [new($"{READ_PDF_FN}.fn")]
|
||||
}
|
||||
};
|
||||
|
||||
base.OnLoadAgentUtility(agent, utilityLoads);
|
||||
base.OnAgentLoaded(agent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,14 +19,10 @@ public class HttpHandlerHook : AgentHookBase
|
|||
var utilityLoad = new AgentUtility
|
||||
{
|
||||
Name = UtilityName.HttpHandler,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = [new(HTTP_HANDLER_FN)],
|
||||
Templates = [new($"{HTTP_HANDLER_FN}.fn")]
|
||||
}
|
||||
Functions = [new(HTTP_HANDLER_FN)],
|
||||
Templates = [new($"{HTTP_HANDLER_FN}.fn")]
|
||||
};
|
||||
|
||||
base.OnLoadAgentUtility(agent, [utilityLoad]);
|
||||
base.OnAgentLoaded(agent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,10 @@ public class KnowledgeBaseAgentHook : AgentHookBase, IAgentHook
|
|||
var utilityLoad = new AgentUtility
|
||||
{
|
||||
Name = UtilityName.KnowledgeRetrieval,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = [new(KNOWLEDGE_RETRIEVAL_FN)],
|
||||
Templates = [new($"{KNOWLEDGE_RETRIEVAL_FN}.fn")]
|
||||
}
|
||||
Functions = [new(KNOWLEDGE_RETRIEVAL_FN)],
|
||||
Templates = [new($"{KNOWLEDGE_RETRIEVAL_FN}.fn")]
|
||||
};
|
||||
|
||||
base.OnLoadAgentUtility(agent, [utilityLoad]);
|
||||
base.OnAgentLoaded(agent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class AgentDocument : MongoBase
|
|||
public List<FunctionDefMongoElement> Functions { get; set; }
|
||||
public List<AgentResponseMongoElement> Responses { get; set; }
|
||||
public List<string> Samples { get; set; }
|
||||
public List<string> Utilities { get; set; }
|
||||
public List<AgentUtilityMongoElement> Utilities { get; set; }
|
||||
public bool IsPublic { get; set; }
|
||||
public bool Disabled { get; set; }
|
||||
public List<string> Profiles { get; set; }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
using BotSharp.Abstraction.Agents.Models;
|
||||
|
||||
namespace BotSharp.Plugin.MongoStorage.Models;
|
||||
|
||||
public class AgentUtilityMongoElement
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public List<UtilityFunctionMongoElement> Functions { get; set; } = [];
|
||||
public List<UtilityTemplateMongoElement> Templates { get; set; } = [];
|
||||
|
||||
public static AgentUtilityMongoElement ToMongoElement(AgentUtility utility)
|
||||
{
|
||||
return new AgentUtilityMongoElement
|
||||
{
|
||||
Name = utility.Name,
|
||||
Functions = utility.Functions?.Select(x => new UtilityFunctionMongoElement(x.Name))?.ToList() ?? [],
|
||||
Templates = utility.Templates?.Select(x => new UtilityTemplateMongoElement(x.Name))?.ToList() ?? []
|
||||
};
|
||||
}
|
||||
|
||||
public static AgentUtility ToDomainElement(AgentUtilityMongoElement utility)
|
||||
{
|
||||
return new AgentUtility
|
||||
{
|
||||
Name = utility.Name,
|
||||
Functions = utility.Functions?.Select(x => new UtilityFunction(x.Name))?.ToList() ?? [],
|
||||
Templates = utility.Templates?.Select(x => new UtilityTemplate(x.Name))?.ToList() ?? []
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class UtilityFunctionMongoElement
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public UtilityFunctionMongoElement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public UtilityFunctionMongoElement(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
|
||||
public class UtilityTemplateMongoElement
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public UtilityTemplateMongoElement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public UtilityTemplateMongoElement(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
|
|
@ -224,13 +224,15 @@ public partial class MongoRepository
|
|||
_dc.Agents.UpdateOne(filter, update);
|
||||
}
|
||||
|
||||
private void UpdateAgentUtilities(string agentId, List<string> utilities)
|
||||
private void UpdateAgentUtilities(string agentId, List<AgentUtility> utilities)
|
||||
{
|
||||
if (utilities == null) return;
|
||||
|
||||
var elements = utilities?.Select(x => AgentUtilityMongoElement.ToMongoElement(x))?.ToList() ?? [];
|
||||
|
||||
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
|
||||
var update = Builders<AgentDocument>.Update
|
||||
.Set(x => x.Utilities, utilities)
|
||||
.Set(x => x.Utilities, elements)
|
||||
.Set(x => x.UpdatedTime, DateTime.UtcNow);
|
||||
|
||||
_dc.Agents.UpdateOne(filter, update);
|
||||
|
|
@ -263,7 +265,7 @@ public partial class MongoRepository
|
|||
.Set(x => x.Functions, agent.Functions.Select(f => FunctionDefMongoElement.ToMongoElement(f)).ToList())
|
||||
.Set(x => x.Responses, agent.Responses.Select(r => AgentResponseMongoElement.ToMongoElement(r)).ToList())
|
||||
.Set(x => x.Samples, agent.Samples)
|
||||
.Set(x => x.Utilities, agent.Utilities)
|
||||
.Set(x => x.Utilities, agent.Utilities.Select(u => AgentUtilityMongoElement.ToMongoElement(u)).ToList())
|
||||
.Set(x => x.LlmConfig, AgentLlmConfigMongoElement.ToMongoElement(agent.LlmConfig))
|
||||
.Set(x => x.IsPublic, agent.IsPublic)
|
||||
.Set(x => x.UpdatedTime, DateTime.UtcNow);
|
||||
|
|
@ -406,28 +408,18 @@ public partial class MongoRepository
|
|||
IconUrl = x.IconUrl,
|
||||
Description = x.Description,
|
||||
Instruction = x.Instruction,
|
||||
ChannelInstructions = x.ChannelInstructions?
|
||||
.Select(i => ChannelInstructionMongoElement.ToMongoElement(i))?
|
||||
.ToList() ?? new List<ChannelInstructionMongoElement>(),
|
||||
Templates = x.Templates?
|
||||
.Select(t => AgentTemplateMongoElement.ToMongoElement(t))?
|
||||
.ToList() ?? new List<AgentTemplateMongoElement>(),
|
||||
Functions = x.Functions?
|
||||
.Select(f => FunctionDefMongoElement.ToMongoElement(f))?
|
||||
.ToList() ?? new List<FunctionDefMongoElement>(),
|
||||
Responses = x.Responses?
|
||||
.Select(r => AgentResponseMongoElement.ToMongoElement(r))?
|
||||
.ToList() ?? new List<AgentResponseMongoElement>(),
|
||||
ChannelInstructions = x.ChannelInstructions?.Select(i => ChannelInstructionMongoElement.ToMongoElement(i))?.ToList() ?? [],
|
||||
Templates = x.Templates?.Select(t => AgentTemplateMongoElement.ToMongoElement(t))?.ToList() ?? [],
|
||||
Functions = x.Functions?.Select(f => FunctionDefMongoElement.ToMongoElement(f))?.ToList() ?? [],
|
||||
Responses = x.Responses?.Select(r => AgentResponseMongoElement.ToMongoElement(r))?.ToList() ?? [],
|
||||
Samples = x.Samples ?? new List<string>(),
|
||||
Utilities = x.Utilities ?? new List<string>(),
|
||||
Utilities = x.Utilities?.Select(u => AgentUtilityMongoElement.ToMongoElement(u))?.ToList() ?? [],
|
||||
IsPublic = x.IsPublic,
|
||||
Type = x.Type,
|
||||
InheritAgentId = x.InheritAgentId,
|
||||
Disabled = x.Disabled,
|
||||
Profiles = x.Profiles,
|
||||
RoutingRules = x.RoutingRules?
|
||||
.Select(r => RoutingRuleMongoElement.ToMongoElement(r))?
|
||||
.ToList() ?? new List<RoutingRuleMongoElement>(),
|
||||
RoutingRules = x.RoutingRules?.Select(r => RoutingRuleMongoElement.ToMongoElement(r))?.ToList() ?? [],
|
||||
LlmConfig = AgentLlmConfigMongoElement.ToMongoElement(x.LlmConfig),
|
||||
CreatedTime = x.CreatedDateTime,
|
||||
UpdatedTime = x.UpdatedDateTime
|
||||
|
|
@ -505,24 +497,14 @@ public partial class MongoRepository
|
|||
IconUrl = agentDoc.IconUrl,
|
||||
Description = agentDoc.Description,
|
||||
Instruction = agentDoc.Instruction,
|
||||
ChannelInstructions = !agentDoc.ChannelInstructions.IsNullOrEmpty() ? agentDoc.ChannelInstructions
|
||||
.Select(i => ChannelInstructionMongoElement.ToDomainElement(i))
|
||||
.ToList() : new List<ChannelInstruction>(),
|
||||
Templates = !agentDoc.Templates.IsNullOrEmpty() ? agentDoc.Templates
|
||||
.Select(t => AgentTemplateMongoElement.ToDomainElement(t))
|
||||
.ToList() : new List<AgentTemplate>(),
|
||||
Functions = !agentDoc.Functions.IsNullOrEmpty() ? agentDoc.Functions
|
||||
.Select(f => FunctionDefMongoElement.ToDomainElement(f))
|
||||
.ToList() : new List<FunctionDef>(),
|
||||
Responses = !agentDoc.Responses.IsNullOrEmpty() ? agentDoc.Responses
|
||||
.Select(r => AgentResponseMongoElement.ToDomainElement(r))
|
||||
.ToList() : new List<AgentResponse>(),
|
||||
RoutingRules = !agentDoc.RoutingRules.IsNullOrEmpty() ? agentDoc.RoutingRules
|
||||
.Select(r => RoutingRuleMongoElement.ToDomainElement(agentDoc.Id, agentDoc.Name, r))
|
||||
.ToList() : new List<RoutingRule>(),
|
||||
ChannelInstructions = agentDoc.ChannelInstructions?.Select(i => ChannelInstructionMongoElement.ToDomainElement(i))?.ToList() ?? [],
|
||||
Templates = agentDoc.Templates?.Select(t => AgentTemplateMongoElement.ToDomainElement(t))?.ToList() ?? [],
|
||||
Functions = agentDoc.Functions?.Select(f => FunctionDefMongoElement.ToDomainElement(f)).ToList() ?? [],
|
||||
Responses = agentDoc.Responses?.Select(r => AgentResponseMongoElement.ToDomainElement(r))?.ToList() ?? [],
|
||||
RoutingRules = agentDoc.RoutingRules?.Select(r => RoutingRuleMongoElement.ToDomainElement(agentDoc.Id, agentDoc.Name, r))?.ToList() ?? [],
|
||||
LlmConfig = AgentLlmConfigMongoElement.ToDomainElement(agentDoc.LlmConfig),
|
||||
Samples = agentDoc.Samples ?? new List<string>(),
|
||||
Utilities = agentDoc.Utilities ?? new List<string>(),
|
||||
Samples = agentDoc.Samples ?? [],
|
||||
Utilities = agentDoc.Utilities?.Select(u => AgentUtilityMongoElement.ToDomainElement(u))?.ToList() ?? [],
|
||||
IsPublic = agentDoc.IsPublic,
|
||||
Disabled = agentDoc.Disabled,
|
||||
Type = agentDoc.Type,
|
||||
|
|
|
|||
|
|
@ -37,22 +37,18 @@ public class PlannerAgentHook : AgentHookBase
|
|||
var utilityLoad = new AgentUtility
|
||||
{
|
||||
Name = UtilityName.TwoStagePlanner,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = [
|
||||
new(PRIMARY_STAGE_FN),
|
||||
new(SECONDARY_STAGE_FN),
|
||||
new(SUMMARY_FN)
|
||||
],
|
||||
Templates = [
|
||||
new($"{PRIMARY_STAGE_FN}.fn"),
|
||||
new($"{SECONDARY_STAGE_FN}.fn"),
|
||||
new($"{SUMMARY_FN}.fn")
|
||||
]
|
||||
}
|
||||
Functions = [
|
||||
new(PRIMARY_STAGE_FN),
|
||||
new(SECONDARY_STAGE_FN),
|
||||
new(SUMMARY_FN)
|
||||
],
|
||||
Templates = [
|
||||
new($"{PRIMARY_STAGE_FN}.fn"),
|
||||
new($"{SECONDARY_STAGE_FN}.fn"),
|
||||
new($"{SUMMARY_FN}.fn")
|
||||
]
|
||||
};
|
||||
|
||||
base.OnLoadAgentUtility(agent, [utilityLoad]);
|
||||
base.OnAgentLoaded(agent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,39 @@
|
|||
"disabled": false,
|
||||
"isPublic": true,
|
||||
"profiles": [ "planning" ],
|
||||
"utilities": [ "two-stage-planner", "sql-dictionary-lookup", "excel-handler" ],
|
||||
"utilities": [
|
||||
{
|
||||
"name": "two-stage-planner",
|
||||
"functions": [
|
||||
{ "name": "plan_primary_stage" },
|
||||
{ "name": "plan_secondary_stage" },
|
||||
{ "name": "plan_summary" }
|
||||
],
|
||||
"templates": [
|
||||
{ "name": "plan_primary_stage.fn" },
|
||||
{ "name": "plan_secondary_stage.fn" },
|
||||
{ "name": "plan_summary.fn" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "sql-dictionary-lookup",
|
||||
"functions": [
|
||||
{ "name": "verify_dictionary_term" }
|
||||
],
|
||||
"templates": [
|
||||
{ "name": "verify_dictionary_term.fn" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "excel-handler",
|
||||
"functions": [
|
||||
{ "name": "handle_excel_request" }
|
||||
],
|
||||
"templates": [
|
||||
{ "name": "handle_excel_request.fn" }
|
||||
]
|
||||
}
|
||||
],
|
||||
"llmConfig": {
|
||||
"provider": "openai",
|
||||
"model": "gpt-4o",
|
||||
|
|
|
|||
|
|
@ -26,33 +26,23 @@ public class SqlDriverAgentHook : AgentHookBase, IAgentHook
|
|||
new AgentUtility
|
||||
{
|
||||
Name = UtilityName.SqlTableDefinition,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = new List<UtilityFunction> { new(SQL_TABLE_DEFINITION_FN) },
|
||||
Templates = new List<UtilityTemplate> { new($"{SQL_TABLE_DEFINITION_FN}.fn") }
|
||||
}
|
||||
Functions = [new(SQL_TABLE_DEFINITION_FN)],
|
||||
Templates = [new($"{SQL_TABLE_DEFINITION_FN}.fn")]
|
||||
},
|
||||
new AgentUtility
|
||||
{
|
||||
Name = UtilityName.SqlDictionaryLookup,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = new List<UtilityFunction> { new(VERIFY_DICTIONARY_TERM_FN) },
|
||||
Templates = new List<UtilityTemplate> { new($"{VERIFY_DICTIONARY_TERM_FN}.fn") }
|
||||
}
|
||||
Functions = [new(VERIFY_DICTIONARY_TERM_FN)],
|
||||
Templates = [new($"{VERIFY_DICTIONARY_TERM_FN}.fn")]
|
||||
},
|
||||
new AgentUtility
|
||||
{
|
||||
Name = UtilityName.SqlExecutor,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = new List<UtilityFunction> { new(SQL_SELECT_FN), new(SQL_TABLE_DEFINITION_FN) },
|
||||
Templates = new List<UtilityTemplate> { new($"sql_executor.fn") }
|
||||
}
|
||||
Functions = new List<UtilityFunction> { new(SQL_SELECT_FN), new(SQL_TABLE_DEFINITION_FN) },
|
||||
Templates = new List<UtilityTemplate> { new($"sql_executor.fn") }
|
||||
}
|
||||
};
|
||||
|
||||
base.OnLoadAgentUtility(agent, utilityLoads);
|
||||
base.OnAgentLoaded(agent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,14 +19,10 @@ namespace BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Hooks
|
|||
var utilityLoad = new AgentUtility
|
||||
{
|
||||
Name = UtilityName.OutboundPhoneCall,
|
||||
Content = new UtilityContent
|
||||
{
|
||||
Functions = [new(OUTBOUND_PHONE_CALL_FN)],
|
||||
Templates = [new($"{OUTBOUND_PHONE_CALL_FN}.fn")]
|
||||
}
|
||||
Functions = [new(OUTBOUND_PHONE_CALL_FN)],
|
||||
Templates = [new($"{OUTBOUND_PHONE_CALL_FN}.fn")]
|
||||
};
|
||||
|
||||
base.OnLoadAgentUtility(agent, [utilityLoad]);
|
||||
base.OnAgentLoaded(agent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue