Skip to content

fix(ollama): include items structure in tool parameter definitions#797

Open
wucm667 wants to merge 1 commit intocloudwego:mainfrom
wucm667:fix/ollama-tool-array-items
Open

fix(ollama): include items structure in tool parameter definitions#797
wucm667 wants to merge 1 commit intocloudwego:mainfrom
wucm667:fix/ollama-tool-array-items

Conversation

@wucm667
Copy link
Copy Markdown

@wucm667 wucm667 commented Apr 24, 2026

Problem

When using Ollama ChatModel with tools that have array-type parameters, the items structure is missing in the tool definition sent to the Ollama API. This causes the model to lack schema information for array elements.

For example, a tool parameter Messages []*message is serialized as:

{
  "messages": {
    "type": "array",
    "description": "Messages to test."
  }
}

Instead of the expected:

{
  "messages": {
    "items": {
      "properties": {
        "title": { "description": "...", "type": "string" },
        "content": { "description": "...", "type": "string" }
      },
      "type": "object"
    },
    "type": "array",
    "description": "Messages to test."
  }
}

Fix

Add a recursive schemaToToolProperty helper that converts *jsonschema.Schema to api.ToolProperty, properly handling:

  • Type / TypeEnhanced
  • Items (recursive for array element types)
  • AnyOf (recursive for union types)
  • Description, Enum

Replaces the previous flat property construction that only handled top-level Type, Description, and Enum.

Closes #716

When converting tool parameters to Ollama API format, array-type
parameters were missing their nested items structure. Add a recursive
schemaToToolProperty helper to handle Items, AnyOf, and other nested
schema fields.

Fixes cloudwego#716
@wucm667 wucm667 force-pushed the fix/ollama-tool-array-items branch from a415e5a to 0667c3b Compare April 24, 2026 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Ollama 的ChatModel 传递tool call 参数定义的时候遗漏items结构

1 participant