Class Skills

java.lang.Object
dev.langchain4j.skills.Skills

@Experimental public class Skills extends Object
Configures and exposes a set of Skills to an LLM.

Implements the Tool-based agents integration approach from the Agent Skills specification: all skill content and resources are loaded into memory at construction time. An activate_skill tool lets the LLM read a skill's instructions on demand, and an optional read_skill_resource tool reads preloaded resource content. The LLM has no access to the file system at inference time, only abovementioned tools can be called and there is no risk of arbitrary code execution.

Typical usage with an AI Service:

Skills skills = Skills.from(FileSystemSkillLoader.loadSkills(skillsDir));

MyAiService service = AiServices.builder(MyAiService.class)
        .chatModel(chatModel)

        .systemMessage("You have access to the following skills:\n" + skills.formatAvailableSkills() + "\nWhen the user's request relates to one of these skills, activate it first using the `activate_skill` tool before proceeding.")
        // or, if you already have a system message configured:
        .systemMessageTransformer(systemMessage -> systemMessage + "\n\nYou have access to the following skills:\n" + skills.formatAvailableSkills() + "\nWhen the user's request relates to one of these skills, activate it first using the `activate_skill` tool before proceeding.")

        .toolProvider(skills.toolProvider())
        // or, if you already have an MCP tool provider configured:
        .toolProviders(mcpToolProvider, skills.toolProvider())

        .build();
  • Constructor Details

  • Method Details

    • toolProvider

      public ToolProvider toolProvider()
      Returns the ToolProvider that exposes the activate_skill and read_skill_resource tools to the LLM. Pass this to AiServices.builder(...).toolProvider(...).
    • formatAvailableSkills

      public String formatAvailableSkills()
      Returns an XML-formatted string listing all configured skills with their names and descriptions. Intended to be included in the system message to inform the LLM which skills are available.
    • from

      public static Skills from(Collection<? extends Skill> skills)
      Creates a Skills instance with default configuration from the given collection of skills.
    • from

      public static Skills from(Skill... skills)
      Creates a Skills instance with default configuration from the given skills.
    • builder

      public static Skills.Builder builder()