Skip to main content

Workflows API Reference

Building and orchestrating multi-agent workflows.

AgentWorkflowBuilder

Provides utility methods for constructing common patterns of workflows composed of agents.

BuildSequential()

Builds a workflow composed of a pipeline of agents where the output of one agent is the input to the next.
string
Optional name for the workflow.
IEnumerable<AIAgent>
required
The sequence of agents to compose into a sequential workflow.
Workflow
The built workflow composed of the supplied agents, in the order they were provided.

Example: Sequential Workflow

BuildConcurrent()

Builds a workflow composed of agents that operate concurrently on the same input, aggregating their outputs.
string
Optional name for the workflow.
IEnumerable<AIAgent>
required
The set of agents to compose into a concurrent workflow.
Func<IList<List<ChatMessage>>, List<ChatMessage>>?
The aggregation function that accepts a list of output messages from each agent and produces a single result list. If null, the default behavior is to return the last message from each agent.
Workflow
The built workflow composed of the supplied concurrent agents.

Example: Concurrent Workflow

CreateHandoffBuilderWith()

Creates a workflow builder for handoff-based agent orchestration.
AIAgent
required
The agent that will receive inputs provided to the workflow.
HandoffsWorkflowBuilder
A builder for creating a workflow based on agent handoffs.

Remarks

Handoffs between agents are achieved by the current agent invoking an AITool provided via ChatClientAgentOptions.ChatOptions.Tools. The agent must be capable of understanding and using these tools for handoffs to occur.

Example: Handoff Workflow

CreateGroupChatBuilderWith()

Creates a workflow builder for group chat orchestration with a manager agent.
Func<IReadOnlyList<AIAgent>, GroupChatManager>
required
Function that creates the GroupChatManager for the workflow. The manager is provided with the set of agents participating in the group chat.
GroupChatWorkflowBuilder
A builder for creating a group chat workflow.

Example: Group Chat Workflow


Workflow

Represents an executable workflow composed of agents.

Properties

string?
The name of the workflow.

Methods

RunAsync()

Runs the workflow with the provided input.
string
The message to send to the workflow.
IEnumerable<ChatMessage>
The messages to send to the workflow.
AgentSession?
Optional session for maintaining state across workflow runs.
AgentRunOptions?
Optional run options.
CancellationToken
default:"default"
Cancellation token.
Task<AgentResponse>
The workflow’s response.

Example: Stateful Workflow


Advanced Workflow Patterns

Example: Custom Aggregation Logic

Example: Conditional Workflow Logic

Example: Iterative Refinement Workflow