Skip to content

Conversation

@devnomad-byte
Copy link

Summary

This PR adds comprehensive Ollama integration to AgentScope, enabling users to leverage local Ollama models with full feature support.

Features Implemented

Core Chat Features:

  • OllamaOptions: Complete configuration class supporting 40+ Ollama parameters including advanced model loading options (GPU offloading, memory management) and runtime generation parameters (sampling strategies, penalties)
  • OllamaHttpClient: HTTP client for Ollama API with sync/async and streaming support, proper JSON serialization/deserialization and error handling
  • OllamaChatModel: Full ChatModel implementation with tool usage, streaming, timeout/retry mechanisms, and seamless integration with AgentScope framework

Message Formatting System:

  • OllamaChatFormatter: Standard chat formatting with proper role mapping
  • OllamaMultiAgentFormatter: Multi-agent conversation formatting with history management
  • OllamaMessageConverter: Message conversion between AgentScope and Ollama formats
  • OllamaConversationMerger: Multi-agent conversation merging with history tags
  • OllamaToolsHelper: Tool configuration and usage support
  • OllamaMediaConverter: Media and image handling for multimodal models

Text Embedding Features:

  • OllamaTextEmbedding: Complete text embedding implementation with support for Ollama's embedding API
  • Includes proper error handling, timeout/retry mechanisms, and dimension validation
  • Supports reactive programming with Project Reactor's Mono

API DTOs:

  • Complete set of data transfer objects for Ollama API requests and responses
  • Support for messages, tools, tool calls, embeddings, and complex conversation structures

Design Decisions

  • Used adapter pattern instead of inheritance for OllamaOptions to avoid coupling with generic options
  • Implemented flexible message formatting system supporting both standard and multi-agent scenarios
  • Added Chain of Thought (CoT) support through thinking options
  • Optimized single message handling to avoid unnecessary conversation history wrapping
  • Proper reactive programming support with timeout and retry mechanisms

Testing

  • Complete test coverage for all Ollama components
  • Unit tests for message formatting, conversion, and API communication
  • Integration tests for end-to-end functionality
  • Tests for both chat and embedding functionality

Additional Notes

This integration provides a complete solution for using Ollama models within the AgentScope ecosystem with full feature parity.

This commit adds complete Ollama support to AgentScope, enabling users to leverage local Ollama models with full feature support.

Core Chat Features:
- OllamaOptions: Complete configuration class supporting 40+ Ollama parameters including advanced model loading options (GPU offloading, memory management) and runtime generation parameters (sampling strategies, penalties)
- OllamaHttpClient: HTTP client for Ollama API with sync/async and streaming support, proper JSON serialization/deserialization and error handling
- OllamaChatModel: Full ChatModel implementation with tool usage, streaming, timeout/retry mechanisms, and seamless integration with AgentScope framework

Message Formatting System:
- OllamaChatFormatter: Standard chat formatting with proper role mapping
- OllamaMultiAgentFormatter: Multi-agent conversation formatting with history management
- OllamaMessageConverter: Message conversion between AgentScope and Ollama formats
- OllamaConversationMerger: Multi-agent conversation merging with history tags
- OllamaToolsHelper: Tool configuration and usage support
- OllamaMediaConverter: Media and image handling for multimodal models

Text Embedding Features:
- OllamaTextEmbedding: Complete text embedding implementation with support for Ollama's embedding API
- Includes proper error handling, timeout/retry mechanisms, and dimension validation
- Supports reactive programming with Project Reactor's Mono

API DTOs:
- Complete set of data transfer objects for Ollama API requests and responses
- Support for messages, tools, tool calls, embeddings, and complex conversation structures

Design Decisions:
- Used adapter pattern instead of inheritance for OllamaOptions to avoid coupling with generic options
- Implemented flexible message formatting system supporting both standard and multi-agent scenarios
- Added Chain of Thought (CoT) support through thinking options
- Optimized single message handling to avoid unnecessary conversation history wrapping
- Proper reactive programming support with timeout and retry mechanisms

Comprehensive Testing:
- Complete test coverage for all Ollama components
- Unit tests for message formatting, conversion, and API communication
- Integration tests for end-to-end functionality
- Tests for both chat and embedding functionality

This integration provides a complete solution for using Ollama models within the AgentScope ecosystem with full feature parity."
@devnomad-byte devnomad-byte requested a review from a team December 29, 2025 07:58
@cla-assistant
Copy link

cla-assistant bot commented Dec 29, 2025

CLA assistant check
All committers have signed the CLA.

@cla-assistant
Copy link

cla-assistant bot commented Dec 29, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive Ollama integration to AgentScope, enabling local model usage with full chat and embedding capabilities. The implementation includes 40+ configuration parameters, tool usage support, streaming, and multi-agent conversation formatting.

Key changes:

  • Core Ollama integration classes (OllamaChatModel, OllamaHttpClient, OllamaOptions)
  • Message formatting system for standard and multi-agent scenarios
  • Text embedding support with OllamaTextEmbedding
  • Complete DTO layer for API communication

Reviewed changes

Copilot reviewed 39 out of 39 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pom.xml Added JVM flag for URLClassPath to support tests
OllamaOptions.java Configuration class with 40+ parameters and conversion utilities
ThinkOption.java Chain of Thought configuration interface with boolean/level support
OllamaHttpClient.java HTTP client for Ollama API with sync/async support
OllamaChatModel.java ChatModel implementation with streaming and tool support
OllamaTextEmbedding.java Text embedding model implementation
OllamaMessageConverter.java Converts AgentScope messages to Ollama format
OllamaMultiAgentFormatter.java Formatter for multi-agent conversations
OllamaChatFormatter.java Standard chat formatter
OllamaToolsHelper.java Tool configuration and conversion utilities
OllamaResponseParser.java Parses Ollama responses to ChatResponse
OllamaConversationMerger.java Merges multi-agent conversations
OllamaMediaConverter.java Handles image/media conversion
DTO classes Request/response objects for Ollama API
Test files Comprehensive unit and e2e tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

void testJsonSerializationError() throws Exception {
// Arrange
OllamaRequest request = mock(OllamaRequest.class);
doThrow(new JsonProcessingException("Serialization error") {}).when(request).toString(); // This will cause issues
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

Default toString(): OllamaRequest inherits toString() from Object, and so is not suitable for printing.

Copilot uses AI. Check for mistakes.

/**
* Convert list of content blocks (usually from tool result) to string.
*/
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

This method overrides AbstractBaseFormatter<OllamaMessage,OllamaResponse,OllamaRequest>.convertToolResultToString; it is advisable to add an Override annotation.

Suggested change
*/
*/
@Override

Copilot uses AI. Check for mistakes.
.dimensions(TEST_DIMENSIONS)
.build();

assertTrue(model instanceof EmbeddingModel);
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

There is no need to test whether an instance of OllamaTextEmbedding is also an instance of EmbeddingModel - it always is.

Copilot uses AI. Check for mistakes.
refactor: replace wildcard imports with specific imports

- Replace import static org.junit.jupiter.api.Assertions.* with specific assertion imports
- Replace import static org.mockito.Mockito.* with specific Mockito imports
- Fix Spotless format issue: forbidWildcardImports
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 39 out of 39 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

agentscope-extensions/agentscope-extensions-rag-simple/src/test/java/io/agentscope/core/embedding/ollama/OllamaTextEmbeddingEmbedTest.java:1

  • Comment is in Chinese. For consistency and accessibility, comments in the codebase should be in English.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +309 to +313
public OllamaHttpException(String message, String errorCode, String responseBody) {
super(message);
this.statusCode = null;
this.responseBody = responseBody;
}
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

The constructor parameter errorCode is defined but never used in the constructor body. This appears to be an unused parameter that should either be removed or utilized properly. Consider removing this parameter if it's not needed, or storing it as a field if it should be accessible.

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +27
* @author qjc
* @since 1.0.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this

Comment on lines +26 to +27
* @author qjc
* @since 1.0.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this

<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>@{argLine} ${argLine}</argLine>
<argLine>@{argLine} ${argLine} -Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why change this?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 41 out of 42 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +273 to +276
public String convertToolResultToString(List<ContentBlock> blocks) {
StringBuilder sb = new StringBuilder();
for (ContentBlock block : blocks) {
if (block instanceof TextBlock) {
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

This method overrides AbstractBaseFormatter<OllamaMessage,OllamaResponse,OllamaRequest>.convertToolResultToString; it is advisable to add an Override annotation.

Suggested change
public String convertToolResultToString(List<ContentBlock> blocks) {
StringBuilder sb = new StringBuilder();
for (ContentBlock block : blocks) {
if (block instanceof TextBlock) {
@Override
public String convertToolResultToString(List<ContentBlock> blocks) {
StringBuilder sb = new StringBuilder();
for (ContentBlock block : blocks) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants