Class ClassPathSkillLoader

java.lang.Object
dev.langchain4j.skills.ClassPathSkillLoader

@Experimental public class ClassPathSkillLoader extends Object
Loads skills from the classpath (including cases when they are packaged inside a JAR file that is on the classpath).

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.

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.

When skills are loaded from a plain directory on the classpath (not from a JAR), 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.

  • Method Details

    • loadSkills

      public static List<Skill> loadSkills(String directoryOnClasspath)
      Loads all skills found in immediate subdirectories of the given classpath directory. Uses the thread's context class loader.
      Parameters:
      directoryOnClasspath - the classpath directory whose immediate subdirectories are scanned for skills
      Returns:
      the list of loaded skills
      Throws:
      IllegalArgumentException - if the directory is not found on the classpath, or if a skill's SKILL.md or resource is a symbolic link to a file outside of its skill directory
    • loadSkills

      public static List<Skill> loadSkills(String directoryOnClasspath, ClassLoader classLoader)
      Loads all skills found in immediate subdirectories of the given classpath directory.
      Parameters:
      directoryOnClasspath - the classpath directory whose immediate subdirectories are scanned for skills
      classLoader - the class loader to use
      Returns:
      the list of loaded skills
      Throws:
      IllegalArgumentException - if the directory is not found on the classpath, or if a skill's SKILL.md or resource is a symbolic link to a file outside of its skill directory
    • loadSkill

      public static Skill loadSkill(String skillDirectoryOnClasspath)
      Loads a single skill from the given classpath directory. Uses the thread's context class loader.
      Parameters:
      skillDirectoryOnClasspath - the classpath path to the skill directory
      Returns:
      the loaded skill
      Throws:
      IllegalArgumentException - if the skill directory or its SKILL.md is not found, or if SKILL.md or a resource is a symbolic link to a file outside of the skill directory
    • loadSkill

      public static Skill loadSkill(String skillDirectoryOnClasspath, ClassLoader classLoader)
      Loads a single skill from the given classpath directory.
      Parameters:
      skillDirectoryOnClasspath - the classpath path to the skill directory
      classLoader - the class loader to use
      Returns:
      the loaded skill
      Throws:
      IllegalArgumentException - if the skill directory or its SKILL.md is not found, or if SKILL.md or a resource is a symbolic link to a file outside of the skill directory