Demonstrates the Task Tools feature for delegating tasks to specialized sub-agents using Spring AI.
This example shows how to configure a main agent that can delegate tasks to specialized sub-agents. Each sub-agent has its own context window, system prompt, and tool access.
- Set environment variables:
export GOOGLE_CLOUD_PROJECT=your-project-id
# Or use Anthropic/OpenAI (see application.properties)- Run the application:
./mvnw spring-boot:runvar taskTool = TaskTool.builder()
.subagentTypes(ClaudeSubagentType.builder()
.skillsResources(skillPaths)
.chatClientBuilder("default", chatClientBuilder.clone())
.braveApiKey(braveApiKey)
.build())
.build();
ChatClient chatClient = chatClientBuilder
.defaultToolCallbacks(taskTool)
// ... other tools and advisors
.build();agent.skills.paths=classpath:/skills
agent.tasks.paths=classpath:/agentssrc/main/resources/
├── agents/
│ └── spring-ai-expert.md # Custom sub-agent definition
├── skills/
│ └── ai-tutor/ # Skills available to sub-agents
└── prompt/
└── MAIN_AGENT_SYSTEM_PROMPT_V2.md
Sub-agents are defined as Markdown files with YAML frontmatter (agents/spring-ai-expert.md):
---
name: spring-ai-expert
description: Use this agent when the user asks questions about Spring AI...
model: sonnet
---
You are a Spring AI Expert...- TaskTool - Launches and manages sub-agents with pluggable resolvers and executors
- ClaudeSubagentType - Configures the Claude subagent type with default tools, skills, and model routing
- Custom Sub-Agents - Domain-specific expert (Spring AI)
- Skills Integration - Sub-agents receive preloaded skill content in their system prompt
- Multi-Model Support - Route sub-agents to different models via the
modelfrontmatter field
spring-ai-agent-utils- Core library with Task Tools and Claude subagent supportspring-ai-starter-model-google-genai- Google Gemini (configurable for Anthropic/OpenAI)
- Task Tools Documentation
- Subagent Framework
- Sub-Agent A2A Demo - Combining local and remote A2A sub-agents