createSkillsMiddleware(
options: SkillsMiddlewareOptions
): AgentMiddleware<StateSchema<__type>, undefined, unknown, readonly | Name | Type | Description |
|---|---|---|
options* | SkillsMiddlewareOptions |
Create backend-agnostic middleware for loading and exposing agent skills.
This middleware loads skills from configurable backend sources and injects skill metadata into the system prompt. It implements the progressive disclosure pattern: skill names and descriptions are shown in the prompt, but the agent reads full SKILL.md content only when needed.
Skills are loaded once per thread and stored in state. To pick up skills
added, edited, or deleted since then, set skillsMetadata to null; the
next model call reloads every source:
await agent.updateState(config, { skillsMetadata: null });
// or as part of the next run's input
await agent.invoke({ messages, skillsMetadata: null }, config);
Loading happens in beforeModel, so the reload is served by the next model
call rather than the next run. A middleware of your own can therefore
invalidate from any hook — including mid-run, from afterModel — and see
the fresh list on the following call. See skillsMetadataValue.
Configuration options
const middleware = createSkillsMiddleware({
backend: new FilesystemBackend({ rootDir: "/" }),
sources: ["/skills/user/", "/skills/project/"],
});