examples/multiagent-patterns/subagent/README.md
A multi-agent example demonstrating the TaskTool pattern: a main orchestrator agent that delegates complex work to specialized sub-agents.
The Tech Due Diligence Assistant helps evaluate software projects by combining:
The main agent uses write_todos for planning and delegates to sub-agents via the Task and TaskOutput tools.
┌─────────────────────────────────────────────────────────────────┐
│ Tech Due Diligence Assistant │
│ (Orchestrator: write_todos, Task, TaskOutput, glob, grep, web) │
└────────────────────────────┬────────────────────────────────────┘
│ delegates via Task tool
┌─────────────────────────┼─────────────────────────┬──────────────────┐
▼ ▼ ▼ ▼
┌──────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────────┐
│codebase- │ │ web-researcher │ │ general-purpose │ │ dependency-analyzer │
│explorer │ │ web_fetch │ │ glob, grep, web │ │ (API-defined) │
│glob, grep │ │ │ │ │ │ glob, grep │
│(Markdown) │ │ (Markdown) │ │ (Markdown) │ └─────────────────────┘
└──────────────┘ └─────────────────┘ └─────────────────┘
Sub-agents can be defined in two ways:
| Agent | Tools | Use Case |
|---|---|---|
| codebase-explorer | glob_search, grep_search | Find files, search code, analyze structure |
| web-researcher | web_fetch | Fetch URLs, research docs, compare technologies |
| general-purpose | glob_search, grep_search, web_fetch | Combined code + web analysis |
Defined in src/main/resources/agents/*.md with YAML front matter.
| Agent | Tools | Use Case |
|---|---|---|
| dependency-analyzer | glob_search, grep_search | Analyze dependencies, version conflicts, outdated libs |
Defined in Java via ReactAgent.builder() and registered with TaskToolsBuilder.subAgent():
@Bean("dependencyAnalyzerAgent")
public ReactAgent dependencyAnalyzerAgent(ChatModel chatModel, List<ToolCallback> defaultTools) {
return ReactAgent.builder()
.name("dependency-analyzer")
.description("Analyzes project dependencies...")
.model(chatModel)
.systemPrompt(DEPENDENCY_ANALYZER_SYSTEM_PROMPT)
.tools(globSearch, grepSearch)
.build();
}
// In taskTools():
TaskToolsBuilder.builder()
.subAgent("dependency-analyzer", dependencyAnalyzerAgent) // API-defined
.addAgentResource(resource) // Markdown-defined
.build();
AI_DASHSCOPE_API_KEY environment variable set# From project root - run with interactive chat
cd /path/to/spring-ai-alibaba
AI_DASHSCOPE_API_KEY=your_key ./mvnw -f examples/multiagent-patterns/subagent/pom.xml spring-boot:run \
-Dspring-boot.run.arguments="--subagent.run-interactive=true"
Or set in application.yml:
subagent:
run-interactive: true
@Autowired
ReactAgent orchestratorAgent;
AssistantMessage response = orchestratorAgent.call(new UserMessage(
"Analyze this codebase for technical debt and research Spring AI documentation"));
| Property | Default | Description |
|---|---|---|
subagent.workspace-path | ${user.dir} | Root path for glob_search and grep_search |
subagent.run-interactive | false | Run interactive chat on startup |
addAgentResource() / addAgentDirectory() loads specs from .md filessubAgent(type, ReactAgent) registers programmatically defined ReactAgentsname, description, tools (comma-separated) in YAML front matter