LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Agent
  • Middleware
  • Backends
  • Sandboxes
  • Skills
  • Subagents
  • Types
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
  • Vitest
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewAgentMiddlewareBackendsSandboxesSkillsSubagentsTypes
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
Vitest
Language
Theme
JavaScriptdeepagentsmiddlewarecreateSkillsMiddleware
Function●Since v1.5

createSkillsMiddleware

Copy
createSkillsMiddleware(
  options: SkillsMiddlewareOptions
): AgentMiddleware<StateSchema<__type>, undefined, unknown, readonly 
View source on GitHub
ClientTool
|
ServerTool
[
]
,
readonly
[
]
>

Parameters

NameTypeDescription
options*SkillsMiddlewareOptions

Example

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

Copy
const middleware = createSkillsMiddleware({
  backend: new FilesystemBackend({ rootDir: "/" }),
  sources: ["/skills/user/", "/skills/project/"],
});