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(string, Action<AgentFactoryOptions>) Method

Creates a new Microsoft.Agents.AI.AIAgent by looking up the registered type for agentClassName, reading its NeedlrAiAgentAttribute, then applying the configure callback to override per-run values.

Microsoft.Agents.AI.AIAgent CreateAgent(string agentClassName, System.Action<NexusLabs.Needlr.AgentFramework.AgentFactoryOptions> configure);

Parameters

agentClassName System.String

The simple class name of an agent type.

configure System.Action<AgentFactoryOptions>

Callback to override attribute-populated defaults.

Returns

Microsoft.Agents.AI.AIAgent

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.

IAgentFactory.CreateAgent<TAgent>(Action<AgentFactoryOptions>) Method

Creates a new Microsoft.Agents.AI.AIAgent by reading configuration from the NeedlrAiAgentAttribute on TAgent, then applying the configure callback to override per-run values (e.g., instructions).

Microsoft.Agents.AI.AIAgent CreateAgent<TAgent>(System.Action<NexusLabs.Needlr.AgentFramework.AgentFactoryOptions> configure)
    where TAgent : class;

Type parameters

TAgent

A class decorated with NeedlrAiAgentAttribute.

Parameters

configure System.Action<AgentFactoryOptions>

Callback to override attribute-populated defaults. The AgentFactoryOptions is pre-populated from the attribute; the callback can override any field.

Returns

Microsoft.Agents.AI.AIAgent

Exceptions

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