Class FileSystemSkillLoader

java.lang.Object
dev.langchain4j.skills.FileSystemSkillLoader

@Experimental public class FileSystemSkillLoader extends Object
Loads skills from the file system.

Each skill must reside in its own directory containing a SKILL.md file. The file must have a YAML front matter block that declares the skill's name and description. The body of the file (below the front matter) becomes the skill's content.

Example SKILL.md structure:

---
name: my-skill
description: Does something useful
---

Detailed instructions for the LLM go here.

Any additional files in the skill directory are loaded as SkillResources, except SKILL.md itself and any files under a scripts/ subdirectory. Empty files are silently skipped.

Symbolic links inside a skill directory are followed only when they point to a file inside the same skill directory. Symbolic links to directories inside a skill are not followed. If SKILL.md or a resource is a symbolic link to a file outside of the skill directory, loading fails with an IllegalArgumentException. The skill directory itself may be a symbolic link; in that case, the files of the directory it points to are loaded.

  • Constructor Details

    • FileSystemSkillLoader

      public FileSystemSkillLoader()
  • Method Details

    • loadSkills

      public static List<FileSystemSkill> loadSkills(Path directory)
      Loads all skills found in immediate subdirectories of the given directory. A subdirectory is treated as a skill only if it contains a SKILL.md file; subdirectories without one are silently skipped.
      Parameters:
      directory - the directory whose immediate subdirectories are scanned for skills
      Returns:
      the list of loaded skills, in filesystem iteration order
      Throws:
      IllegalArgumentException - if a skill's SKILL.md or resource is a symbolic link to a file outside of its skill directory
      RuntimeException - if the directory cannot be listed or a skill fails to load
    • loadSkill

      public static FileSystemSkill loadSkill(Path skillDirectory)
      Loads a single skill from the given directory. The directory must contain a SKILL.md file with a YAML front matter block declaring the skill's name and description.
      Parameters:
      skillDirectory - the directory to load the skill from
      Returns:
      the loaded skill
      Throws:
      IllegalArgumentException - if SKILL.md is not found in the directory, or if SKILL.md or a resource is a symbolic link to a file outside of the directory
      RuntimeException - if the file cannot be read or resources cannot be loaded