Missing 'multiple' handling in ContextDefinitionNormalizer::normalize

Created on 4 September 2025, 10 days ago

Problem/Motivation

Context definitions have a 'multiple' property, which turns them into a list/array with the original data_type used as the 'item' definition.

Proposed resolution

Just before $properties[] = $property; in \Drupal\ai\Utility\ContextDefinitionNormalizer::normalize, we add:

      // If multiple, wrap in array.
      if ($definition->isMultiple()) {
        $array_property = new ToolsPropertyInput($key);
        $array_property->setType('array');
        $array_property->setDescription('List of ' . $definition->getLabel());
        $array_property->setItems($property);
        $property = $array_property;
      }

We also need to map over other properties as well (ex.. if item is required, set required or minItems, etc..)? The \Drupal\ai\OperationType\Chat\Tools\ToolsPropertyInput::setItems method also only accepts array|string, when I think we may actually want it to accept ToolPropertyInputInterface, as most definitions I've found have a single definition and not an array for 'items'. The exception are items that use anyOf, oneOf, etc...

An example array usage:

{
  "type": "function",
  "function": {
    "name": "record_weather",
    "description": "Record temperatures by city.",
    "parameters": {
      "type": "object",
      "properties": {
        "readings": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "properties": {
              "city": { "type": "string", "minLength": 1 },
              "temperature": { "type": "number" },
              "unit": { "type": "string", "enum": ["C", "F"] }
            },
            "required": ["city", "temperature"],
            "additionalProperties": false
          }
        }
      },
      "required": ["readings"],
      "additionalProperties": false
    }
  }
}

Remaining tasks

Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)

πŸ“Œ Task
Status

Active

Version

1.2

Component

...to be triaged

Created by

πŸ‡ΊπŸ‡ΈUnited States michaellander

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024