Skip to content

FoundryAgentAttribute

NexusLabs.Foundry.MicrosoftAgentFramework

NexusLabs.Foundry.MicrosoftAgentFramework

FoundryAgentAttribute Class

Marks a class as a declared agent type for Foundry's Agent Framework integration. Apply this attribute to a class to enable compile-time registration via the source generator and CreateAgent<TAgent>() lookup.

public sealed class FoundryAgentAttribute : System.Attribute

Inheritance System.Object 🡒 System.Attribute 🡒 FoundryAgentAttribute

Example

[FoundryAgent(
    Instructions = "You are a helpful customer support agent. Answer questions about orders.",
    Description = "Customer support agent for order inquiries")]
[AgentHandoffsTo(typeof(BillingAgent), "Escalate billing or payment questions to the billing agent")]
public class CustomerSupportAgent
{
}

// In your composition root:
var agentFactory = syringe.BuildAgentFactory();
var agent = agentFactory.CreateAgent<CustomerSupportAgent>();

Remarks

When the NexusLabs.Foundry.MicrosoftAgentFramework.Generators package is referenced, a [ModuleInitializer] is emitted that automatically registers the agent type with AgentFrameworkGeneratedBootstrap. UsingAgentFramework() then discovers and registers these types without any explicit Add*FromGenerated() calls.

Properties

FoundryAgentAttribute.Description Property

Gets or sets a human-readable description of this agent's purpose.

public string? Description { get; set; }

Property Value

System.String

FoundryAgentAttribute.FunctionGroups Property

Gets or sets named function groups (registered via AgentFunctionGroupAttribute) whose types are wired as tools for this agent.

public string[]? FunctionGroups { get; set; }

Property Value

System.String[]

FoundryAgentAttribute.FunctionTypes Property

Gets or sets the function types whose AgentFunctionAttribute-tagged methods are wired as tools for this agent. When null and FunctionGroups is also null, all registered function types are used.

public System.Type[]? FunctionTypes { get; set; }

Property Value

System.Type[]

FoundryAgentAttribute.Instructions Property

Gets or sets the system prompt instructions for this agent.

public string? Instructions { get; set; }

Property Value

System.String

FoundryAgentAttribute.Name Property

Gets or sets the name this agent is published under, overriding the class name. When null, the simple class name is used.

public string? Name { get; set; }

Property Value

System.String

Remarks

This is the agent's identity everywhere a name rather than a type identifies it: the key for CreateAgent(string), the value of Microsoft.Agents.AI.AIAgent.Name and therefore the author of the messages it produces, the gen_ai.agent.name telemetry dimension, and the key a hosted agent is registered under. Setting it here sets all of them, because they are all resolved from this one value.

Set it when the published identity should outlive the class name — a workflow document that names agents in text, or a metrics dashboard that groups by agent, both keep working across a class rename only if the name is declared rather than derived.

Setting a name replaces the class name as the addressable alias: once [FoundryAgent(Name = "Triage")] is applied to TriageAgent, CreateAgent("TriageAgent") no longer resolves and CreateAgent("Triage") does. There is one published name, not two. The fully-qualified type name always resolves as well, regardless of this property.

Names must be unique across all declared agents, exactly as class names must be; a collision is reported by FDRYMAF031 at compile time and rejected when the factory is built. Because the name reaches the model as part of a handoff tool name, prefer characters a provider accepts in a function name — letters, digits, hyphens, and underscores. Nothing enforces that here, so a name containing other characters may be rejected by the provider rather than by Foundry.