anything-llm/server/utils/agents/defaults.js
Timothy Carambat d1103e2b71
Add support for custom agent skills via plugins (#2202)
* Add support for custom agent skills via plugins
Update Admin.systemPreferences to updated endpoint (legacy has deprecation notice

* lint

* dev build

* patch safeJson
patch label loading

* allow plugins with no config options

* lint

* catch invalid setupArgs in frontend

* update link to docs page for agent skills

* remove unneeded files

---------

Co-authored-by: shatfield4 <seanhatfield5@gmail.com>
2024-09-10 17:06:02 -07:00

72 lines
2.0 KiB
JavaScript

const AgentPlugins = require("./aibitat/plugins");
const { SystemSettings } = require("../../models/systemSettings");
const { safeJsonParse } = require("../http");
const Provider = require("./aibitat/providers/ai-provider");
const ImportedPlugin = require("./imported");
const USER_AGENT = {
name: "USER",
getDefinition: async () => {
return {
interrupt: "ALWAYS",
role: "I am the human monitor and oversee this chat. Any questions on action or decision making should be directed to me.",
};
},
};
const WORKSPACE_AGENT = {
name: "@agent",
getDefinition: async (provider = null) => {
const defaultFunctions = [
AgentPlugins.memory.name, // RAG
AgentPlugins.docSummarizer.name, // Doc Summary
AgentPlugins.webScraping.name, // Collector web-scraping
];
return {
role: Provider.systemPrompt(provider),
functions: [
...defaultFunctions,
...(await agentSkillsFromSystemSettings()),
...(await ImportedPlugin.activeImportedPlugins()),
],
};
},
};
/**
* Fetches and preloads the names/identifiers for plugins that will be dynamically
* loaded later
* @returns {Promise<string[]>}
*/
async function agentSkillsFromSystemSettings() {
const systemFunctions = [];
const _setting = (await SystemSettings.get({ label: "default_agent_skills" }))
?.value;
safeJsonParse(_setting, []).forEach((skillName) => {
if (!AgentPlugins.hasOwnProperty(skillName)) return;
// This is a plugin module with many sub-children plugins who
// need to be named via `${parent}#${child}` naming convention
if (Array.isArray(AgentPlugins[skillName].plugin)) {
for (const subPlugin of AgentPlugins[skillName].plugin) {
systemFunctions.push(
`${AgentPlugins[skillName].name}#${subPlugin.name}`
);
}
return;
}
// This is normal single-stage plugin
systemFunctions.push(AgentPlugins[skillName].name);
});
return systemFunctions;
}
module.exports = {
USER_AGENT,
WORKSPACE_AGENT,
agentSkillsFromSystemSettings,
};