alibaba/spring-ai-alibaba · error · IllegalArgumentException
AgentScope routing flow requires root agent to be AgentScope
Error message
AgentScope routing flow requires root agent to be AgentScopeRoutingAgent
What it means
AgentScopeRoutingGraphBuildingStrategy.validateAgentScopeRoutingConfig throws this IllegalArgumentException when a routing-flow config declares a root agent that is not an instance of AgentScopeRoutingAgent. The routing graph-building strategy can only wire the special routing root (which produces MultiCommand branch decisions), so any other root agent type is rejected before graph construction.
Source
Thrown at spring-boot-starters/spring-ai-alibaba-starter-agentscope/src/main/java/com/alibaba/cloud/ai/agent/agentscope/flow/AgentScopeRoutingGraphBuildingStrategy.java:138
return strategies;
};
}
@Override
public void validateConfig(FlowGraphBuilder.FlowGraphConfig config) {
super.validateConfig(config);
validateAgentScopeRoutingConfig(config);
}
private void validateAgentScopeRoutingConfig(FlowGraphBuilder.FlowGraphConfig config) {
if (config.getSubAgents() == null || config.getSubAgents().isEmpty()) {
throw new IllegalArgumentException("AgentScope routing flow requires at least one sub-agent");
}
if (config.getCustomProperty("agentScopeModel") == null) {
throw new IllegalArgumentException("AgentScope routing flow requires agentScopeModel in config custom properties");
}
if (!(config.getRootAgent() instanceof AgentScopeRoutingAgent)) {
throw new IllegalArgumentException("AgentScope routing flow requires root agent to be AgentScopeRoutingAgent");
}
}
}
View on GitHub (pinned to f82da0b50f)
Solutions
- Set config.setRootAgent(...) to an actual AgentScopeRoutingAgent instance (or its builder) before building the graph
- Verify the root agent's concrete class extends AgentScopeRoutingAgent, not a similarly named base class
- If the flow should not be a routing flow, use the graph-building strategy that matches the root agent type you provided
Example fix
// before
config.setRootAgent(new AgentScopeAgent("router"));
// after
config.setRootAgent(AgentScopeRoutingAgent.builder()
.name("router")
.subAgents(subAgents)
.model(model)
.build()); Defensive patterns
Strategy: validation
Validate before calling
if (!(config.getRootAgent() instanceof AgentScopeRoutingAgent)) {
throw new IllegalArgumentException("routing flow requires AgentScopeRoutingAgent as root");
} Type guard
static boolean isRoutingRoot(AgentConfig c) {
return c != null && c.getRootAgent() instanceof AgentScopeRoutingAgent;
} Try / catch
try {
graph = strategy.build(config);
} catch (IllegalArgumentException e) {
logger.error("Invalid routing config: {}", e.getMessage());
throw new ConfigException(e);
} Prevention
- Always build the root with AgentScopeRoutingAgent.builder() for routing flows
- Validate root agent type in a unit test for each flow definition
- Centralize flow config creation in one factory so the right strategy/agent pairing is guaranteed
When it happens
Trigger: Calling the AgentScope routing flow builder (buildCoreGraph / validateConfig) with a config whose getRootAgent() returns a plain agent, a SequentialAgent, or any agent other than AgentScopeRoutingAgent, even when sub-agents and agentScopeModel are correctly set.
Common situations: Developers reuse a graph-config builder shared with other flow types and forget to swap the root agent for AgentScopeRoutingAgent; custom agent subclasses fail an instanceof check because they extend a base agent class instead of AgentScopeRoutingAgent; config deserialization creates a generic agent type.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Routing sub-agents must be BaseAgent for merge support
- AgentScope routing flow requires at least one sub-agent
- AgentScope routing flow requires agentScopeModel in config c
- 参数 %s 的值 '%s' 应该是数值类型
- AgentScope Model must be provided for AgentScope routing age
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/134948b1db321634.
Report an issue: GitHub.