You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.6 KiB

11 months ago
  1. const AgentPlugins = require("./aibitat/plugins");
  2. const { SystemSettings } = require("../../models/systemSettings");
  3. const { safeJsonParse } = require("../http");
  4. const Provider = require("./aibitat/providers/ai-provider");
  5. const ImportedPlugin = require("./imported");
  6. const { AgentFlows } = require("../agentFlows");
  7. // This is a list of skills that are built-in and default enabled.
  8. const DEFAULT_SKILLS = [
  9. AgentPlugins.memory.name,
  10. AgentPlugins.docSummarizer.name,
  11. AgentPlugins.webScraping.name,
  12. ];
  13. const USER_AGENT = {
  14. name: "USER",
  15. getDefinition: async () => {
  16. return {
  17. interrupt: "ALWAYS",
  18. role: "I am the human monitor and oversee this chat. Any questions on action or decision making should be directed to me.",
  19. };
  20. },
  21. };
  22. const WORKSPACE_AGENT = {
  23. name: "@agent",
  24. getDefinition: async (provider = null) => {
  25. return {
  26. role: Provider.systemPrompt(provider),
  27. functions: [
  28. ...(await agentSkillsFromSystemSettings()),
  29. ...ImportedPlugin.activeImportedPlugins(),
  30. ...AgentFlows.activeFlowPlugins(),
  31. ],
  32. };
  33. },
  34. };
  35. /**
  36. * Fetches and preloads the names/identifiers for plugins that will be dynamically
  37. * loaded later
  38. * @returns {Promise<string[]>}
  39. */
  40. async function agentSkillsFromSystemSettings() {
  41. const systemFunctions = [];
  42. // Load non-imported built-in skills that are configurable, but are default enabled.
  43. const _disabledDefaultSkills = safeJsonParse(
  44. await SystemSettings.getValueOrFallback(
  45. { label: "disabled_agent_skills" },
  46. "[]"
  47. ),
  48. []
  49. );
  50. DEFAULT_SKILLS.forEach((skill) => {
  51. if (!_disabledDefaultSkills.includes(skill))
  52. systemFunctions.push(AgentPlugins[skill].name);
  53. });
  54. // Load non-imported built-in skills that are configurable.
  55. const _setting = safeJsonParse(
  56. await SystemSettings.getValueOrFallback(
  57. { label: "default_agent_skills" },
  58. "[]"
  59. ),
  60. []
  61. );
  62. _setting.forEach((skillName) => {
  63. if (!AgentPlugins.hasOwnProperty(skillName)) return;
  64. // This is a plugin module with many sub-children plugins who
  65. // need to be named via `${parent}#${child}` naming convention
  66. if (Array.isArray(AgentPlugins[skillName].plugin)) {
  67. for (const subPlugin of AgentPlugins[skillName].plugin) {
  68. systemFunctions.push(
  69. `${AgentPlugins[skillName].name}#${subPlugin.name}`
  70. );
  71. }
  72. return;
  73. }
  74. // This is normal single-stage plugin
  75. systemFunctions.push(AgentPlugins[skillName].name);
  76. });
  77. return systemFunctions;
  78. }
  79. module.exports = {
  80. USER_AGENT,
  81. WORKSPACE_AGENT,
  82. agentSkillsFromSystemSettings,
  83. };