agentscope-ai / agentscope-ai/agentscope-java

[Bug] streamEvents() throws NPE when generateOptions is not set on HarnessAgent

Abierto
#1,644 0 comentarios 0 reacciones 0 asignados Ver en GitHub
area/harness bug
Lenguaje dominante
Java
Estrellas
5.6k
Forks
1.3k
Merge medio
4 d 12 h
PR fusionados (30 d)
77

Descripción

## 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 |

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.