UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

46 lines (45 loc) • 2.34 kB
import { engineTextFor } from "../prompt-assembly/engine-text.js"; export const WORKFLOW_SIZE_GUIDELINES = ["unrestricted", "small", "medium", "large"]; export const WORKFLOW_SIZE_GUIDELINE_DEFAULT = "medium"; export const WORKFLOW_SIZE_GUIDELINE_AGENT_CAPS = Object.freeze({ small: 5, medium: 15, large: 50, }); export function normalizeWorkflowSizeGuideline(value) { return WORKFLOW_SIZE_GUIDELINES.includes(value) ? value : undefined; } export function resolveWorkflowSizeGuideline(value) { const configured = normalizeWorkflowSizeGuideline(value); return configured === undefined ? { size: WORKFLOW_SIZE_GUIDELINE_DEFAULT, isDefault: true } : { size: configured, isDefault: false }; } export function workflowSizeGuidelineAgentCap(g) { return g === "small" || g === "medium" || g === "large" ? WORKFLOW_SIZE_GUIDELINE_AGENT_CAPS[g] : undefined; } function tierAndNotHardLimit(g, say) { return { tier: say("core/engine.workflow-size.tier", { size: g, cap: String(WORKFLOW_SIZE_GUIDELINE_AGENT_CAPS[g]) }), notHardLimit: say("core/engine.workflow-size.not-hard-limit") }; } export function formatWorkflowSizeGuidelineLabel(g) { const cap = workflowSizeGuidelineAgentCap(g); return cap === undefined ? g : `${g} (aim for <${cap} agents)`; } function workflowSizeGuidelineSentence(g, isDefault, say) { const lead = isDefault ? "This session has the default workflow size guideline:" : "A workflow size guideline is configured for this session:"; const escape = isDefault ? ' The user can raise or remove it with "Dynamic workflow size" in /config.' : ""; const { tier, notHardLimit } = tierAndNotHardLimit(g, say); return `${lead} ${tier}. ${notHardLimit}${escape}`; } export function workflowSizeGuidelineSection(value, say = engineTextFor()) { const { size, isDefault } = resolveWorkflowSizeGuideline(value); if (size === "unrestricted") return ""; return `\n\n${workflowSizeGuidelineSentence(size, isDefault, say)}`; } export function workflowSizeGuidelineChangeNotice(g, say) { if (g === "unrestricted") return say("core/event.workflow-size-guideline-change.unrestricted"); const { tier, notHardLimit } = tierAndNotHardLimit(g, say); return `${say("core/event.workflow-size-guideline-change", { tier })} ${notHardLimit}`; }