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.
Methods¶
IAgentFactory.CreateAgent(string) Method¶
Creates a new Microsoft.Agents.AI.AIAgent by looking up the registered type for agentClassName and reading its NeedlrAiAgentAttribute.
Parameters¶
agentClassName System.String
The simple class name of an agent type registered via AddAgent<T>(),
AddAgentsFromGenerated(), or the source generator bootstrap.
Returns¶
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¶
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.
Type parameters¶
TAgent
A class decorated with NeedlrAiAgentAttribute.
The class name becomes the agent's Name.
Returns¶
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¶
Exceptions¶
System.InvalidOperationException
Thrown when TAgent is not decorated with NeedlrAiAgentAttribute.
IAgentFactory.ResolveTools(Action<AgentFactoryOptions>) Method¶
Resolves the set of Microsoft.Extensions.AI.AITool instances that would be wired to an agent, without creating the agent itself.
System.Collections.Generic.IReadOnlyList<Microsoft.Extensions.AI.AITool> ResolveTools(System.Action<NexusLabs.Needlr.AgentFramework.AgentFactoryOptions>? configure=null);
Parameters¶
configure System.Action<AgentFactoryOptions>
Optional callback to scope tools by FunctionTypes
or FunctionGroups. When null, all
registered function types are included.
Returns¶
System.Collections.Generic.IReadOnlyList<Microsoft.Extensions.AI.AITool>
The resolved tools, ready to pass to Tools.
IAgentFactory.ResolveTools<TAgent>() Method¶
Resolves the tools scoped to the NeedlrAiAgentAttribute on
TAgent (reads FunctionTypes and FunctionGroups
from the attribute).
System.Collections.Generic.IReadOnlyList<Microsoft.Extensions.AI.AITool> ResolveTools<TAgent>()
where TAgent : class;
Type parameters¶
TAgent
A class decorated with NeedlrAiAgentAttribute.
Returns¶
System.Collections.Generic.IReadOnlyList<Microsoft.Extensions.AI.AITool>
IAgentFactory.ResolveTools<TAgent>(Action<AgentFactoryOptions>) Method¶
Resolves the tools scoped to the NeedlrAiAgentAttribute on TAgent, then applies the configure callback to override per-run scoping.
System.Collections.Generic.IReadOnlyList<Microsoft.Extensions.AI.AITool> ResolveTools<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.
Returns¶
System.Collections.Generic.IReadOnlyList<Microsoft.Extensions.AI.AITool>