Skip to content

Hardening of tool definitions #479

@ceskyDJ

Description

@ceskyDJ

Currently, Neuron lets developers write invalid tool definitions and doesn't warn about it. This then leads to hard-to-understand error messages from the LLM providers, so the developer can easily get lost. There are at least two cases where some additional checks would be handy.

Array tool properties

Neuron currently allows you to define an invalid (but syntactically correct) definition of an array tool property:

new ToolProperty(
    name: 'view_range',
    type: PropertyType::ARRAY,
    description: '...',
    required: false,
),

It works for some providers (at least Anthropic) for some reason, but causes crashes with others. I found it after a pretty long debugging, as everything seemed to be "just fine".

The correct definition looks more or less like this:

new ArrayProperty(
    name: 'view_range',
    description: '...',
    required: false,
    items: new ToolProperty(
        name: 'Line number',
        type: PropertyType::INTEGER,
        description: '....',
        required: true,
    ),
    minItems: 2,
    maxItems: 2,
),

It is definitely suspicious that you don't define the type of array items, but one can easily overlook that. So, there should be a check for this case and an exception thrown for the first example and similar cases (when the array property isn't complete). Even better would be to make changes so it won't even syntactically exist, but I'm aware it's not that easy, and as Neuron v3 is almost stable, it's not a very good idea.

Multiple properties with the same name

There isn't even a check for name collision of properties like this in Neuron:

protected function properties(): array
{
    return [
        new ToolProperty(
            name: 'view_range',
            type: PropertyType::ARRAY,
            description: '...',
            required: false,
        ),
        new ArrayProperty(
            name: 'view_range',
            description: '...',
            required: false,
            items: new ToolProperty(
                name: 'Line number',
                type: PropertyType::INTEGER,
                description: '...',
                required: true,
            ),
            minItems: 2,
            maxItems: 2,
        ),
    ];
}

I think this should be addressed, too. It could cause serious problems after copy errors, etc.

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