Sitemap

Spring AI Recipe: Invoking A2A Sub-Agents with TaskTool

2 min readApr 22, 2026

--

Press enter or click to view image in full size

In the previous recipe, we created an A2A-enabled agent and exposed it over HTTP. But using the A2A Inspector only takes you so far — the real purpose of A2A is to enable agents to delegate work to other agents.

Instead of handling everything itself, an agent can call on specialized sub-agents as needed to achieve its goal.

Spring AI’s TaskTool makes this delegation straightforward.

NOTE: This recipe has been updated since it’s original publication to reflect changes in Spring AI 2.0.0.

What is TaskTool?

The A2A Java SDK allows Java applications to invoke A2A-enabled agents, but using it directly can be cumbersome.

TaskTool simplifies this by registering a tool with ChatClient that proxies to one or more A2A sub-agents.

From the perspective of your agent, other agents become tools that it can invoke as part of its normal execution loop.

Starting Point

Begin with a simple Spring AI application, such as the chat loop from the first recipe.

Dependencies

Add the Spring AI Agent Utils and A2A support:

implementation 'org.springaicommunity:spring-ai-agent-utils:0.7.0'
implementation 'org.springaicommunity:spring-ai-agent-utils-a2a:0.7.0'

Registering TaskTool

Use a ChatClientBuilderCustomizer to register a TaskTool that references your A2A server:

@Bean
ChatClientBuilderCustomizer addTaskTool() {
return builder -> {
var taskTool = TaskTool.builder()
.subagentReferences(
new SubagentReference(
"http://localhost:8080/a2a",
A2ASubagentDefinition.KIND))
.subagentTypes(
new SubagentType(
new A2ASubagentResolver(),
new A2ASubagentExecutor()))
.build();
builder.defaultToolCallbacks(taskTool);
};
}

This configuration:

  • references the A2A server running at http://localhost:8080/a2a
  • uses an A2A resolver to discover agent details
  • uses an A2A executor to invoke the agent
  • registers the TaskTool as a tool callback for ChatClient

Trying It Out

Make sure the A2A server agent from the previous recipe is running.

Then start this application and ask:

What is the weather in Jal, New Mexico?

The client agent will delegate the request to the weather agent and return the response.

Verifying Delegation

To confirm that delegation is happening, add logging to the server agent (for example, in getWeatherForZipcode()).

You should see the request being handled by the sub-agent.

What You’ve Built

At this point, your agent can:

  • discover A2A-enabled agents
  • invoke them as needed
  • delegate work as part of achieving its goal

This is a key step toward building multi-agent systems where agents collaborate instead of working in isolation.

Find the source code for this recipe and other Spring AI recipes at https://github.com/habuma/spring-ai-recipes

--

--

Craig Walls
Craig Walls

Written by Craig Walls

Author Spring AI in Action, Spring in Action, and Build Talking Apps for Alexa