Skip to content

[Bug] Java Ollama connection drops assistant tool calls from the chat history #1165

Closed

Description

@Zhuoxi2000

Search before asking

  • I searched in the issues and found nothing similar.

Description

The Java OllamaChatModelConnection drops the tool calls of assistant messages when it turns the chat history into an Ollama request. convertToOllamaChatMessages builds every message from its role and text only:

return new OllamaChatMessage(ollamaRole, message.getText());

After a tool round, the next request therefore carries the tool results but not the assistant turn that asked for them. The model sees results for calls it never made, and can respond by calling the same tool again.

The Python connection already forwards them as Message.ToolCall with the function name and arguments, so the same agent behaves differently on the same Ollama model depending on the language.

Expected: an assistant message's tool calls are sent as tool_calls, each with the function name and the arguments object, as in Python.

Actual: the assistant message is sent with empty content and no tool_calls.

How to reproduce

  1. Build a Java agent with an OllamaChatModelSetup (for example qwen3) and one tool.
  2. Send an input that makes the model call the tool.
  3. Inspect the request for the second chat turn, for example through OllamaChatModelConnection.buildRequest: the assistant message has no tool_calls, and the tool message follows it.

Version and environment

main (eb35a38), Java OllamaChatModelConnection, ollama4j 1.1.5. The Python connection is not affected.

Are you willing to submit a PR?

  • I'm willing to submit a PR!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    affectVersion/0.2.1affectVersion/0.3.1The bug affects the 0.3.1 version. The features are not needed.bug[Issue Type] Something isn't working as expected.fixVersion/0.4.0priority/majorDefault priority of the PR or issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions