Skip to content
pleach
Build

Skills

SkillLoader loads markdown skills from three sources, matches them by user intent, and injects the body into the system prompt as a contribution.

A skill is a markdown file with YAML frontmatter. The runtime loads it, indexes it by intent, and injects its body into the system prompt when the user's intent matches. The variable surface is the markdown body and the activation policy in the frontmatter; the loader, the cache, and the intent matching are structural. See Prompts for the contribution shape the skill body becomes, and Subagents for how the model delegates to a child runtime.

Skill is one of three concepts in the composing-agents cluster, alongside the subagent spawn and the agent profile that scores a run.

Ships from the @pleach/core/skills barrel — a real, emitted subpath export (SkillLoader, parseSkillFrontmatter, and the Skill / SkillFrontmatter types all import from it). @pleach/core/skills/loader and @pleach/core/skills/types are exported too, and there is no /parser subpath; import everything from the @pleach/core/skills barrel.

import { SkillLoader, parseSkillFrontmatter } from "@pleach/core/skills";
import type { Skill, SkillFrontmatter } from "@pleach/core/skills";

Skill shape

FieldTypeNotes
namestringkebab-case identifier
descriptionstringOne-line summary
versionstring | undefinedSemver, optional
authorstring | undefinedEmail or identifier
allowedToolsstring[] | undefinedTools this skill relates to. A plan that uses one of them is a signal to surface the skill
disallowedToolsstring[] | undefinedStored with the skill. Read when deriving a sub-agent spec: these names are removed from allowedTools.
toolMode"inherit" | "none" | undefinedStored with the skill.
intentsstring[] | undefinedKeywords from the intent classifier
activationenumauto / manual / intent-matched (default intent-matched)
contentstringMarkdown body, injected into the prompt
sourceenumbuiltin / org / user / promoted
pathstring | undefinedFilesystem path (builtin skills)
executionobject | undefinedOptional maxSteps, timeout and canDelegate. A skill with an execution block can be derived into a sub-agent spec with deriveSubAgentSpecs (see Skills as sub-agents)

activation decides how the loader surfaces the skill. auto and intent-matched are both returned by getByIntent(intent); manual skills are returned only by getByName(name).

Loader sources

SkillLoader.loadAll(orgId?, userId?) walks three sources and unions the results into a single cache. Builtin first, then store, then subagent-spec migration; the loader returns the merged list and caches by name.

OrderSourceWhere it readsNotes
1Builtinskills/builtin/<name>/SKILL.md (server only)Skipped in the browser; missing dir is fine
2Org / user store[orgId, "skills"] then [orgId, userId, "skills"]The org tier is read first. It reads 50 rows a page and follows later pages when the store declares stable paging (searchPagingStable). The user tier reads up to 50
3Subagent specsThe subagentSpecs array passed to the constructorSkipped if a skill with the same name already exists from sources 1 or 2

The constructor takes the store and the spec list:

const loader = new SkillLoader({
  store,                                  // anything implementing { search }
  subagentSpecs: [
    {
      name:               "researcher",
      description:        "Fan out searches.",
      tools:              ["search_corpus", "search_news"],
      maxSteps:           5,
      timeout:            120_000,
      systemPromptSuffix: "You are a research subagent.",
    },
  ],
});

await loader.loadAll(orgId, userId);

A migrated subagent spec lands as a builtin skill with activation: "manual" — the spec was already gated by an explicit delegation, not by intent matching.

When the org read fails, or the loader can't show it read the whole org tier, user-tier skills still load and answer lookups, but they derive no sub-agent on that load (see Skills as sub-agents). The loader warns once when an org read stops early.

Lookups

MethodReturnsEffect
loadAll(orgId?, userId?)Skill[]Walks the three sources, clears and repopulates the cache
getByIntent(intent)Skill[]Skills whose intents include intent and whose activation is auto or intent-matched
getByName(name)Skill | undefinedExact-match cache lookup
getAll()Skill[]Every cached skill, one per name (the later entry wins)
getLoadedSkills()Skill[]The most recent load, unmerged, in load order. Pass this to deriveSubAgentSpecs
sizenumberCache size

loadAll is the only async method; everything else reads from the in-memory cache the load populated.

The lookup path is the synchronous half — call loadAll once at session start, then route per-turn intents through the cache.

await loader.loadAll(orgId, userId);

const matched = loader.getByIntent("vendor_evaluation");
for (const skill of matched) {
  systemPrompt.append(skill.content);
}

const fallback = loader.getByName("researcher");
if (fallback) await delegateToSubagent(fallback);

getByIntent filters to auto and intent-matched activations. getByName is the only path to a manual skill.

Skills as sub-agents

A skill that carries an execution block can run as a delegated sub-agent. deriveSubAgentSpecs turns the skills one loadAll returned into SubAgentSpec entries, and createDelegateToolLite turns a spec into a delegate_to_<name> tool the model can call. Nothing is registered for you: the host opts in by adding the derived specs to its own registry and contributing the tools from a plugin.

import { deriveSubAgentSpecs } from "@pleach/core/skills";
import { createDelegateToolLite, type SubAgentSpec } from "@pleach/core/subagents";
import { definePleachPlugin } from "@pleach/core/plugins";
import { createPleachRuntime } from "@pleach/core/runtime/createPleachRuntime";

const SPECS: Record<string, SubAgentSpec> = { /* the specs you already own */ };

// Derive before the runtime is built: contributeTools() is synchronous.
const skills = await loader.loadAll(orgId, userId);
const derived = deriveSubAgentSpecs(skills, SPECS, loader.migratedSpecNames());
for (const spec of derived) SPECS[spec.name] = spec;

const skillAgents = definePleachPlugin("skill-agents", {
  _raw: {
    version: "1.0.0",
    contributeTools: () => derived.map((spec) => createDelegateToolLite(spec)),
  },
});

const runtime = createPleachRuntime({ provider, plugins: [skillAgents] });

With a provider, when a plugin contributes a spawn-capable tool, which createDelegateToolLite returns, createPleachRuntime installs createToolLoopSubagentExecutor over the runtime's provider stream and plugin tools, with a maximum depth of 1. To use your own, pass subagentExecutor under host.raw. provider must carry a model, or pass model as well. The installed executor draws only on plugin tools, so the tools a skill lists must come from a plugin in the same plugins array.

deriveSubAgentSpecs(skills, hostSpecs, migratedNames) takes the loaded skills, your registry (a record or an array of specs) and the names SkillLoader#migratedSpecNames() reports. It is pure: the result depends only on its arguments. A name your registry already uses keeps your spec, and a spec the loader migrated in as a skill is not derived back.

Pass the unmerged load: the array loadAll returned, or getLoadedSkills() on a loader from loadSkillsMemoized. getAll() has already merged entries by name, so it can't apply the rule below.

Org wins on derive. When a name has an org or builtin entry, a user entry of the same name is passed over, whichever comes first in the array. The name comparison here ignores case, surrounding space, Unicode compatibility forms and _ versus -. Only the winning entry is graded: if it is refused, the name derives no spec rather than falling back to the user copy. loadAll and getByName keep their exact, later-entry-wins lookup.

What a derived spec looks like:

  • Which skills convert. A skill converts when it has an execution block and its source is builtin, org or user. A promoted skill is not converted. The name is lowercase kebab-case, at most 52 characters, and not general-purpose, which is reserved for spawn_agent. The body has a character limit. A skill read from the store keeps its execution block only when its stored source is org, user or promoted.
  • Tools. The spec's tools are the skill's allowedTools minus its disallowedTools. A skill with no list gets "none": the child holds no tools. toolMode does not widen that, and a derived agent never inherits the parent's toolset.
  • Limits. execution.maxSteps becomes the step budget (5 when it is not set) and execution.timeout, in milliseconds, the wall-clock budget. subAgentSpecToConfig clamps both, raising a timeout to at least a minimum floor. A maxSteps set on the tool-loop executor caps a derived child, so it can only lower the budget.
  • No further delegation. The spec sets noNestedSpawn, and canDelegate is not read. createToolLoopSubagentExecutor runs such a child with no spawn path and applies the spec's disallowedTools as SubAgentConfig.deniedTools. A sub-agent's deniedTools also applies to every sub-agent it starts, merged with any list the nested config passes.

Executors declare containment

A derived spec only runs on an executor that has declared it enforces noNestedSpawn and deniedTools. spawnAgent returns a failed result, without calling the executor, for a config that sets noNestedSpawn: true or a non-empty deniedTools when the configured executor hasn't declared support. Configs without those fields are unaffected. A noNestedSpawn that isn't a boolean, or a deniedTools that isn't an array of strings, fails with any executor.

createToolLoopSubagentExecutor declares support. A custom subagentExecutor, or a wrapper around a declared one, declares it once it applies both fields from the config it receives:

import {
  markSubagentContainmentHonoured,
  honoursSubagentContainment,
  configRequiresSubagentContainment,
} from "@pleach/core/subagents";

const executor = markSubagentContainmentHonoured(async (config, parentConfig, options) => {
  // Enforce config.noNestedSpawn and config.deniedTools here.
  return runChild(config, parentConfig, options);
});

honoursSubagentContainment(executor); // true

// A wrapper declares only if the inner executor did and it passes both fields through.
const traced = honoursSubagentContainment(inner)
  ? markSubagentContainmentHonoured(tracedWrapper)
  : tracedWrapper;

The declaration is an own, non-enumerable property on the function, so wrapping a declared executor drops it and the wrapper has to declare again. configRequiresSubagentContainment(config) reports whether a config needs a declared executor.

createDelegateToolLite(spec) returns a ToolDefinitionLite named delegate_to_<name>, with hyphens in the skill name mapped to underscores (vendor-evaluation becomes delegate_to_vendor_evaluation). It takes task (required) and context parameters, builds the child's config with subAgentSpecToConfig, and spawns it at the dispatching turn's depth. The result is { agent, result } on completion and { error } otherwise.

SKILL.md format

---
name: vendor-evaluation
description: Score vendors against a fixed rubric.
version: 1.0.0
author: ops@example.com
allowed-tools:
  - search_web
  - fetch_url
intents:
  - vendor_evaluation
  - rfp_scoring
activation: intent-matched
execution:
  maxSteps: 8
---

You are a vendor-evaluation agent. Score each candidate against the
fixed rubric in the user's request. Cite every claim with the URL
you pulled it from.

parseSkillFrontmatter(fileContent, source, filePath?) is exported directly for callers that want to parse a SKILL.md without going through the loader (tests, custom store adapters). The parser is intentionally a lightweight YAML reader — keys, scalars, inline arrays, indented arrays, and one level of nested objects. Anything more elaborate belongs in a real YAML library.

A direct parse, no loader involved:

import { parseSkillFrontmatter } from "@pleach/core/skills";

const raw = await readFile("./skills/builtin/researcher/SKILL.md", "utf-8");
const skill = parseSkillFrontmatter(raw, "builtin", "./skills/builtin/researcher/SKILL.md");

console.log(skill.name, skill.activation, skill.allowedTools);

On-demand skill bodies — skill_view

Progressive disclosure has two halves. The runtime injects a compact index of the active skills into the system prompt — each entry is the name plus a one-line description, not the full body — so the model sees what exists without paying the token cost of every body every turn. The model then loads a single body on demand with the skill_view tool, the moment it decides a skill is relevant.

skill_view ships from the @pleach/core/base-tools barrel and is agnostic by injection: you supply a SkillSource reader; the tool never learns where bodies live. Without a source it refuses every call (refuse-by-default), like the network tools.

import { createBaseToolsPlugin } from "@pleach/core/base-tools";
import { SkillLoader } from "@pleach/core/skills";

const loader = new SkillLoader({ store });
await loader.loadAll(orgId, userId);

const plugin = createBaseToolsPlugin({
  include: ["skill_view"],
  skillView: {
    // Given a name from the in-prompt index, return its body — or null.
    source: async (name) => {
      const skill = loader.getByName(name);
      return skill ? { name: skill.name, description: skill.description, content: skill.content } : null;
    },
  },
});

The model calls skill_view({ name }) with a name from the index and gets back { name, content }. An unknown name or a missing source returns a failed envelope (the model is told not to retry). Bodies over maxContentChars (default 24000) are truncated with a trailing marker.

OptionTypeNotes
sourceSkillSource | undefined(name, ctx) => Promise<{ name, description?, content } | null>. Absent ⇒ refuses.
maxContentCharsnumber | undefinedDefensive body cap, default 24000.

skill_view is opt-in — it is not in the default base-tools set, so list it explicitly in include and supply a source.

Agent-authored skills — create_skill

Skills don't have to be written by a human ahead of time. create_skill is a base-tool that lets the agent name a repeatable procedure as a reusable skill mid-session — it captures the steps once and turns them into a skill the agent can reach for again. Authored skills are then surfaced through the same progressive-disclosure path as any loaded skill: a one-line entry in the in-prompt index, the body pulled on demand with skill_view.

Like skill_view, create_skill is opt-in. It is not in the default base-tools set, so list it in include, and it becomes available when the runtime has a durable store — that store is where an authored skill persists. No store, nowhere to keep the skill.

Where to go next