UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

33 lines (32 loc) • 1.92 kB
export const POLICY_NAME_REFUSAL_CODE = "config.legacy_tool_name"; const LAYER_WORD = { caller_policy: "the run's tool policy", session_rules: "the session's stored permission rules", ancestor_session_rules: "the stored permission rules of an ancestor session", task_selector: "the run's tool-name lists", skill_table: "a Skill's disallowed-tools", host_table: "a restricting tool table of the host", }; export const RETIRED_NOTICE_ENTRIES_SHOWN = 32; export function accountOfRetired(layer, entries) { const unique = []; const seen = new Set(); for (const e of entries) { const key = `${e.field}\u0000${e.entry}\u0000${e.source ?? ""}`; if (seen.has(key)) continue; seen.add(key); unique.push(e); } const one = unique.length === 1; const shown = unique.slice(0, 5).map((e) => `${e.field}-list entry "${e.entry}"${e.source !== undefined ? ` of ${e.source}` : ""}`); const more = unique.length > shown.length ? ` and ${unique.length - shown.length} more` : ""; return { message: `${LAYER_WORD[layer]} holds ${shown.join(", ")}${more}, ${one ? "a RETIRED tool name" : "RETIRED tool names"} that ${one ? "reaches" : "reach"} no tool in this run's roster — ${one ? "it guards" : "they guard"} nothing, and the run goes on without ${one ? "it" : "them"}. Remove ${one ? "the entry" : "the entries"} from the list.`, detail: { layer, entries: unique.slice(0, RETIRED_NOTICE_ENTRIES_SHOWN).map((e) => ({ field: e.field, entry: e.entry, layer: e.layer, guidance: e.guidance, ...(e.source !== undefined ? { source: e.source } : {}) })), total: unique.length }, }; } export function retiredToolNameNotice(layer, entries, sessionId) { const account = accountOfRetired(layer, entries); return { code: POLICY_NAME_REFUSAL_CODE, message: account.message, detail: { ...account.detail, sessionId } }; }