Skip to content

IWorkflowFactory

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework

IWorkflowFactory Interface

Creates MAF Microsoft.Agents.AI.Workflows.Workflow instances from topology declared on agent classes via AgentHandoffsToAttribute, AgentGroupChatMemberAttribute, and AgentSequenceMemberAttribute. Registered in DI by UsingAgentFramework() — inject via constructor or resolve from IServiceProvider.

public interface IWorkflowFactory

Remarks

When the NexusLabs.Needlr.AgentFramework.Generators source generator is used, strongly-typed extension methods are emitted directly into the agents assembly — for example, CreateTriageHandoffWorkflow(), CreateCodeReviewGroupChatWorkflow(), and CreateContentPipelineSequentialWorkflow(). These generated methods call the core CreateHandoffWorkflow<TInitialAgent>(), CreateGroupChatWorkflow(string, int), and CreateSequentialWorkflow(string) methods internally, encapsulating type references and pipeline name strings so the composition root requires neither.

When the generator is not used, all three factory methods fall back to reading attributes via reflection.

Methods

IWorkflowFactory.CreateGroupChatWorkflow(string, int) Method

Creates a round-robin group chat Microsoft.Agents.AI.Workflows.Workflow for the named group. All agent types decorated with [AgentGroupChatMember()] are included as participants.

Microsoft.Agents.AI.Workflows.Workflow CreateGroupChatWorkflow(string groupName, int maxIterations=10);

Parameters

groupName System.String

The group name. Must match the GroupName value (case-sensitive) on at least two agent types. Prefer using a generated extension method (e.g. CreateCodeReviewGroupChatWorkflow()) to avoid referencing this string directly.

maxIterations System.Int32

Maximum number of round-robin turns before the workflow terminates. Defaults to 10.

Returns

Microsoft.Agents.AI.Workflows.Workflow
A built Microsoft.Agents.AI.Workflows.Workflow ready to run via MAF's execution environment.

Exceptions

System.InvalidOperationException
Thrown when groupName has fewer than two registered members.

IWorkflowFactory.CreateHandoffWorkflow<TInitialAgent>() Method

Creates a handoff Microsoft.Agents.AI.Workflows.Workflow where TInitialAgent is the starting agent and its AgentHandoffsToAttribute declarations determine the available handoff targets.

Microsoft.Agents.AI.Workflows.Workflow CreateHandoffWorkflow<TInitialAgent>()
    where TInitialAgent : class;

Type parameters

TInitialAgent

The type of the initial agent. Must be annotated with both NeedlrAiAgentAttribute and at least one AgentHandoffsToAttribute.

Returns

Microsoft.Agents.AI.Workflows.Workflow
A built Microsoft.Agents.AI.Workflows.Workflow ready to run via MAF's execution environment.

Exceptions

System.InvalidOperationException
Thrown when TInitialAgent has no AgentHandoffsToAttribute attributes declared.

IWorkflowFactory.CreateSequentialWorkflow(AIAgent[]) Method

Creates a sequential pipeline Microsoft.Agents.AI.Workflows.Workflow where the output of each agent flows as input to the next agent in the sequence.

Microsoft.Agents.AI.Workflows.Workflow CreateSequentialWorkflow(params Microsoft.Agents.AI.AIAgent[] agents);

Parameters

agents Microsoft.Agents.AI.AIAgent[]

The agents to chain in order. Must contain at least one agent.

Returns

Microsoft.Agents.AI.Workflows.Workflow
A built Microsoft.Agents.AI.Workflows.Workflow ready to run via MAF's execution environment.

IWorkflowFactory.CreateSequentialWorkflow(string) Method

Creates a sequential pipeline Microsoft.Agents.AI.Workflows.Workflow from a named pipeline declared via AgentSequenceMemberAttribute. Agents are assembled in ascending order.

Microsoft.Agents.AI.Workflows.Workflow CreateSequentialWorkflow(string pipelineName);

Parameters

pipelineName System.String

The pipeline name. Must match the PipelineName value (case-sensitive) on at least one agent type. Prefer using a generated extension method (e.g. CreateContentPipelineSequentialWorkflow()) to avoid referencing this string directly.

Returns

Microsoft.Agents.AI.Workflows.Workflow
A built Microsoft.Agents.AI.Workflows.Workflow ready to run via MAF's execution environment.

Exceptions

System.InvalidOperationException
Thrown when pipelineName has no registered members.