Class SkillsAgentHook
java.lang.Object
com.alibaba.cloud.ai.graph.agent.hook.AgentHook
com.alibaba.cloud.ai.graph.agent.hook.skills.SkillsAgentHook
- All Implemented Interfaces:
Hook,Prioritized
AgentHook for integrating Skills with ReactAgent.
This hook provides a complete Skills integration solution:
- Manages skill loading and reloading from the SkillRegistry
- Provides the `read_skill` tool for LLM to read SKILL.md files
- Automatically creates and configures SkillsInterceptor to inject skills into system prompts
The hook wraps a SkillRegistry instance and shares it with SkillsInterceptor.
The SkillRegistry must be provided explicitly - it will not be created automatically.
Skills can be optionally reloaded in beforeAgent if auto-reload is enabled.
The hook uses the SkillRegistry's generic interface methods, making it compatible
with any SkillRegistry implementation (FileSystemSkillRegistry, DatabaseSkillRegistry, etc.).
Example Usage:
// Create a FileSystemSkillRegistry first
FileSystemSkillRegistry registry = FileSystemSkillRegistry.builder()
.userSkillsDirectory("~/saa/skills")
.projectSkillsDirectory("./skills")
.build();
// Then create the hook with the registry
SkillsAgentHook hook = SkillsAgentHook.builder()
.skillRegistry(registry)
.autoReload(true)
.build();
// With grouped tools (skill name → tools for dynamic injection when LLM calls read_skill)
Map<String, List<ToolCallback>> groupedTools = Map.of("my-skill", List.of(myTool));
SkillsAgentHook hookWithTools = SkillsAgentHook.builder()
.skillRegistry(registry)
.groupedTools(groupedTools)
.build();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating SkillsAgentHook instances. -
Field Summary
Fields inherited from interface com.alibaba.cloud.ai.graph.agent.Prioritized
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Method Summary
Modifier and TypeMethodDescriptionbeforeAgent(OverAllState state, RunnableConfig config) static SkillsAgentHook.Builderbuilder()Gets the list of model interceptors provided by this hook.getName()Gets the unique name of this hook.intGet the SkillRegistry instance used by this hook.List<org.springframework.ai.tool.ToolCallback>getTools()Gets the list of tools provided by this hook.booleanMethods inherited from class com.alibaba.cloud.ai.graph.agent.hook.AgentHook
afterAgent, getAgent, getAgentName, getOrder, setAgent, setAgentNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.alibaba.cloud.ai.graph.agent.hook.Hook
canJumpTo, getHookPositions, getKeyStrategys, getToolInterceptors
-
Method Details
-
builder
-
beforeAgent
- Overrides:
beforeAgentin classAgentHook
-
getSkillRegistry
Get the SkillRegistry instance used by this hook. This allows sharing the registry with SkillsInterceptor.- Returns:
- the SkillRegistry instance
-
getModelInterceptors
Description copied from interface:HookGets the list of model interceptors provided by this hook.Model interceptors can modify model requests/responses, add retry logic, implement guardrails, or provide other cross-cutting concerns.
These interceptors will be merged with the agent's configured interceptors and applied to all model calls.
- Returns:
- list of model interceptors, empty list by default
- See Also:
-
getTools
Description copied from interface:HookGets the list of tools provided by this hook.Tools provided by hooks will be merged with the agent's configured tools and made available for the agent to use during execution.
These tools will be registered with the agent's tool node and can be invoked by the agent during its execution.
- Returns:
- list of tool callbacks, empty list by default
- See Also:
-
ToolCallback
-
getSkillCount
public int getSkillCount() -
hasSkill
-
listSkills
-
getName
Description copied from interface:HookGets the unique name of this hook. The name is used to identify the hook in the execution graph.- Returns:
- the hook name, must not be null
-