[BUG] AgentScopeRoutingMergeNode should not re-synthesize single routed result
kind/bugneeds-triage
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Current Behavior
`AgentScopeRoutingMergeNode` always calls `synthesize()` after collecting routed sub-agent outputs, even when only one sub-agent produced a result.
This is inconsistent with the regular `RoutingMergeNode`, which already returns a single routed result directly without another synthesis model call.
As a result, a single sub-agent answer may be sent back to the model for an unnecessary synthesis step, which can increase latency/token cost and may rewrite or duplicate the original answer.
### Expected Behavior
When only one sub-agent result is present, `AgentScopeRoutingMergeNode` should return that result directly, without invoking `synthesize()`.
The synthesis step should only be used when multiple sub-agent results need to be merged.
### Steps To Reproduce
1. Build an AgentScope routing agent with multiple sub-agents.
2. Send a request that is routed to only one sub-agent.
3. The selected sub-agent writes its result to state.
4. `AgentScopeRoutingMergeNode` collects exactly one result.
5. Observe that it still calls `synthesize()` and creates a `ReActAgent` for another model call instead of returning the single result directly.
### Environment
```markdown
Spring AI Alibaba version(s): latest main branch
```
### Debug logs
_No response_
### Anything else?
The regular `RoutingMergeNode` already has a guard for this case:
```java
if (formattedResults.size() == 1) {
return Map.of(mergedOutputKey, lastResult);
}
```
`AgentScopeRoutingMergeNode` does not have the same guard and always executes:
```java
String query = extractOriginalQuery(state);
String finalAnswer = synthesize(query, formattedResults);
return Map.of(mergedOutputKey, finalAnswer);
```
Suggested fix:
* Track the collected single result.
* Return it directly when formattedResults.size() == 1.
* Keep the existing synthesis behavior for multiple results.
* Add a regression test for the single-result case.
0 条评论