SkillsMiddleware(
self,
*,
backend: BACKEND_TYPES,
sources: Sequence[SkillSource],
system_prompt: | Name | Type | Description |
|---|---|---|
backend* | BACKEND_TYPES | |
sources* | Sequence[SkillSource] | |
system_prompt | str | None | Default: SKILLS_SYSTEM_PROMPT |
| Name | Type |
|---|---|
| backend | BACKEND_TYPES |
| sources | Sequence[SkillSource] |
| system_prompt | str | None |
Middleware for loading and exposing agent skills to the system prompt.
Loads skills from backend sources and injects them into the system prompt using progressive disclosure (metadata first, full content on demand).
Skills are loaded in source order with later sources overriding earlier ones.
Example:
from deepagents.backends.filesystem import FilesystemBackend
backend = FilesystemBackend(root_dir="/path/to/skills")
middleware = SkillsMiddleware(
backend=backend,
sources=[
"/path/to/skills/user/",
"/path/to/skills/project/",
# Pass a (path, label) tuple to disambiguate sources whose
# leaf directories would otherwise collide
("/home/me/.claude/skills", "User Claude"),
("/repo/.claude/skills", "Project Claude"),
],
)
See constructor for the full argument list.
Backend instance (e.g. StateBackend()).
List of skill sources.
Each entry is either a bare path (e.g. '/skills/user/') or
a (path, label) tuple
(e.g. ('/home/me/.claude/skills', 'User Claude')). Labels
are rendered as **{label} Skills** in the system prompt
(do not include the trailing Skills in your label).
System-prompt fragment template. Must contain
{skills_locations}, {skills_load_warnings}, and
{skills_list} slots for runtime substitution. Pass None
to skip appending entirely (skills are still loaded into
state["skills_metadata"]).
Inject skills documentation into a model request's system message.
Load skills metadata before agent execution (synchronous).
Loads skills once per session from all configured sources. If
skills_metadata is already present in state (from a prior turn or
checkpointed session), the load is skipped and None is returned.
Skills are loaded in source order with later sources overriding earlier ones if they contain skills with the same name (last one wins).
Load skills metadata before agent execution (async).
Loads skills once per session from all configured sources. If
skills_metadata is already present in state (from a prior turn or
checkpointed session), the load is skipped and None is returned.
Skills are loaded in source order with later sources overriding earlier ones if they contain skills with the same name (last one wins).
Inject skills documentation into the system prompt.
Inject skills documentation into the system prompt (async version).