Class SubAgentInterceptor
java.lang.Object
com.alibaba.cloud.ai.graph.agent.interceptor.ModelInterceptor
com.alibaba.cloud.ai.graph.agent.extension.interceptor.SubAgentInterceptor
- All Implemented Interfaces:
Interceptor
SubAgent interceptor that provides subagent invocation capabilities to agents.
This interceptor adds a `task` tool to the agent that can be used to invoke subagents.
Subagents are useful for handling complex tasks that require multiple steps, or tasks
that require a lot of context to resolve.
A chief benefit of subagents is that they can handle multi-step tasks, and then return
a clean, concise response to the main agent.
This interceptor comes with a default general-purpose subagent that can be used to
handle the same tasks as the main agent, but with isolated context.
Example:
SubAgentInterceptor interceptor = SubAgentInterceptor.builder()
.defaultModel(chatModel)
.addSubAgent(SubAgentSpec.builder()
.name("research-analyst")
.description("Use this agent to conduct thorough research on complex topics")
.systemPrompt("You are a research analyst...")
.build())
.build();
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic SubAgentInterceptor.Builderbuilder()getName()List<org.springframework.ai.tool.ToolCallback>getTools()Get tools provided by this interceptor.interceptModel(ModelRequest request, ModelCallHandler handler) Wrap a model call with custom logic.
-
Method Details
-
builder
-
getTools
Description copied from class:ModelInterceptorGet tools provided by this interceptor. Interceptors can provide built-in tools that will be automatically added to the agent.- Overrides:
getToolsin classModelInterceptor- Returns:
- List of tools provided by this interceptor, empty list by default
-
getName
-
interceptModel
Description copied from class:ModelInterceptorWrap a model call with custom logic. Implementations can: - Modify the request before calling the handler - Call the handler multiple times (retry logic) - Modify the response after handler returns - Handle exceptions and provide fallbacks- Specified by:
interceptModelin classModelInterceptor- Parameters:
request- The model requesthandler- The next handler in the chain (or base handler)- Returns:
- The model response
-