Multi-Agent Systems
A multi-agent system assigns different responsibilities to specialized AI agents and coordinates their work toward one result. This guide compares practical .NET orchestration options, shows a bounded C# workflow, and includes a live analyst–reviewer–coordinator playground.
What multiple agents add
- Narrow, explicit specialist roles
- A workflow that controls handoffs
- Review and challenge before delivery
- Visible limits, state, and policy
Start with the task, not the number of agents
An agent is a model plus instructions, tools or functions, state, and an execution policy. A multi-agent system gives two or more such roles a defined way to exchange results. The orchestrator—not an informal “team”—decides who runs, what context is passed, when to stop, and which result is returned.
Separate roles when work can be meaningfully divided, independently checked, or handled with different permissions. For a simple question, one model call or one tool-using assistant is usually cheaper, faster, and easier to evaluate.
Choose the simplest coordination pattern
| Pattern | How it works | Good fit | Main trade-off |
|---|---|---|---|
| Sequential pipeline | Specialists run in a fixed order; each receives the task and selected prior outputs. | Draft → review → final answer, or extract → validate → summarize. | Extra sequential calls increase latency; later stages inherit earlier mistakes. |
| Manager and workers | A manager delegates bounded subtasks, gathers results, and decides whether to finish. | A request can be split into a known set of independent research or analysis tasks. | Dynamic delegation needs strict limits on workers, rounds, tools, and budget. |
| Parallel specialists | Independent agents run at the same time and a later stage reconciles their results. | Independent classifications or separate perspectives with no shared writes. | Concurrency adds cost; disagreement needs a defined resolution rule. |
| Handoff | One agent transfers control to a specialist with a different context, tool set, or policy. | Routing a support request to billing, technical help, or a human operator. | Validate the handoff target and preserve the original authorization boundary. |
| Group conversation | Several agents exchange messages under a manager, turn limit, or termination rule. | Tasks that benefit from structured debate or multiple proposals. | Without a clear stopping condition, agents can repeat, drift, or amplify errors. |
| Durable workflow | A graph of steps can pause, wait for a person, checkpoint, and resume. | Long-running business processes with retries, approvals, or external events. | Requires versioned state, idempotent steps, and operational monitoring. |
.NET building blocks and frameworks
| Package / API | Role in a multi-agent application | Choose it when |
|---|---|---|
Microsoft.Extensions.AI |
Common IChatClient, messages, options, tool abstractions, and middleware. |
You want to write an explicit, provider-independent orchestration loop in ordinary C#. |
Microsoft.Extensions.AI.OpenAI + OpenAI |
Adapt an OpenAI .NET chat client to IChatClient; model features still vary by endpoint and model. |
You use OpenAI or a compatible provider and want a shared application-facing interface. |
Microsoft.Agents.AI |
Microsoft Agent Framework agent abstractions, conversations, tools, and integration points. | You need managed agent instances, sessions, middleware, or framework-level orchestration. |
Microsoft.Agents.AI.Workflows |
Workflow graph and execution primitives for sequencing, routing, and coordinating work. | The application needs explicit workflow steps, events, or resumable execution. |
Microsoft.SemanticKernel |
Kernel services, plugins, prompts, and orchestration patterns for Semantic Kernel applications. | Your application already uses Semantic Kernel or its plugin and planning abstractions. |
Task.WhenAll / System.Threading.Channels |
Built-in .NET primitives for bounded parallel work or producer/consumer coordination. | You have a small, well-defined workflow and do not need a full agent framework. |
This application references Microsoft.Extensions.AI 10.11.0, Microsoft.Extensions.AI.OpenAI 10.11.0, and OpenAI 2.14.0. Agent Framework, its workflow package, and Semantic Kernel are optional integrations, not dependencies of the live demo below. Check each framework's current NuGet release, provider matrix, and preview status before adopting its APIs.
Make roles and handoffs explicit with IChatClient
A fixed workflow can be implemented with a few bounded model calls. Each specialist gets a distinct system prompt, the original task remains available for review, and only the outputs needed by the next stage are passed forward.
dotnet add package Microsoft.Extensions.AI
dotnet add package Microsoft.Extensions.AI.OpenAI
dotnet add package OpenAI
using System;
using System.Threading;
using Microsoft.Extensions.AI;
using OpenAI;
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY")
?? throw new InvalidOperationException("Set OPENAI_API_KEY.");
IChatClient client = new OpenAIClient(apiKey)
.GetChatClient("gpt-6.1-sol")
.AsIChatClient();
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(60));
var cancellationToken = timeout.Token;
async Task<string> RunRoleAsync(
string instructions,
string input,
CancellationToken cancellationToken)
{
var response = await client.GetResponseAsync(
[
new ChatMessage(ChatRole.System, instructions),
new ChatMessage(ChatRole.User, input)
],
new ChatOptions { MaxOutputTokens = 900 },
cancellationToken);
return response.Text
?? throw new InvalidOperationException("The agent returned no text.");
}
const string request =
"Plan a small community event. State assumptions and keep the budget realistic.";
var draft = await RunRoleAsync(
"You are an analyst. Draft a concise plan and label assumptions.",
request,
cancellationToken);
var review = await RunRoleAsync(
"You are a reviewer. Check the draft against the request and flag gaps or unsupported claims.",
$"Original request:\n{request}\n\nDraft to review:\n{draft}",
cancellationToken);
var finalAnswer = await RunRoleAsync(
"You are the coordinator. Address the original request using the review; preserve uncertainty.",
$"Request:\n{request}\n\nDraft:\n{draft}\n\nReview:\n{review}",
cancellationToken);
Console.WriteLine(finalAnswer);
This is a deterministic three-stage workflow, not an open-ended agent swarm. The same provider client serves each role, while role instructions and task context define the handoffs. A framework becomes useful when the application also needs managed sessions, workflow events, checkpointing, human input, or more complex routing.
Keep collaboration bounded and auditable
Set a hard execution budget
Bound agent count, rounds, parallel calls, input history, output tokens, and wall-clock time. A retry or handoff must consume the same request budget rather than silently starting another one.
Pass data, not authority
Treat user input, retrieved content, and peer-agent output as untrusted. Enforce authorization in application code, keep tool permissions narrow, and require human approval for consequential actions.
Persist workflow state deliberately
Store versioned task state and validated step results, not just an unbounded transcript. Make external writes idempotent so retries or resumed workflows cannot duplicate actions.
Evaluate each stage
Measure task completion, factual support, reviewer usefulness, latency, and cost against a single-agent baseline. Log role, duration, and outcome without storing secrets or unnecessary personal data.
See Autonomous Agents for bounded tool-using agents, Tools & Plugins for guarded functions, and the .NET LLM guide for framework comparisons and workflow examples.
Try a .NET multi-agent workflow
Send one task through a bounded analyst, reviewer, and coordinator pipeline, with each agent's output shown before the final answer.
Keys remain in this browser's saved AI Agent settings. When you send a message, the selected provider's key is transferred over this Interactive Server circuit to the server, where its .NET SDK makes the HTTPS request. The key is not written to server storage or returned with the answer. Use this demo only with a server you trust; production applications should authenticate users and use a server-side secret manager.
This demo runs three sequential stages: an analyst drafts, a reviewer checks the draft against your task, and a coordinator produces the final answer. If a stage returns no text, it is retried once with the full configured output-token limit. The stages do not access tools.