Skip to content

Support DisplayNameAttribute as AIFunction name #6941

@verdie-g

Description

@verdie-g
var f = AIFunctionFactory.Create(GetUserId);

[Description("This does this")]
void GetUserId() { }

This code generates an AIFunction with a description resolved from the DescriptionAttribute and a name resolved from the C# function name. That latter is usually never great. At best you'll get a pascal cased GetUserId which I understood is not ideal because LLMs are trained on snake cased code. At worst, you'll get _Main_g_GetUserId_0_0.

To have a better name you can simply specify a second parameter

var f = AIFunctionFactory.Create(GetUserId, "get_user_id");

This works fine but it forces defining the name at a different place than the method which is inconvenient. For example, I would like to create several classes that define some methods, with no dependencies on anything AI, then in the Startup of my agent, register these services and create tools from their methods without having to give them new names.

Would it make sense to support DisplayNameAttribute to define the name of the tool?

[DisplayName("get_user_id")]
[Description("This does this")]
void GetUserId() { }

The resolution priority of the name would become "AIFunctionFactory parameter" > DisplayNameAttribute > C# method name.

Metadata

Metadata

Assignees

Labels

area-aiMicrosoft.Extensions.AI libraries

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions