Advanced

πŸ”€ Sequential Workflows

Chain multiple specialised agents together so the output of one becomes the input of the next.

Workflows let you decompose a complex task into a pipeline of focused agents, each with its own role and instructions. In a sequential workflow, the agents execute one after another β€” the first agent's response is automatically passed as input to the next agent in the chain. This is ideal for multi-step content pipelines such as research β†’ drafting β†’ editing β†’ formatting.

Agent Framework provides an AgentWorkflow class in the Microsoft.Agents.AI.Workflows namespace. You add agents to it using AddSequential(), then run the entire pipeline with a single RunAsync() call β€” just like running a single agent.

Each agent in the workflow receives the accumulated conversation context, including all prior agents' outputs. This means later agents can reference and build upon everything that came before them without you having to wire the plumbing manually.

Key Concepts

  • AgentWorkflow β€” orchestrates multiple agents as a pipeline
  • AddSequential() β€” registers agents to run in order, left to right
  • name parameter β€” give each agent a descriptive name for tracing and logging
  • Single RunAsync() β€” one call runs the full pipeline end-to-end
  • Context propagation β€” each agent sees prior agents' outputs automatically

NuGet Packages

dotnet add package Microsoft.Agents.AI.OpenAI --prerelease
dotnet add package Azure.AI.OpenAI --prerelease
dotnet add package Azure.Identity

Code Sample β€” Research & Write Pipeline

using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Workflows;

// Share a single Azure OpenAI client across all agents.
var client = new AzureOpenAIClient(
    new Uri(Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")!),
    new AzureCliCredential());

// Agent 1: Research the topic and gather key facts.
AIAgent researchAgent = client.GetChatClient("gpt-4o-mini")
    .AsAIAgent(
        instructions: "You research topics thoroughly and produce concise bullet-point summaries of key facts.",
        name: "Researcher");

// Agent 2: Turn the research notes into a polished blog post.
AIAgent writerAgent = client.GetChatClient("gpt-4o-mini")
    .AsAIAgent(
        instructions: "You are a skilled writer. Using the research notes provided, write a clear, engaging blog post with an introduction, body, and conclusion.",
        name: "Writer");

// Agent 3: Proof-read and improve the draft.
AIAgent editorAgent = client.GetChatClient("gpt-4o-mini")
    .AsAIAgent(
        instructions: "You are a meticulous editor. Review the blog post for clarity, grammar, and flow. Return the improved final version only.",
        name: "Editor");

// Build the sequential pipeline: Researcher β†’ Writer β†’ Editor.
var workflow = new AgentWorkflow()
    .AddSequential(researchAgent, writerAgent, editorAgent);

// Run the entire pipeline with one call.
var result = await workflow.RunAsync("Write a blog post about the history of the Eiffel Tower.");

Console.WriteLine(result.Text);

Step-by-Step Explanation

  1. Create a shared client β€” All agents share one AzureOpenAIClient instance. This is efficient and avoids creating redundant HTTP connections. Each agent can target a different model deployment if needed.
  2. Define specialised agents β€” Each agent has focused instructions that describe exactly its role. The name parameter is used for logging, tracing, and debugging. Naming agents makes it easy to track which agent produced which output.
  3. Build the workflow with AddSequential() β€” Pass agents in the order you want them to execute. The method accepts any number of agents as params.
  4. Run the pipeline β€” workflow.RunAsync() starts with the initial user message, passes it to the first agent, then feeds each agent's output to the next. The return value is the final agent's AgentResponse.

Example Pipeline Flow

User prompt β†’ [Researcher] β†’ bullet points
             β†’ [Writer] β†’ draft blog post
             β†’ [Editor] β†’ polished final post βœ“

Next Steps