Skip to content

Fix Ollama streaming null generate options#1648

Open
SPUERSAIYAN wants to merge 1 commit into
agentscope-ai:mainfrom
SPUERSAIYAN:codex/fix-harness-stream-null-options
Open

Fix Ollama streaming null generate options#1648
SPUERSAIYAN wants to merge 1 commit into
agentscope-ai:mainfrom
SPUERSAIYAN:codex/fix-harness-stream-null-options

Conversation

@SPUERSAIYAN

@SPUERSAIYAN SPUERSAIYAN commented Jun 6, 2026

Copy link
Copy Markdown

AgentScope-Java Version

Version: agentscope-harness:2.0.0-RC1
Java: 21

Description

Fixes #1644
This PR fixes a NullPointerException in the Ollama streaming path when GenerateOptions is not explicitly configured.

Background:
HarnessAgent.streamEvents() can ultimately call the Ollama model streaming API with GenerateOptions == null. OllamaChatModel.doStream(...) previously accessed options.getToolChoice() directly, which caused an NPE. Non-streaming calls were unaffected because the options conversion path already handled null values.

Changes made:

  • Added a null-safe default GenerateOptions.builder().build() in OllamaChatModel.doStream(...).
  • Added a regression test covering OllamaChatModel.stream(..., null) to ensure streaming works without explicit generate options.

How to test:

  • mvn -pl agentscope-core -Dtest=OllamaChatModelTest test
  • mvn -pl agentscope-core -Dtest=OllamaChatModelTest#testStreamChatRequestWithNullOptions test
  • git diff --check

Checklist

Please check the following items before code is ready to be reviewed.

  • 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.)
  • Code is ready for review

@SPUERSAIYAN SPUERSAIYAN requested a review from a team June 6, 2026 11:00

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR fixes a NullPointerException in OllamaChatModel.doStream() when GenerateOptions is null. The base class ChatModelBase contract explicitly documents options as "null to use defaults", but doStream() called options.getToolChoice() without a null-guard, causing an NPE. The fix introduces a null-safe effectiveOptions fallback (GenerateOptions.builder().build()) — a clean, minimal one-line guard that is consistent with the project's existing null-handling patterns (e.g., OllamaOptions.fromGenerateOptions(null) already returns a default instance, and the constructor null-guards defaultOptions). A well-structured regression test covers stream(messages, null, null). The non-streaming chat() path was already null-safe via OllamaOptions.fromGenerateOptions(). No issues found.

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/model Model providers and formatters labels Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core/model Model providers and formatters bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants