Files
anything-llm/server/utils/agents/defaults.js
Marcello Fitton 4a4378ed99 chore: add ESLint to /server (#5126)
* add eslint config to server

* add break statements to switch case

* add support for browser globals and turn off empty catch blocks

* disable lines with useless try/catch wrappers

* format

* fix no-undef errors

* disbale lines violating no-unsafe-finally

* ignore syncStaticLists.mjs

* use proper null check for creatorId instead of unreachable nullish coalescing

* remove unneeded typescript eslint comment

* make no-unused-private-class-members a warning

* disable line for no-empty-objects

* add new lint script

* fix no-unused-vars violations

* make no-unsued-vars an error

---------

Co-authored-by: shatfield4 <seanhatfield5@gmail.com>
Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
2026-03-05 16:32:45 -08:00

102 lines
3.1 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 { AgentFlows } = require("../agentFlows");
const MCPCompatibilityLayer = require("../MCP");
// This is a list of skills that are built-in and default enabled.
const DEFAULT_SKILLS = [
AgentPlugins.memory.name,
AgentPlugins.docSummarizer.name,
AgentPlugins.webScraping.name,
];
const USER_AGENT = {
name: "USER",
getDefinition: () => {
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",
/**
* Get the definition for the workspace agent with its role (prompt) and functions in Aibitat format
* @param {string} provider
* @param {import("@prisma/client").workspaces | null} workspace
* @param {import("@prisma/client").users | null} user
* @returns {Promise<{ role: string, functions: object[] }>}
*/
getDefinition: async (provider = null, workspace = null, user = null) => {
return {
role: await Provider.systemPrompt({ provider, workspace, user }),
functions: [
...(await agentSkillsFromSystemSettings()),
...ImportedPlugin.activeImportedPlugins(),
...AgentFlows.activeFlowPlugins(),
...(await new MCPCompatibilityLayer().activeMCPServers()),
],
};
},
};
/**
* Fetches and preloads the names/identifiers for plugins that will be dynamically
* loaded later
* @returns {Promise<string[]>}
*/
async function agentSkillsFromSystemSettings() {
const systemFunctions = [];
// Load non-imported built-in skills that are configurable, but are default enabled.
const _disabledDefaultSkills = safeJsonParse(
await SystemSettings.getValueOrFallback(
{ label: "disabled_agent_skills" },
"[]"
),
[]
);
DEFAULT_SKILLS.forEach((skill) => {
if (!_disabledDefaultSkills.includes(skill))
systemFunctions.push(AgentPlugins[skill].name);
});
// Load non-imported built-in skills that are configurable.
const _setting = safeJsonParse(
await SystemSettings.getValueOrFallback(
{ label: "default_agent_skills" },
"[]"
),
[]
);
_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,
};