Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.Extensions.AI.AIFunctionMetadata should allow to be initialized with a json schema string #5655

Open
raffaeler opened this issue Nov 16, 2024 · 0 comments
Assignees
Labels
area-AI enhancement This issue represents an ask for new feature or an enhancement to an existing one

Comments

@raffaeler
Copy link

Description

I built a C# code generator to implement the boilerplate for Tools/Agents/Functions.
I already generate at compile time the json schema string complying to the OpenAI specification for any agent.

The AIFunctionMetadata should provide a way to be initialized with the json schema directly.
Currently I can only specify (but there is no example, therefore I don't know how) the schema in AIFunctionReturnParameterMetadata and AIFunctionParameterMetadata.

Anyway, the problem with AIFunctionParameterMetadata is that the json section specifying whether the parameter is required or not, belongs to the parent key (properties). This means that even if I can initialize this class with each parameter schema, I cannot specify the required field.

To get rid of all the problems and completely avoid the serialization at runtime, the root class AIFunctionMetadata should allow to take the entire schema. This also provides better performance.

Reproduction Steps

    private AIFunctionMetadata CreateMetadata(
        string functionName,
        string functionDescription,
        string returnSchema,
        IEnumerable<(string name, string schema)> parametersSchema)
    {
        List<AIFunctionParameterMetadata> parameters = new();
        foreach (var par in parametersSchema)
        {
            parameters.Add(new AIFunctionParameterMetadata(par.name)
            {
                Schema = par.schema,
            });
        }

        // how can I specify the 'required' field for each parameter?

        var returnParameter = new AIFunctionReturnParameterMetadata()
        {
            Schema = returnSchema,
        };

        var meta = new AIFunctionMetadata(functionName)
        {
            Description = functionDescription,
            ReturnParameter = returnParameter,
            Parameters = parameters,
        };

        return meta;
    }

Expected behavior

I expect:

  • to be able to initialize the AIFunctionMetadata with the entire schema, as for the OpenAI specification.
  • to be able to avoid any serialization or reflection in order to obtain better performance

Actual behavior

See example above: the ability to specify the schema per-parameter is not sufficient and does not provide any benefit

Regression?

No

Known Workarounds

Use reflection and serialize at runtime

Configuration

.NET 9.0.100

Other information

No response

@raffaeler raffaeler added bug This issue describes a behavior which is not expected - a bug. untriaged labels Nov 16, 2024
@eiriktsarpalis eiriktsarpalis self-assigned this Nov 18, 2024
@eiriktsarpalis eiriktsarpalis added enhancement This issue represents an ask for new feature or an enhancement to an existing one and removed untriaged bug This issue describes a behavior which is not expected - a bug. labels Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-AI enhancement This issue represents an ask for new feature or an enhancement to an existing one
Projects
None yet
Development

No branches or pull requests

3 participants