Class Skills
java.lang.Object
dev.langchain4j.skills.Skills
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();
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Skills.Builderbuilder()Returns an XML-formatted string listing all configured skills with their names and descriptions.static SkillsCreates aSkillsinstance with default configuration from the given skills.static Skillsfrom(Collection<? extends Skill> skills) Creates aSkillsinstance with default configuration from the given collection of skills.
-
Constructor Details
-
Skills
-
-
Method Details
-
toolProvider
Returns theToolProviderthat exposes theactivate_skillandread_skill_resourcetools to the LLM. Pass this toAiServices.builder(...).toolProvider(...). -
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
Creates aSkillsinstance with default configuration from the given collection of skills. -
from
-
builder
-