[Bug][integrations][java] Ollama tool conversion fails on nullable tool parameters

Open Beginner friendly
#1,395 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java, ollama
Domain
backend

Research direction

Start with OllamaChatModelConnection.convertToOllamaTools in integrations/chat-models/ollama/src/main/java/org/apache/flink/agents/integrations/chatmodels/ollama/OllamaChatModelConnection.java and the conversion coverage in OllamaChatModelConnectionTest. Reproduce the failure with a schema whose property type is ["string", "null"], then check how the non-null type should be passed to Ollama. Done when conversion succeeds and the test verifies the parameter is sent as its non-null type.

Written by the indexing model from the issue text.

Description

Search before asking
  • I searched in the issues and found nothing similar.
Description

A Java function tool with a nullable parameter cannot be used with the Java Ollama chat model.

FunctionSchema writes @ToolParam(nullable = true) as "type": [<type>, "null"] (plan/src/main/java/org/apache/flink/agents/plan/tools/FunctionSchema.java:186). OllamaChatModelConnection.convertToOllamaTools reads every property's type as a String (integrations/chat-models/ollama/src/main/java/org/apache/flink/agents/integrations/chatmodels/ollama/OllamaChatModelConnection.java:158).

Expected: the tool converts, with the parameter sent as its non-null type.
Actual: every chat call with that tool fails with RuntimeException: java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.lang.String.

The Python Ollama connection passes the schema through and is not affected.

How to reproduce

In OllamaChatModelConnectionTest, convert a tool whose schema is:

{"type":"object","properties":{"city":{"type":["string","null"]}},"required":["city"]}

connection().convertToOllamaTools(List.of(new SchemaOnlyTool(schema))) throws the ClassCastException above.

Version and environment

main at 5b0b5531, Java 17, macOS.

Are you willing to submit a PR?
  • I'm willing to submit a PR!
Dominant language
Java
Stars
491
Forks
184
Avg merge
1d 17h
Merged PRs (30d)
69

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/flink-agents

All issues in apache/flink-agents

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.