Class TaskToolsBuilder
java.lang.Object
com.alibaba.cloud.ai.graph.agent.tools.task.TaskToolsBuilder
Convenience builder for configuring both TaskTool and TaskOutputTool with a shared TaskRepository.
Supports two modes:
- Programmatic: Pass
ReactAgentinstances viasubAgents(Map)orsubAgent(String, ReactAgent). - File-based: Load agent specs from Markdown files via
addAgentDirectory(String)oraddAgentResource(Resource). Specs are converted to ReactAgents usingAgentSpecReactAgentFactory.
// Programmatic mode
List<ToolCallback> taskTools = TaskToolsBuilder.builder()
.taskRepository(repo)
.subAgents(Map.of("Explore", exploreAgent))
.build();
// File-based mode
List<ToolCallback> taskTools = TaskToolsBuilder.builder()
.taskRepository(repo)
.chatModel(chatModel)
.defaultTools(grepTool, globTool, readTool)
.addAgentDirectory(".claude/agents")
.build();
- Author:
- Spring AI Alibaba
-
Method Summary
Modifier and TypeMethodDescriptionaddAgentDirectory(String directoryPath) Add a directory to load agent specs from (file-based mode).addAgentResource(org.springframework.core.io.Resource resource) Add a Spring Resource to load agent specs from (file-based mode).Set the factory for converting specs to ReactAgents (file-based mode).List<org.springframework.ai.tool.ToolCallback>build()Build both TaskTool and TaskOutputTool as a list of ToolCallbacks.static TaskToolsBuilderbuilder()Create a new builder.chatClient(org.springframework.ai.chat.client.ChatClient chatClient) Set ChatClient for file-based mode (used to build ReactAgents from specs).chatModel(org.springframework.ai.chat.model.ChatModel chatModel) Set ChatModel for file-based mode (used to build ReactAgents from specs).defaultTools(org.springframework.ai.tool.ToolCallback... tools) Set default tools for sub-agents (file-based mode).subAgent(String type, ReactAgent agent) Add a single sub-agent (programmatic mode).subAgents(Map<String, ReactAgent> subAgents) Set the map of sub-agent types to ReactAgent instances (programmatic mode).taskRepository(TaskRepository taskRepository) Set the task repository (required for background execution).
-
Method Details
-
builder
Create a new builder. -
taskRepository
Set the task repository (required for background execution). -
subAgents
Set the map of sub-agent types to ReactAgent instances (programmatic mode). -
subAgent
Add a single sub-agent (programmatic mode). -
addAgentDirectory
Add a directory to load agent specs from (file-based mode). Scans for .md files recursively. RequireschatModel(ChatModel)orchatClient(ChatClient)anddefaultTools(ToolCallback...). -
addAgentResource
Add a Spring Resource to load agent specs from (file-based mode). For classpath resources, useresourceLoader.getResource("classpath:.claude/agents"). -
agentSpecFactory
Set the factory for converting specs to ReactAgents (file-based mode). If not set, one is built from chatModel/chatClient and defaultTools in build(). -
chatModel
Set ChatModel for file-based mode (used to build ReactAgents from specs). -
chatClient
Set ChatClient for file-based mode (used to build ReactAgents from specs). -
defaultTools
Set default tools for sub-agents (file-based mode). -
build
Build both TaskTool and TaskOutputTool as a list of ToolCallbacks.
-