Commit 3ce740c
fix(tool): handle empty tool publisher results (#1498)
## AgentScope-Java Version
1.1.0-SNAPSHOT
## Description
This PR fixes an edge case where a tool returns `Mono.empty()`.
Previously, when a tool publisher completed without emitting a result,
`ToolExecutor.executeAll()` collected fewer `ToolResultBlock`s than tool
calls. `ReActAgent.executeToolCalls()` then paired tool calls and
results by index, which could throw `IndexOutOfBoundsException`.
Changes made:
- Convert empty tool publishers into an error `ToolResultBlock`.
- Keep one result per tool call so `ReActAgent` can safely pair tool
calls and results.
- Add a regression test for a tool that returns `Mono.empty()`.
Minimal reproduction tool:
```java
@tool(
name = "empty_result_tool",
description = "Simulate a tool that completes without returning a result")
public Mono<String> emptyResultTool() {
return Mono.empty();
}
```
Test command:
```bash
mvn -pl agentscope-core -Dtest=ToolExecutorTest test
```
Local result:
```text
Tests run: 9, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS
```
Fixes #1497
## Checklist
Please check the following items before code is ready to be reviewed.
- [x] Code has been formatted with `mvn spotless:apply`
- [ ] All tests are passing (`mvn test`)
- [ ] Javadoc comments are complete and follow project conventions
- [ ] Related documentation has been updated (e.g. links, examples,
etc.)
- [x] Code is ready for review
Co-authored-by: LearningGp <learninggp4.74@gmail.com>1 parent 0738e78 commit 3ce740c
2 files changed
Lines changed: 53 additions & 1 deletion
File tree
- agentscope-core/src
- main/java/io/agentscope/core/tool
- test/java/io/agentscope/core/tool
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
264 | 269 | | |
265 | 270 | | |
266 | 271 | | |
| |||
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
129 | 176 | | |
130 | 177 | | |
131 | 178 | | |
| |||
0 commit comments