Skip to content

AgentFunctionAttribute

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework

AgentFunctionAttribute Class

Marks a method as an agent function that can be auto-discovered by Needlr and registered as an Microsoft.Extensions.AI.AIFunction tool for Microsoft Agent Framework agents.

public sealed class AgentFunctionAttribute : System.Attribute

Inheritance System.Object 🡒 System.Attribute 🡒 AgentFunctionAttribute

Example

public class OrderTools
{
    [AgentFunction]
    [Description("Look up the status of an order by its ID")]
    public string GetOrderStatus(
        [Description("The order identifier")] string orderId)
    {
        return orderId == "123" ? "Shipped" : "Processing";
    }
}

// Wire the function group to an agent:
[NeedlrAiAgent(Instructions = "Help users track their orders")]
[AgentFunctionGroup(typeof(OrderTools))]
public class OrderTrackingAgent { }

Remarks

Apply this attribute to public methods on a class or static class. Needlr's scanners and source generator will discover all classes that contain at least one method decorated with [AgentFunction] and register them with the agent factory.

Use System.ComponentModel.DescriptionAttribute to provide LLM-friendly descriptions for methods and parameters.