Skip to content

Collections are not described as arrays when using @ToolArg #126

@DKarim

Description

@DKarim

Expected Behavior

When a @ToolArg parameter is a List for example, it should be described as array when listing tools.

Actual Behaviour

The argument is described as object.
Claude works around it but ChatGPT is more strict and tries to wrap its queries in objects.
For example: {"someList": {"someList": ["someItem"]}}

Steps To Reproduce

With those tools

@Singleton
public class TestTools {

    @Tool
    String withToolArg(@ToolArg List<String> someList) {
        return "test";
    }

    @Tool
    String withJsonSchema(JsonSchemaRequest request) {
        return "test";
    }
}

and this request object

/**
 * @param someList List of things
 */
@Introspected
@JsonSchema
public record JsonSchemaRequest(
        List<String> someList
) {
}

a call to list tools returns

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "tools": [
      {
        "name": "withToolArg",
        "inputSchema": {
          "type": "object",
          "properties": {
            "someList": {
              "type": "object"
            }
          },
          "required": [
            "someList"
          ]
        }
      },
      {
        "name": "withJsonSchema",
        "inputSchema": {
          "type": "object",
          "properties": {
            "someList": {
              "description": "List of things",
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      }
    ]
  }
}

Another difference we can see here is also that arguments are:

  • required by default with @JsonSchema
  • optional by default with @ToolArg

Environment Information

No response

Example Application

No response

Version

4.10.3
0.0.17

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions