Skip to content

[API Proposal]: Make AITool.AdditionalProperties a writable AdditionalPropertiesDictionary #6570

@kzu

Description

@kzu

Background and motivation

For some reason, the AITool.AdditionalProperties is an IReadOnlyDictionary<string, object?> rather than an AdditionalPropertiesDictionary? like elsewhere (ChatOptions, ChatMessage, etc.). In addition, it's a readonly property (although virtual) so it cannot be extended the way the other AdditionalProperties-provided types can.

This means that the only mechanism for extending the tools is by deriving from them, unlike the other cases mentioned where just adding properties can be done using the new extension properties and serve as hints to an implementation that understands them.

API Proposal

public abstract class AITool
{
    public AdditionalPropertiesDictionary? AdditionalProperties { get; set; }
}

vs current

public abstract class AITool
{
    public virtual IReadOnlyDictionary<string, object?> AdditionalProperties => EmptyReadOnlyDictionary<string, object>.Instance;
}

API Usage

// send tool hints if supported by the specific client
var search = new HostedWebSearchTool
{
  AdditionalProperties = new()
  {
      { "Mode", "Auto" }
  }
};

// could also be done via extension properties:
var search = new HostedWebSearchTool
{
  Mode = "Auto"
};

Alternative Designs

No response

Risks

It's an API breaking change and it has already shipped, so perhaps it's too late (or by design and I'm missing something :)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-aiMicrosoft.Extensions.AI libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions