agentscope-ai / agentscope-ai/agentscope-java
[Bug] streamEvents() throws NPE when generateOptions is not set on HarnessAgent
- 主要語言
- Java
- 星號
- 5.6k
- 分支
- 1.3k
- 平均合併
- 4 天 12 小時
- 30 天內合併 PR
- 77
描述
## Bug Report
**Version:** `agentscope-harness:2.0.0-RC1`
**Java:** 21
**Model backend:** Ollama (qwen3:8b)
---
### Description
When calling `HarnessAgent.streamEvents()` without explicitly setting `generateOptions` on the builder, a `NullPointerException` is thrown because the internal options field is `null`.
```
Cannot invoke "io.agentscope.core.model.GenerateOptions.getToolChoice()"
because "options" is null
```
`HarnessAgent.call()` (non-streaming) works correctly under the same configuration.
Only `streamEvents()` is affected.
---
### Steps to Reproduce
```java
HarnessAgent agent = HarnessAgent.builder()
.name("my-agent")
.sysPrompt("You are a helpful assistant.")
.model("ollama:qwen3:8b")
.workspace(Paths.get(".agentscope/workspace"))
// ← generateOptions NOT set
.build();
// This throws NPE ↓
agent.streamEvents(new UserMessage("Hello"), ctx)
.filter(e -> e.getType() == AgentEventType.TEXT_BLOCK_DELTA)
.cast(TextBlockDeltaEvent.class)
.map(TextBlockDeltaEvent::getDelta)
.subscribe(System.out::print);
```
---
### Workaround
Explicitly passing an empty `GenerateOptions` fixes the issue:
```java
HarnessAgent agent = HarnessAgent.builder()
.name("my-agent")
.sysPrompt("You are a helpful assistant.")
.model("ollama:qwen3:8b")
.workspace(Paths.get(".agentscope/workspace"))
.generateOptions(GenerateOptions.builder().build()) // ← add this
.build();
```
---
### Root Cause (suspected)
Inside `streamEvents` → `delegate.streamEvents`, the code calls `options.getToolChoice()` without a null-check on `options`. When `generateOptions` is not provided via the builder, `options` remains `null`.
**Suggested fix:** Either initialize `generateOptions` to `GenerateOptions.builder().build()` by default in the builder, or add a null-check before accessing `options.getToolChoice()`.
---
### Environment
| Item | Value |
|------|-------|
| OS | macOS |
| Java | 21 |
| Spring Boot | 3.3.0 |
| agentscope-harness | 2.0.0-RC1 |
| Model | Ollama / qwen3:8b |
貢獻指南
評估
這個 Issue 還沒有評估資料。