n8n
Version:
n8n Workflow Automation Tool
82 lines (80 loc) • 3.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConfigRulesSection = getConfigRulesSection;
exports.getSchemaReferenceSection = getSchemaReferenceSection;
const zod_1 = require("zod");
const zod_to_json_schema_1 = require("zod-to-json-schema");
const api_types_1 = require("@n8n/api-types");
const schema_text_serializer_1 = require("../../json-config/schema-text-serializer");
const BuilderPromptMemoryWorkerModelSchema = zod_1.z.object({
model: api_types_1.AgentModelSchema,
credential: zod_1.z.string().trim().min(1),
});
const BuilderPromptMemoryConfigSchema = zod_1.z.object({
enabled: zod_1.z.boolean(),
storage: zod_1.z.literal('n8n'),
observationalMemory: zod_1.z
.object({
enabled: zod_1.z.boolean().optional(),
observerModel: BuilderPromptMemoryWorkerModelSchema.optional(),
reflectorModel: BuilderPromptMemoryWorkerModelSchema.optional(),
observerThresholdTokens: zod_1.z.number().int().min(1).optional(),
reflectorThresholdTokens: zod_1.z.number().int().min(1).optional(),
renderTokenBudget: zod_1.z.number().int().min(1).optional(),
observationLogTailLimit: zod_1.z.number().int().min(1).optional(),
lockTtlMs: zod_1.z.number().int().min(0).optional(),
})
.optional(),
episodicMemory: zod_1.z
.discriminatedUnion('enabled', [
zod_1.z.object({ enabled: zod_1.z.literal(false) }),
zod_1.z.object({
enabled: zod_1.z.literal(true),
credential: zod_1.z.string().min(1),
extractorModel: BuilderPromptMemoryWorkerModelSchema.optional(),
reflectorModel: BuilderPromptMemoryWorkerModelSchema.optional(),
topK: zod_1.z.number().int().min(1).max(100).optional(),
maxEntriesPerRun: zod_1.z.number().int().min(1).max(50).optional(),
}),
])
.optional(),
});
const BuilderPromptAgentJsonConfigSchema = api_types_1.RunnableAgentJsonConfigSchema.extend({
memory: BuilderPromptMemoryConfigSchema.optional(),
});
function getConfigRulesSection() {
return `\
#### Agent Config Rules
- \`model\` must be "provider/model-name".
- \`credential\` must be the id returned by \`resolve_llm\` or \`ask_llm\`.
- Fresh agents must include
\`memory: { "enabled": true, "storage": "n8n" }\`
unless the user explicitly asks to disable memory.
- \`memory.storage\` must be "n8n".
- \`memory.episodicMemory\` requires \`ask_credential\` with
\`credentialType: "openAiApi"\`.
- Memory worker model fields use \`{ "model": "provider/model-name", "credential": "<credentialId>" }\`;
use only credential IDs returned by \`resolve_llm\`, \`ask_llm\`, or \`ask_credential\`.
- Web search lives under \`config.webSearch\`. Only OpenAI and Anthropic models
support native web search; for those providers, use
\`{ "enabled": true, "provider": "native" }\` or omit \`provider\`. Every
other provider requires fallback search with \`provider: "brave"\` or
\`provider: "searxng"\` and a credential. Never write \`{ "enabled": true }\`
alone for fallback search. Use exact \`ask_credential\` types:
\`braveSearchApi\` for Brave and \`searXngApi\` for SearXNG.
- Preserve existing Brave/SearXNG \`config.webSearch\` on model switches unless
the user explicitly asks to change web-search method.
- \`config.maxIterations\` caps the number of agent loop iterations per run. Do not set or change this unless the user explicitly asks.
- Fresh agents need a real model, credential, and instructions before config
is written.`;
}
function getSchemaReferenceSection() {
const zodSchema = BuilderPromptAgentJsonConfigSchema;
const jsonSchemaText = (0, schema_text_serializer_1.jsonSchemaToCompactText)((0, zod_to_json_schema_1.zodToJsonSchema)(zodSchema));
return `\
#### Config Schema Reference
\`\`\`text
${jsonSchemaText}
\`\`\``;
}
//# sourceMappingURL=config-rules.prompt.js.map