Can someone provide Quickstart / Sample Code for different types of Orchestration in .Net C#?

Deepankar 385 Reputation points
2026-07-12T17:05:08.2066667+00:00

I am following the Microsoft Learn exercise: Develop a multi-agent solution with Microsoft Agent Framework

The exercise demonstrates a sequential multi-agent pattern but the provided code samples are only in Python.

Could you please share the Quickstart or equivalent implementation in .NET C# using the Microsoft Agent Framework SDK?

Specifically, I am looking for:

How to set up the project in C#

Equivalent client initialization and agent orchestration steps

  • Example of sequential agent execution in C# (matching the Python flow)
  • Different sample code execution for different types of orchestrations: Magentic, Sequential, Concurrent, Group chat, and Hand off.

This will help me mirror the exercise in .NET and practice with the same workflow.

Azure | Azure Training
0 comments No comments

3 answers

Sort by: Most helpful
  1. hoda osama 0 Reputation points
    2026-08-22T13:49:45.1866667+00:00

    Yes. For the current Microsoft Agent Framework SDK in .NET, I would start with the Sequential orchestration first, since it is the closest equivalent to the Python exercise you referenced.

    One important note: the AI-generated answer above appears to use an older orchestration API surface. The current Agent Framework C# documentation uses AgentWorkflowBuilder and InProcessExecution.

    Basic setup

    using Azure.AI.Projects;
    using Azure.Identity;
    using Microsoft.Agents.AI;
    using Microsoft.Agents.AI.Workflows;
    using Microsoft.Extensions.AI;
    
    var endpoint =
        Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
        ?? throw new InvalidOperationException(
            "Set AZURE_OPENAI_ENDPOINT");
    
    var deploymentName =
        Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME")
        ?? "gpt-4o-mini";
    
    AIProjectClient projectClient =
        new(new Uri(endpoint), new DefaultAzureCredential());
    
    AIAgent writerAgent = projectClient.AsAIAgent(
        model: deploymentName,
        name: "Writer",
        instructions: "Create a concise first draft.");
    
    AIAgent reviewerAgent = projectClient.AsAIAgent(
        model: deploymentName,
        name: "Reviewer",
        instructions: "Review the previous response and improve it.");
    

    Sequential orchestration

    Workflow workflow =
        AgentWorkflowBuilder.BuildSequential(
            [writerAgent, reviewerAgent]);
    

    In this pattern, the output flows in order:

    User Input
       ↓
    Writer Agent
       ↓
    Reviewer Agent
       ↓
    Final Output
    

    Then run the workflow using the current in-process execution API:

    var messages = new List<ChatMessage>
    {
        new(
            ChatRole.User,
            "Create a short launch message for a new product.")
    };
    
    await using StreamingRun run =
        await InProcessExecution.RunStreamingAsync(
            workflow,
            messages);
    
    await run.TrySendMessageAsync(
        new TurnToken(emitEvents: true));
    
    await foreach (
        WorkflowEvent evt in run.WatchStreamAsync())
    {
        if (evt is AgentResponseUpdateEvent update)
        {
            Console.Write(update.Update.Text);
        }
    }
    

    So if your immediate goal is to reproduce the Microsoft Learn sequential Python exercise in C#, AgentWorkflowBuilder.BuildSequential() is the place I would start.

    Once you confirm that this version is working in your project, I can also share the equivalent C# pattern for Concurrent, Handoff, Group Chat, or Magentic orchestration separately.

    I validated this against the current Microsoft Agent Framework Sequential Orchestration and Get Started documentation.

    AI assistance disclosure: I used ChatGPT to help structure this response, and I reviewed and validated the code and guidance against the current Microsoft Agent Framework documentation before posting.

    References:

    Was this answer helpful?

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. AI answer

    2026-07-12T17:05:41.9233333+00:00

    The .NET C# equivalents for the multi-agent orchestration patterns are provided in the Semantic Kernel / Agent Framework samples. These cover Sequential, Concurrent, Handoff, Group Chat–style flows, and Magentic orchestration.

    Below is how these patterns look in C#, based on the official samples.


    Project setup in C# (high level)

    The C# samples use:

    • ChatCompletionAgent for individual agents
    • An orchestration type (SequentialOrchestration, ConcurrentOrchestration, HandoffOrchestration, MagenticOrchestration, etc.)
    • InProcessRuntime to run the orchestration

    Each sample follows this pattern:

    1. Define agents (with instructions/tools as needed).
    2. Create the orchestration object with those agents.
    3. Create and start InProcessRuntime.
    4. Invoke the orchestration with a task string.
    5. Await the result and print the output and history.
    6. Optionally stop the runtime.

    Sequential orchestration (sequential multi-agent pattern)

    The Sequential pattern matches the Python exercise flow: one agent processes the input, passes its output to the next, and so on.

    Key C# steps:

    1. Define agents (for example: analyst, copywriter, editor) using ChatCompletionAgent.
    2. Optional response callback to observe intermediate outputs:
    ChatHistory history = [];
    
    ValueTask responseCallback(ChatMessageContent response)
    {
        history.Add(response);
        return ValueTask.CompletedTask;
    }
    
    1. Create the sequential orchestration:
    SequentialOrchestration orchestration = new(analystAgent, writerAgent, editorAgent)
    {
        ResponseCallback = responseCallback,
    };
    
    1. Start runtime and invoke:
    InProcessRuntime runtime = new InProcessRuntime();
    await runtime.StartAsync();
    
    var result = await orchestration.InvokeAsync(
        "An eco-friendly stainless steel water bottle that keeps drinks cold for 24 hours",
        runtime);
    
    1. Collect final result and history:
    string output = await result.GetValueAsync(TimeSpan.FromSeconds(20));
    Console.WriteLine($"\n# RESULT: {output}");
    Console.WriteLine("\n\nORCHESTRATION HISTORY");
    foreach (ChatMessageContent message in history)
    {
        // Custom print helper
    }
    
    1. Optional: stop runtime:
    await runtime.RunUntilIdleAsync();
    

    The full sample is in the Sequential orchestration C# sample referenced in the context.


    Concurrent orchestration

    Concurrent orchestration runs multiple agents in parallel on the same task.

    1. Define agents (for example: physicist and chemist).
    2. Create concurrent orchestration:
    ConcurrentOrchestration orchestration = new(physicist, chemist);
    
    1. Start runtime and invoke:
    InProcessRuntime runtime = new InProcessRuntime();
    await runtime.StartAsync();
    
    var result = await orchestration.InvokeAsync("What is temperature?", runtime);
    
    1. Collect results (array of strings, order not guaranteed):
    string[] output = await result.GetValueAsync(TimeSpan.FromSeconds(20));
    Console.WriteLine($"# RESULT:\n{string.Join("\n\n", output.Select(text => $"{text}"))}");
    
    1. Optional: stop runtime:
    await runtime.RunUntilIdleAsync();
    

    The full sample is in the Concurrent orchestration C# sample.


    Handoff orchestration

    Handoff orchestration lets agents transfer control between each other based on context (for example, customer support → technical expert → billing).

    Typical C# flow:

    1. Define multiple agents with different expertise.
    2. Create a HandoffOrchestration with those agents.
    3. Start InProcessRuntime.
    4. Invoke with a customer-style task:
    string task = "I am a customer that needs help with my orders";
    var result = await orchestration.InvokeAsync(task, runtime);
    
    1. Collect result and history:
    string output = await result.GetValueAsync(TimeSpan.FromSeconds(300));
    Console.WriteLine($"\n# RESULT: {output}");
    Console.WriteLine("\n\nORCHESTRATION HISTORY");
    foreach (ChatMessageContent message in history)
    {
        Console.WriteLine($"# {message.Role} - {message.AuthorName}: {message.Content}");
    }
    
    1. Optional: stop runtime:
    await runtime.RunUntilIdleAsync();
    

    The full sample is in the Handoff orchestration C# sample.


    Magentic orchestration

    Magentic orchestration is a more advanced multi-agent pattern based on Magentic-One, with a manager agent that plans and coordinates specialized agents.

    The C# pattern is similar to other orchestrations:

    1. Define specialized agents (researcher, coder, executor, etc.).
    2. Define a manager agent with planning instructions.
    3. Create the Magentic orchestration object.
    4. Start InProcessRuntime.
    5. Invoke with a complex task.
    6. Collect result and history:
    string output = await result.GetValueAsync(TimeSpan.FromSeconds(300));
    Console.WriteLine($"\n# RESULT: {output}");
    Console.WriteLine("\n\nORCHESTRATION HISTORY");
    foreach (ChatMessageContent message in history)
    {
        Console.WriteLine($"# {message.Role} - {message.AuthorName}: {message.Content}");
    }
    
    1. Optional: stop runtime:
    await runtime.RunUntilIdleAsync();
    

    The full Magentic C# sample is referenced in the context.


    Group chat–style orchestration and HITL

    Group chat orchestration uses a powerful manager coordinating multiple agents (similar architecture to Magentic). For human-in-the-loop (HITL) scenarios and tool approval with orchestrations:

    • Agent tool calls that require approval emit RequestInfoEvent with ToolApprovalRequestContent.
    • The workflow pauses until a response is provided.
    • This applies to sequential, concurrent, and group chat workflows.

    Relevant samples include:

    • Sequential orchestration with HITL
    • GroupChatToolApproval sample (C#)

    These show how to subscribe to RequestInfoEvent, route requests to a human, and send responses back to the workflow.


    Where to find complete C# quickstarts and samples

    The context points to the official sample locations for each orchestration type:

    • Sequential orchestration C# sample
    • Concurrent orchestration C# sample
    • Handoff orchestration C# sample
    • Magentic orchestration C# sample
    • Group chat / tool approval samples

    These samples provide full project setup, agent definitions, and orchestration wiring that can be mirrored to match the Python exercise flow.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.