Skip to content

IAgentFactory

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework

IAgentFactory Interface

Factory for creating configured Microsoft.Agents.AI.AIAgent instances with auto-discovered AgentFunctionAttribute tools wired up.

public interface IAgentFactory

Methods

IAgentFactory.CreateAgent(string) Method

Creates a new Microsoft.Agents.AI.AIAgent by looking up the registered type for agentClassName and reading its NeedlrAiAgentAttribute.

Microsoft.Agents.AI.AIAgent CreateAgent(string agentClassName);

Parameters

agentClassName System.String

The simple class name of an agent type registered via AddAgent<T>(), AddAgentsFromGenerated(), or the source generator bootstrap.

Returns

Microsoft.Agents.AI.AIAgent

Exceptions

System.InvalidOperationException
Thrown when no agent with the given name is registered.

IAgentFactory.CreateAgent(Action<AgentFactoryOptions>) Method

Creates a new Microsoft.Agents.AI.AIAgent with the registered function tools applied.

Microsoft.Agents.AI.AIAgent CreateAgent(System.Action<NexusLabs.Needlr.AgentFramework.AgentFactoryOptions>? configure=null);

Parameters

configure System.Action<AgentFactoryOptions>

Optional callback to configure per-agent options such as instructions or a subset of function types to wire for this specific agent instance.

Returns

Microsoft.Agents.AI.AIAgent
A fully configured Microsoft.Agents.AI.AIAgent ready to run.

IAgentFactory.CreateAgent<TAgent>() Method

Creates a new Microsoft.Agents.AI.AIAgent by reading configuration directly from the NeedlrAiAgentAttribute on TAgent.

Microsoft.Agents.AI.AIAgent CreateAgent<TAgent>()
    where TAgent : class;

Type parameters

TAgent

A class decorated with NeedlrAiAgentAttribute. The class name becomes the agent's Name.

Returns

Microsoft.Agents.AI.AIAgent

Exceptions

System.InvalidOperationException
Thrown when TAgent is not decorated with NeedlrAiAgentAttribute.