Problem/Motivation

Drupal\ai_neuron\Providers\ToolMapper::map() rebuilds each tool's schema one property at a time from ToolInterface::getProperties():

foreach ($tool->getProperties() as $property) {
  $function->setProperty($this->property($property));
}

Neuron's provider contract (src/Providers/AGENTS.md) says a tool mapper "consumes ToolInterface::getInputSchema() rather than rebuilding the schema from properties", and Neuron's own Providers\OpenAI\ToolMapper sends getInputSchema() as parameters and merges getParameters() on top.

Two consequences:

  1. A tool that overrides getInputSchema() loses everything the property list does not carry. FrontendTool, which Neuron's AG-UI input translator builds from a client-supplied schema, is the shipped example. For a schema with email {format, maxLength}, count {minimum, maximum} and opts {additionalProperties: false}, getInputSchema() keeps all of these, while the module sends {"email": {"type": "string", "description": "Address"}, "count": {"type": "integer"}, "opts": {..., "required": []}}.
  2. Tool::setParameters() (hand-written schema fragments, cache_control and other raw provider keys) is ignored for every tool.

The model therefore gets a looser contract than the tool declares, and validation that the tool author relied on does not happen.

Steps to reproduce

  1. Build a FrontendTool with an input schema carrying format, maxLength, minimum or additionalProperties.
  2. Run it through ToolMapper::map() and render the resulting ToolsFunctionInput.
  3. Compare with $tool->getInputSchema(): the constraints are gone.

Proposed resolution

Map from getInputSchema(): take properties and required from the schema instead of iterating getProperties(), then merge getParameters() into the function definition the way Neuron's OpenAI mapper does. NeuronPropertyInput can stay as the vehicle for passing each property's schema through to drupal/ai unchanged.

Issue fork ai_neuron-3628781

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joevagyok created an issue. See original summary.

joevagyok’s picture

Title: Build the tool schema from getInputSchema() and getParameters() instead of rebuilding it from properties » Align ToolMapper with Neuron's mapper contract
Category: Bug report » Task
joevagyok’s picture

Status: Active » Postponed

Revisit with frontend tool support later.

ademarco’s picture

Status: Postponed » Active

We are actually going to tackle this head on.

ademarco’s picture

Assigned: Unassigned » ademarco

ademarco changed the visibility of the branch 3628781-build-the-tool to hidden.

ademarco changed the visibility of the branch 3628781-build-the-tool to active.